PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ecpg-pthread-win32.h
Go to the documentation of this file.
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
13typedef struct pthread_mutex_t
14{
15 /* initstate = 0: not initialized; 1: init done; 2: init in progress */
16 LONG initstate;
17 CRITICAL_SECTION csection;
19
20typedef DWORD pthread_key_t;
21typedef bool pthread_once_t;
22
23#define PTHREAD_MUTEX_INITIALIZER { 0 }
24#define PTHREAD_ONCE_INIT false
25
26int pthread_mutex_init(pthread_mutex_t *, void *attr);
29
30void 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 */
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:60
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:42
int pthread_mutex_init(pthread_mutex_t *mp, void *attr)
Definition: pthread-win32.c:35
ULONG pthread_key_t
Definition: pthread-win32.h:7
int pthread_once_t
Definition: pthread-win32.h:18
struct pthread_mutex_t pthread_mutex_t
CRITICAL_SECTION csection
Definition: pthread-win32.h:13
static void * fn(void *arg)
Definition: thread-alloc.c:119