Path: blob/master/thirdparty/sdl/thread/windows/SDL_systls.c
9905 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021#include "SDL_internal.h"2223#ifdef SDL_THREAD_WINDOWS2425#include "../../core/windows/SDL_windows.h"2627#include "../SDL_thread_c.h"2829static DWORD thread_local_storage = TLS_OUT_OF_INDEXES;30static bool generic_local_storage = false;3132void SDL_SYS_InitTLSData(void)33{34if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) {35thread_local_storage = TlsAlloc();36if (thread_local_storage == TLS_OUT_OF_INDEXES) {37SDL_Generic_InitTLSData();38generic_local_storage = true;39}40}41}4243SDL_TLSData *SDL_SYS_GetTLSData(void)44{45if (generic_local_storage) {46return SDL_Generic_GetTLSData();47}4849if (thread_local_storage != TLS_OUT_OF_INDEXES) {50return (SDL_TLSData *)TlsGetValue(thread_local_storage);51}52return NULL;53}5455bool SDL_SYS_SetTLSData(SDL_TLSData *data)56{57if (generic_local_storage) {58return SDL_Generic_SetTLSData(data);59}6061if (!TlsSetValue(thread_local_storage, data)) {62return WIN_SetError("TlsSetValue()");63}64return true;65}6667void SDL_SYS_QuitTLSData(void)68{69if (generic_local_storage) {70SDL_Generic_QuitTLSData();71generic_local_storage = false;72} else {73if (thread_local_storage != TLS_OUT_OF_INDEXES) {74TlsFree(thread_local_storage);75thread_local_storage = TLS_OUT_OF_INDEXES;76}77}78}7980#endif // SDL_THREAD_WINDOWS818283