~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/interfaces/ecpg/include/ecpg-pthread-win32.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $PostgreSQL$ */
 
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
#ifdef ENABLE_THREAD_SAFETY
 
9
 
 
10
#ifndef WIN32
 
11
 
 
12
#include <pthread.h>
 
13
#else
 
14
 
 
15
typedef struct pthread_mutex_t
 
16
{
 
17
        HANDLE          handle;
 
18
        LONG            initlock;
 
19
} pthread_mutex_t;
 
20
 
 
21
typedef DWORD pthread_key_t;
 
22
typedef bool pthread_once_t;
 
23
 
 
24
#define PTHREAD_MUTEX_INITIALIZER       { NULL, 0 }
 
25
#define PTHREAD_ONCE_INIT                       false
 
26
 
 
27
void            win32_pthread_mutex(volatile pthread_mutex_t *mutex);
 
28
void            win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void));
 
29
 
 
30
#define pthread_mutex_lock(mutex) \
 
31
        do { \
 
32
                if ((mutex)->handle == NULL) \
 
33
                        win32_pthread_mutex((mutex)); \
 
34
                WaitForSingleObject((mutex)->handle, INFINITE); \
 
35
        } while(0)
 
36
 
 
37
#define pthread_mutex_unlock(mutex) \
 
38
        ReleaseMutex((mutex)->handle)
 
39
 
 
40
#define pthread_getspecific(key) \
 
41
        TlsGetValue((key))
 
42
 
 
43
#define pthread_setspecific(key, value) \
 
44
        TlsSetValue((key), (value))
 
45
 
 
46
/* FIXME: destructor is never called in Win32. */
 
47
#define pthread_key_create(key, destructor) \
 
48
        do { *(key) = TlsAlloc(); ((void)(destructor)); } while(0)
 
49
 
 
50
#define pthread_once(once, fn) \
 
51
        do { \
 
52
                if (!*(once)) \
 
53
                        win32_pthread_once((once), (fn)); \
 
54
        } while(0)
 
55
#endif   /* WIN32 */
 
56
#endif   /* ENABLE_THREAD_SAFETY */
 
57
 
 
58
#endif   /* _ECPG_PTHREAD_WIN32_H */