X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/1b96e9580714d7a677d10a8e286b3f8a2bddc6f5..c11f668ec9c5b2f0016cf6920a111c52e895b24a:/src/thread-w32.h diff --git a/src/thread-w32.h b/src/thread-w32.h index 44282d8..fb3bdc4 100644 --- a/src/thread-w32.h +++ b/src/thread-w32.h @@ -19,14 +19,12 @@ #define WIN32_LEAN_AND_MEAN #include +#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; +}