summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2014-08-29 09:58:18 +0000
committerMarko Kreen2014-08-30 16:14:37 +0000
commit84463fe8f68c472c74378ffe5b35afd27600ecbd (patch)
tree84226f9903e902c5acc019674ed123c598f65aaf
parentd9649d1a5b7861fefd5bbf1ac9d61839b850652e (diff)
pthread: non-working once wrapper
-rw-r--r--usual/pthread.c14
-rw-r--r--usual/pthread.h5
2 files changed, 19 insertions, 0 deletions
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 */