diff options
Diffstat (limited to 'include/cutils/threads.h')
-rw-r--r-- | include/cutils/threads.h | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/include/cutils/threads.h b/include/cutils/threads.h index acf8f48..3133cdb 100644 --- a/include/cutils/threads.h +++ b/include/cutils/threads.h @@ -29,20 +29,22 @@ extern "C" { /***********************************************************************/ /***********************************************************************/ -#ifdef HAVE_PTHREADS +#if !defined(_WIN32) #include <pthread.h> +#include <sys/types.h> typedef struct { pthread_mutex_t lock; int has_tls; pthread_key_t tls; - } thread_store_t; +extern pid_t gettid(); + #define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 } -#elif defined HAVE_WIN32_THREADS +#else // !defined(_WIN32) #include <windows.h> @@ -51,20 +53,17 @@ typedef struct { int has_tls; DWORD tls; CRITICAL_SECTION lock; - } thread_store_t; #define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} } -#else -# error "no thread_store_t implementation for your platform !!" -#endif +#endif // !defined(_WIN32) typedef void (*thread_store_destruct_t)(void* value); extern void* thread_store_get(thread_store_t* store); -extern void thread_store_set(thread_store_t* store, +extern void thread_store_set(thread_store_t* store, void* value, thread_store_destruct_t destroy); @@ -76,7 +75,7 @@ extern void thread_store_set(thread_store_t* store, /***********************************************************************/ /***********************************************************************/ -#ifdef HAVE_PTHREADS +#if !defined(_WIN32) typedef pthread_mutex_t mutex_t; @@ -98,10 +97,10 @@ static __inline__ void mutex_destroy(mutex_t* lock) { pthread_mutex_destroy(lock); } -#endif -#ifdef HAVE_WIN32_THREADS -typedef struct { +#else // !defined(_WIN32) + +typedef struct { int init; CRITICAL_SECTION lock[1]; } mutex_t; @@ -134,10 +133,10 @@ static __inline__ void mutex_destroy(mutex_t* lock) { if (lock->init) { lock->init = 0; - DeleteCriticalSection(lock->lock); + DeleteCriticalSection(lock->lock); } } -#endif +#endif // !defined(_WIN32) #ifdef __cplusplus } |