aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_inline_lock_posix.x
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/include/eina_inline_lock_posix.x')
-rw-r--r--libraries/eina/src/include/eina_inline_lock_posix.x51
1 files changed, 49 insertions, 2 deletions
diff --git a/libraries/eina/src/include/eina_inline_lock_posix.x b/libraries/eina/src/include/eina_inline_lock_posix.x
index 77f5b8b..64e049a 100644
--- a/libraries/eina/src/include/eina_inline_lock_posix.x
+++ b/libraries/eina/src/include/eina_inline_lock_posix.x
@@ -19,6 +19,15 @@
19#ifndef EINA_INLINE_LOCK_POSIX_X_ 19#ifndef EINA_INLINE_LOCK_POSIX_X_
20#define EINA_INLINE_LOCK_POSIX_X_ 20#define EINA_INLINE_LOCK_POSIX_X_
21 21
22#ifdef EINA_UNUSED
23# undef EINA_UNUSED
24#endif
25#ifdef __GNUC__
26# define EINA_UNUSED __attribute__((unused))
27#else
28# define EINA_UNUSED
29#endif
30
22#include <errno.h> 31#include <errno.h>
23#ifndef __USE_UNIX98 32#ifndef __USE_UNIX98
24# define __USE_UNIX98 33# define __USE_UNIX98
@@ -28,7 +37,10 @@
28# include <pthread.h> 37# include <pthread.h>
29#endif 38#endif
30 39
40#include <semaphore.h>
41
31#include <sys/time.h> 42#include <sys/time.h>
43#include <stdio.h>
32 44
33#ifdef EINA_HAVE_DEBUG_THREADS 45#ifdef EINA_HAVE_DEBUG_THREADS
34#include <stdlib.h> 46#include <stdlib.h>
@@ -45,6 +57,7 @@ typedef struct _Eina_Lock Eina_Lock;
45typedef struct _Eina_RWLock Eina_RWLock; 57typedef struct _Eina_RWLock Eina_RWLock;
46typedef struct _Eina_Condition Eina_Condition; 58typedef struct _Eina_Condition Eina_Condition;
47typedef pthread_key_t Eina_TLS; 59typedef pthread_key_t Eina_TLS;
60typedef sem_t Eina_Semaphore;
48 61
49struct _Eina_Lock 62struct _Eina_Lock
50{ 63{
@@ -77,8 +90,6 @@ struct _Eina_RWLock
77EAPI extern Eina_Bool _eina_threads_activated; 90EAPI extern Eina_Bool _eina_threads_activated;
78 91
79#ifdef EINA_HAVE_DEBUG_THREADS 92#ifdef EINA_HAVE_DEBUG_THREADS
80# include <sys/time.h>
81
82EAPI extern int _eina_threads_debug; 93EAPI extern int _eina_threads_debug;
83EAPI extern pthread_t _eina_main_loop; 94EAPI extern pthread_t _eina_main_loop;
84EAPI extern pthread_mutex_t _eina_tracking_lock; 95EAPI extern pthread_mutex_t _eina_tracking_lock;
@@ -506,4 +517,40 @@ eina_tls_set(Eina_TLS key, const void *data)
506 return EINA_TRUE; 517 return EINA_TRUE;
507} 518}
508 519
520static inline Eina_Bool
521eina_semaphore_new(Eina_Semaphore *sem, int count_init)
522{
523 if (!sem || (count_init <= 0))
524 return EINA_FALSE;
525
526 return (sem_init(sem, count_init, 1) == 0) ? EINA_TRUE : EINA_FALSE;
527}
528
529static inline Eina_Bool
530eina_semaphore_free(Eina_Semaphore *sem)
531{
532 if (!sem)
533 return EINA_FALSE;
534
535 return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE;
536}
537
538static inline Eina_Bool
539eina_semaphore_lock(Eina_Semaphore *sem)
540{
541 if (!sem)
542 return EINA_FALSE;
543
544 return (sem_wait(sem) == 0) ? EINA_TRUE : EINA_FALSE;
545}
546
547static inline Eina_Bool
548eina_semaphore_release(Eina_Semaphore *sem, int count_release EINA_UNUSED)
549{
550 if (!sem)
551 return EINA_FALSE;
552
553 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE;
554}
555
509#endif 556#endif