]> git.draconx.ca Git - cdecl99.git/blobdiff - src/thread-w32.h
libcdecl: Punt gnulib lock module.
[cdecl99.git] / src / thread-w32.h
index 44282d87dd8d39a9a0c6848b8279697f4474c12b..fb3bdc40870e4ee005185215a429bfdafc3d856e 100644 (file)
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#include "windows-once.h"
 
 static DWORD tls_key;
 #define tls_key_valid (tls_key != TLS_OUT_OF_INDEXES)
 
-static void tls_key_init(void)
-{
-       tls_key = TlsAlloc();
-}
+static void init_once_cb(void);
 
 static void *tls_get(void)
 {
@@ -37,3 +35,17 @@ static BOOL tls_set(void *p)
 {
        return TlsSetValue(tls_key, p);
 }
+
+static void init_once_with_tls(void)
+{
+       tls_key = TlsAlloc();
+       init_once_cb();
+}
+
+static int init_once(void)
+{
+       static glwthread_once_t ctrl = GLWTHREAD_ONCE_INIT;
+
+       glwthread_once(&ctrl, init_once_with_tls);
+       return 1;
+}