| 1 |
/* src/interfaces/ecpg/include/ecpg-pthread-win32.h */ |
| 2 |
/* |
| 3 |
* pthread mapping macros for win32 native thread implementation |
| 4 |
*/ |
| 5 |
#ifndef _ECPG_PTHREAD_WIN32_H |
| 6 |
#define _ECPG_PTHREAD_WIN32_H |
| 7 |
|
| 8 |
#ifndef WIN32 |
| 9 |
|
| 10 |
#include <pthread.h> |
| 11 |
#else |
| 12 |
|
| 13 |
typedef struct pthread_mutex_t |
| 14 |
{ |
| 15 |
/* initstate = 0: not initialized; 1: init done; 2: init in progress */ |
| 16 |
LONG initstate; |
| 17 |
CRITICAL_SECTION csection; |
| 18 |
} pthread_mutex_t; |
| 19 |
|
| 20 |
typedef DWORD pthread_key_t; |
| 21 |
typedef bool pthread_once_t; |
| 22 |
|
| 23 |
#define PTHREAD_MUTEX_INITIALIZER { 0 } |
| 24 |
#define PTHREAD_ONCE_INIT false |
| 25 |
|
| 26 |
int pthread_mutex_init(pthread_mutex_t *, void *attr); |
| 27 |
int pthread_mutex_lock(pthread_mutex_t *); |
| 28 |
int pthread_mutex_unlock(pthread_mutex_t *); |
| 29 |
|
| 30 |
void win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void)); |
| 31 |
|
| 32 |
#define pthread_getspecific(key) \ |
| 33 |
TlsGetValue((key)) |
| 34 |
|
| 35 |
#define pthread_setspecific(key, value) \ |
| 36 |
TlsSetValue((key), (value)) |
| 37 |
|
| 38 |
/* FIXME: destructor is never called in Win32. */ |
| 39 |
#define pthread_key_create(key, destructor) \ |
| 40 |
do { *(key) = TlsAlloc(); ((void)(destructor)); } while(0) |
| 41 |
|
| 42 |
#define pthread_once(once, fn) \ |
| 43 |
do { \ |
| 44 |
if (!*(once)) \ |
| 45 |
win32_pthread_once((once), (fn)); \ |
| 46 |
} while(0) |
| 47 |
#endif /* WIN32 */ |
| 48 |
|
| 49 |
#endif /* _ECPG_PTHREAD_WIN32_H */ |