add pthread_once(3) implementation for Windows
This commit is contained in:
parent
3fb9e63b90
commit
d5608b38af
43
include/compat/pthread.h
Normal file
43
include/compat/pthread.h
Normal file
@ -0,0 +1,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
|
Loading…
x
Reference in New Issue
Block a user