1 /* src/interfaces/ecpg/include/ecpg-pthread-win32.h */
3 * pthread mapping macros for win32 native thread implementation
5 #ifndef _ECPG_PTHREAD_WIN32_H
6 #define _ECPG_PTHREAD_WIN32_H
8 #ifdef ENABLE_THREAD_SAFETY
15 typedef struct pthread_mutex_t
21 typedef DWORD pthread_key_t;
22 typedef bool pthread_once_t;
24 #define PTHREAD_MUTEX_INITIALIZER { NULL, 0 }
25 #define PTHREAD_ONCE_INIT false
27 void win32_pthread_mutex(volatile pthread_mutex_t *mutex);
28 void win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void));
30 #define pthread_mutex_lock(mutex) \
32 if ((mutex)->handle == NULL) \
33 win32_pthread_mutex((mutex)); \
34 WaitForSingleObject((mutex)->handle, INFINITE); \
37 #define pthread_mutex_unlock(mutex) \
38 ReleaseMutex((mutex)->handle)
40 #define pthread_getspecific(key) \
43 #define pthread_setspecific(key, value) \
44 TlsSetValue((key), (value))
46 /* FIXME: destructor is never called in Win32. */
47 #define pthread_key_create(key, destructor) \
48 do { *(key) = TlsAlloc(); ((void)(destructor)); } while(0)
50 #define pthread_once(once, fn) \
53 win32_pthread_once((once), (fn)); \
56 #endif /* ENABLE_THREAD_SAFETY */
58 #endif /* _ECPG_PTHREAD_WIN32_H */