X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/1b96e9580714d7a677d10a8e286b3f8a2bddc6f5..c11f668ec9c5b2f0016cf6920a111c52e895b24a:/src/thread-stdc.h diff --git a/src/thread-stdc.h b/src/thread-stdc.h index 46fe361..a29ec8c 100644 --- a/src/thread-stdc.h +++ b/src/thread-stdc.h @@ -22,10 +22,7 @@ static tss_t tls_key; static bool tls_key_valid; -static void tls_key_init(void) -{ - tls_key_valid = (tss_create(&tls_key, free) == thrd_success); -} +static void init_once_cb(void); static void *tls_get(void) { @@ -36,3 +33,17 @@ static int tls_set(void *p) { return tss_set(tls_key, p) == thrd_success; } + +static void init_once_with_tls(void) +{ + tls_key_valid = (tss_create(&tls_key, free) == thrd_success); + init_once_cb(); +} + +static int init_once(void) +{ + static once_flag flag; + + call_once(&flag, init_once_with_tls); + return 1; +}