From 84463fe8f68c472c74378ffe5b35afd27600ecbd Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 29 Aug 2014 12:58:18 +0300 Subject: [PATCH] pthread: non-working once wrapper --- usual/pthread.c | 14 ++++++++++++++ usual/pthread.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/usual/pthread.c b/usual/pthread.c index c0e6ff8..ddec529 100644 --- a/usual/pthread.c +++ b/usual/pthread.c @@ -90,5 +90,19 @@ int pthread_mutex_unlock(pthread_mutex_t *lock) return 0; } +typedef void (*once_posix_cb_t)(void); + +static BOOL once_wrapper(PINIT_ONCE once, void *arg, void **ctx) +{ + once_posix_cb_t cb = arg; + arg(); + return TRUE; +} + +int pthread_once(pthread_once_t *once, void (*once_func)(void)) +{ + return InitOnceExecuteOnce(once, once_wrapper, once_func, NULL) ? 0 : -1; +} + #endif /* win32 */ #endif /* !HAVE_PTHREAD_H */ diff --git a/usual/pthread.h b/usual/pthread.h index 1493451..9d8e95d 100644 --- a/usual/pthread.h +++ b/usual/pthread.h @@ -36,6 +36,7 @@ #define pthread_mutex_lock(a) compat_pthread_mutex_lock(a) #define pthread_mutex_unlock(a) compat_pthread_mutex_unlock(a) #define pthread_join(a,b) compat_pthread_join(a,b) +#define pthread_once(a,b) compat_pthread_once(a,b) typedef HANDLE pthread_t; typedef HANDLE pthread_mutex_t; @@ -48,6 +49,10 @@ int pthread_mutex_lock(pthread_mutex_t *lock); int pthread_mutex_unlock(pthread_mutex_t *lock); int pthread_join(pthread_t *t, void **ret); +#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT +typedef INIT_ONCE pthread_once_t; +int pthread_once(pthread_once_t *once, void (*once_func)(void)); + #endif /* WIN32 */ #endif /* HAVE_PTHREAD_H */ -- 2.39.5