X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=compat%2Fwin32%2Fpthread.h;h=2e205485570bf62a11112c665624203207c724a9;hb=6bead0c3203431ca63a6b1e7cf47c659f1a7021d;hp=c72f100f40ce2ab9ae7abead730ed00c2a461fbf;hpb=755f0e36bcaaeb1c95726faaccb10da800803570;p=git.git diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h index c72f100f4..2e2054855 100644 --- a/compat/win32/pthread.h +++ b/compat/win32/pthread.h @@ -18,11 +18,17 @@ */ #define pthread_mutex_t CRITICAL_SECTION -#define pthread_mutex_init(a,b) InitializeCriticalSection((a)) +#define pthread_mutex_init(a,b) (InitializeCriticalSection((a)), 0) #define pthread_mutex_destroy(a) DeleteCriticalSection((a)) #define pthread_mutex_lock EnterCriticalSection #define pthread_mutex_unlock LeaveCriticalSection +typedef int pthread_mutexattr_t; +#define pthread_mutexattr_init(a) (*(a) = 0) +#define pthread_mutexattr_destroy(a) do {} while (0) +#define pthread_mutexattr_settype(a, t) 0 +#define PTHREAD_MUTEX_RECURSIVE 0 + /* * Implement simple condition variable for Windows threads, based on ACE * implementation. @@ -52,6 +58,7 @@ typedef struct { HANDLE handle; void *(*start_routine)(void*); void *arg; + DWORD tid; } pthread_t; extern int pthread_create(pthread_t *thread, const void *unused, @@ -65,4 +72,28 @@ extern int pthread_create(pthread_t *thread, const void *unused, extern int win32_pthread_join(pthread_t *thread, void **value_ptr); +#define pthread_equal(t1, t2) ((t1).tid == (t2).tid) +extern pthread_t pthread_self(void); + +static inline int pthread_exit(void *ret) +{ + ExitThread((DWORD)ret); +} + +typedef DWORD pthread_key_t; +static inline int pthread_key_create(pthread_key_t *keyp, void (*destructor)(void *value)) +{ + return (*keyp = TlsAlloc()) == TLS_OUT_OF_INDEXES ? EAGAIN : 0; +} + +static inline int pthread_setspecific(pthread_key_t key, const void *value) +{ + return TlsSetValue(key, (void *)value) ? 0 : EINVAL; +} + +static inline void *pthread_getspecific(pthread_key_t key) +{ + return TlsGetValue(key); +} + #endif /* PTHREAD_H */