Patch by Vincent Torri.
SVN revision: 66693
2011-12-28 Cedric Bail
* Fix NONNULL argument for eina_hash_find.
+
+2011-12-30 Vincent Torri
+
+ * Add Eina_Semaphore abstraction API.
Additions:
* eina_mempool_calloc
+ * Eina_Semaphore abstraction API
Eina 1.1.0
#ifndef EINA_INLINE_LOCK_POSIX_X_
#define EINA_INLINE_LOCK_POSIX_X_
+#ifdef EINA_UNUSED
+# undef EINA_UNUSED
+#endif
+#ifdef __GNUC__
+# define EINA_UNUSED __attribute__((unused))
+#else
+# define EINA_UNUSED
+#endif
+
#include <errno.h>
#ifndef __USE_UNIX98
# define __USE_UNIX98
# include <pthread.h>
#endif
+#include <semaphore.h>
+
#include <sys/time.h>
#include <stdio.h>
typedef struct _Eina_RWLock Eina_RWLock;
typedef struct _Eina_Condition Eina_Condition;
typedef pthread_key_t Eina_TLS;
+typedef sem_t Eina_Semaphore;
struct _Eina_Lock
{
return EINA_TRUE;
}
+static inline Eina_Bool
+eina_semaphore_new(Eina_Semaphore *sem, int count_init)
+{
+ if (!sem || (count_init <= 0))
+ return EINA_FALSE;
+
+ return (sem_init(sem, count_init, 1) == 0) ? EINA_TRUE : EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_free(Eina_Semaphore *sem)
+{
+ if (!sem)
+ return EINA_FALSE;
+
+ return (sem_destroy(sem) == 0) ? EINA_TRUE : EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_lock(Eina_Semaphore *sem)
+{
+ if (!sem)
+ return EINA_FALSE;
+
+ return (sem_wait(sem) == 0) ? EINA_TRUE : EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_release(Eina_Semaphore *sem, int count_release EINA_UNUSED)
+{
+ if (!sem)
+ return EINA_FALSE;
+
+ return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE;
+}
+
#endif
typedef void *Eina_RWLock;
typedef void *Eina_Condition;
typedef void *Eina_TLS;
+typedef void *Eina_Semaphore;
/**
* @brief Create a new #Eina_Lock.
return EINA_FALSE;
}
+static inline Eina_Bool
+eina_semaphore_new(Eina_Semaphore *sem EINA_UNUSED,
+ int count_init EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_free(Eina_Semaphore *sem EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_lock(Eina_Semaphore *sem EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_release(Eina_Semaphore *sem EINA_UNUSED,
+ int count_release EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
/**
* @}
typedef DWORD Eina_TLS;
+typedef HANDLE Eina_Semaphore;
+
EAPI extern Eina_Bool _eina_threads_activated;
static inline Eina_Bool
return EINA_TRUE;
}
+static inline Eina_Bool
+eina_semaphore_new(Eina_Semaphore *sem, int count_init)
+{
+ if (!sem || (count_init <= 0))
+ return EINA_FALSE;
+
+ *sem = CreateSemaphore(NULL, count_init, 32767, NULL);
+ if (!*sem)
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_free(Eina_Semaphore *sem)
+{
+ if (!sem)
+ return EINA_FALSE;
+
+ CloseHandle(*sem);
+}
+
+static inline Eina_Bool
+eina_semaphore_lock(Eina_Semaphore *sem)
+{
+ DWORD res;
+
+ if (!sem)
+ return EINA_FALSE;
+
+ res = WaitForSingleObject(ev->shared->lock, 0L);
+ if (res == WAIT_OBJECT_0)
+ return EINA_TRUE;
+
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_release(Eina_Semaphore *sem, int count_release)
+{
+ if (!sem)
+ return EINA_FALSE;
+
+ return ReleaseSemaphore(*sem, count_release, NULL) ? EINA_TRUE : EINA_FALSE;
+}
+
#endif
#ifndef EINA_INLINE_LOCK_WIN32_X_
#define EINA_INLINE_LOCK_WIN32_X_
+#ifdef EINA_UNUSED
+# undef EINA_UNUSED
+#endif
+#ifdef __GNUC__
+# define EINA_UNUSED __attribute__((unused))
+#else
+# define EINA_UNUSED
+#endif
+
#include <windows.h>
EAPI extern Eina_Bool _threads_activated;
typedef HANDLE Eina_Lock;
typedef Eina_Lock Eina_RWLock;
typedef DWORD Eina_TLS;
+typedef void * Eina_Semaphore;
static inline Eina_Bool
eina_lock_new(Eina_Lock *mutex)
return EINA_TRUE;
}
+static inline Eina_Bool
+eina_semaphore_new(Eina_Semaphore *sem EINA_UNUSED,
+ int count_init EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+static inline Eina_Bool
+eina_semaphore_free(Eina_Semaphore *sem EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_lock(Eina_Semaphore *sem EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
+
+static inline Eina_Bool
+eina_semaphore_release(Eina_Semaphore *sem EINA_UNUSED,
+ int count_release EINA_UNUSED)
+{
+ return EINA_FALSE;
+}
#endif
static inline void *eina_tls_get(Eina_TLS key);
static inline Eina_Bool eina_tls_set(Eina_TLS key, const void *data);
+static inline Eina_Bool eina_semaphore_new(Eina_Semaphore *sem, int count_init);
+static inline Eina_Bool eina_semaphore_free(Eina_Semaphore *sem);
+static inline Eina_Bool eina_semaphore_lock(Eina_Semaphore *sem);
+static inline Eina_Bool eina_semaphore_release(Eina_Semaphore *sem, int count_release);
#ifdef EINA_HAVE_DEBUG_THREADS
# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val) \