aboutsummaryrefslogtreecommitdiff
path: root/include/compat/pthread.h
blob: 53d2bbc22bd75f2c7e92309ca0e1c40a8824387e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Public domain
 * pthread.h compatibility shim
 */

#ifdef _WIN32

#include <synchapi.h>

/*
 * Static once initialization values.
 */
#define PTHREAD_ONCE_INIT   { INIT_ONCE_STATIC_INIT }

/*
 * Once definitions.
 */
struct pthread_once {
	INIT_ONCE once;
};

typedef struct pthread_once pthread_once_t;

static BOOL CALLBACK _pthread_once_win32_cb(PINIT_ONCE once, PVOID param, PVOID *context)
{
	void (*cb) (void) = param;
	cb();
    return TRUE;
}

static int pthread_once(pthread_once_t *once, void (*cb) (void))
{
	BOOL rc = InitOnceExecuteOnce(&once->once, _pthread_once_win32_cb, cb, NULL);
	if (rc == 0) {
		return -1;
	} else {
		return 0;
	}
}

#else
#include_next <pthread.h>
#endif