diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/thread/windows/SDL_systls.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/thread/windows/SDL_systls.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/thread/windows/SDL_systls.c b/contrib/SDL-3.2.8/src/thread/windows/SDL_systls.c new file mode 100644 index 0000000..354016a --- /dev/null +++ b/contrib/SDL-3.2.8/src/thread/windows/SDL_systls.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "SDL_internal.h" | ||
| 23 | |||
| 24 | #ifdef SDL_THREAD_WINDOWS | ||
| 25 | |||
| 26 | #include "../../core/windows/SDL_windows.h" | ||
| 27 | |||
| 28 | #include "../SDL_thread_c.h" | ||
| 29 | |||
| 30 | static DWORD thread_local_storage = TLS_OUT_OF_INDEXES; | ||
| 31 | static bool generic_local_storage = false; | ||
| 32 | |||
| 33 | void SDL_SYS_InitTLSData(void) | ||
| 34 | { | ||
| 35 | if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) { | ||
| 36 | thread_local_storage = TlsAlloc(); | ||
| 37 | if (thread_local_storage == TLS_OUT_OF_INDEXES) { | ||
| 38 | SDL_Generic_InitTLSData(); | ||
| 39 | generic_local_storage = true; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | SDL_TLSData *SDL_SYS_GetTLSData(void) | ||
| 45 | { | ||
| 46 | if (generic_local_storage) { | ||
| 47 | return SDL_Generic_GetTLSData(); | ||
| 48 | } | ||
| 49 | |||
| 50 | if (thread_local_storage != TLS_OUT_OF_INDEXES) { | ||
| 51 | return (SDL_TLSData *)TlsGetValue(thread_local_storage); | ||
| 52 | } | ||
| 53 | return NULL; | ||
| 54 | } | ||
| 55 | |||
| 56 | bool SDL_SYS_SetTLSData(SDL_TLSData *data) | ||
| 57 | { | ||
| 58 | if (generic_local_storage) { | ||
| 59 | return SDL_Generic_SetTLSData(data); | ||
| 60 | } | ||
| 61 | |||
| 62 | if (!TlsSetValue(thread_local_storage, data)) { | ||
| 63 | return WIN_SetError("TlsSetValue()"); | ||
| 64 | } | ||
| 65 | return true; | ||
| 66 | } | ||
| 67 | |||
| 68 | void SDL_SYS_QuitTLSData(void) | ||
| 69 | { | ||
| 70 | if (generic_local_storage) { | ||
| 71 | SDL_Generic_QuitTLSData(); | ||
| 72 | generic_local_storage = false; | ||
| 73 | } else { | ||
| 74 | if (thread_local_storage != TLS_OUT_OF_INDEXES) { | ||
| 75 | TlsFree(thread_local_storage); | ||
| 76 | thread_local_storage = TLS_OUT_OF_INDEXES; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | #endif // SDL_THREAD_WINDOWS | ||
