pthread: non-working once wrapper
authorMarko Kreen <markokr@gmail.com>
Fri, 29 Aug 2014 09:58:18 +0000 (12:58 +0300)
committerMarko Kreen <markokr@gmail.com>
Sat, 30 Aug 2014 16:14:37 +0000 (19:14 +0300)
usual/pthread.c
usual/pthread.h

index c0e6ff8fb5d34ca44b1063b243e1f1e5db624b05..ddec5298b12c2fc405fb5439878f911b98258939 100644 (file)
@@ -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 */
index 1493451d480f5503491ad6c37c18d204c98f0932..9d8e95d22573779d191390d996de01ca22647d89 100644 (file)
@@ -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 */