]> git.draconx.ca Git - cdecl99.git/blob - src/thread-w32.h
libcdecl: Punt gnulib tls module.
[cdecl99.git] / src / thread-w32.h
1 /*
2  * Copyright © 2024 Nick Bowler
3  *
4  * Helpers for hosts using native Windows threading API.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19
20 #define WIN32_LEAN_AND_MEAN
21 #include <windows.h>
22
23 static DWORD tls_key;
24 #define tls_key_valid (tls_key != TLS_OUT_OF_INDEXES)
25
26 static void tls_key_init(void)
27 {
28         tls_key = TlsAlloc();
29 }
30
31 static void *tls_get(void)
32 {
33         return TlsGetValue(tls_key);
34 }
35
36 static BOOL tls_set(void *p)
37 {
38         return TlsSetValue(tls_key, p);
39 }