SDL API renaming: SDL TLS functions

Fixes https://github.com/libsdl-org/SDL/issues/7743
This commit is contained in:
Sam Lantinga 2023-05-26 08:32:31 -07:00
parent 2a271aeaf1
commit cb73bed6eb
12 changed files with 92 additions and 52 deletions

View File

@ -2648,3 +2648,23 @@ typedef SDL_cond, SDL_Condition;
@@
- SDL_WINDOW_ALLOW_HIGHDPI
+ SDL_WINDOW_HIGH_PIXEL_DENSITY
@@
@@
- SDL_TLSCreate
+ SDL_CreateTLS
(...)
@@
@@
- SDL_TLSGet
+ SDL_GetTLS
(...)
@@
@@
- SDL_TLSSet
+ SDL_SetTLS
(...)
@@
@@
- SDL_TLSCleanup
+ SDL_CleanupTLS
(...)

View File

@ -1022,6 +1022,14 @@ The structures in this file are versioned separately from the rest of SDL, allow
This function now returns a standard int result instead of SDL_bool, returning 0 if the function succeeds or a negative error code if there was an error. You should also pass SDL_SYSWM_CURRENT_VERSION as the new third version parameter. The version member of the info structure will be filled in with the version of data that is returned, the minimum of the version you requested and the version supported by the runtime SDL library.
## SDL_thread.h
The following functions have been renamed:
* SDL_TLSCleanup() => SDL_CleanupTLS()
* SDL_TLSCreate() => SDL_CreateTLS()
* SDL_TLSGet() => SDL_GetTLS()
* SDL_TLSSet() => SDL_SetTLS()
## SDL_timer.h
SDL_GetTicks() now returns a 64-bit value. Instead of using the SDL_TICKS_PASSED macro, you can directly compare tick values, e.g.

View File

@ -455,6 +455,12 @@
#define SDL_RenderGetD3D11Device SDL_GetRenderD3D11Device
#define SDL_RenderGetD3D9Device SDL_GetRenderD3D9Device
/* ##SDL_thread.h */
#define SDL_TLSCleanup SDL_CleanupTLS
#define SDL_TLSCreate SDL_CreateTLS
#define SDL_TLSGet SDL_GetTLS
#define SDL_TLSSet SDL_SetTLS
/* ##SDL_timer.h */
#define SDL_GetTicks64 SDL_GetTicks
@ -885,6 +891,12 @@
#define SDL_RenderGetD3D11Device SDL_RenderGetD3D11Device_renamed_SDL_GetRenderD3D11Device
#define SDL_RenderGetD3D9Device SDL_RenderGetD3D9Device_renamed_SDL_GetRenderD3D9Device
/* ##SDL_thread.h */
#define SDL_TLSCleanup SDL_TLSCleanup_renamed_SDL_CleanupTLS
#define SDL_TLSCreate SDL_TLSCreate_renamed_SDL_CreateTLS
#define SDL_TLSGet SDL_TLSGet_renamed_SDL_GetTLS
#define SDL_TLSSet SDL_TLSSet_renamed_SDL_SetTLS
/* ##SDL_timer.h */
#define SDL_GetTicks64 SDL_GetTicks64_renamed_SDL_GetTicks

View File

@ -387,10 +387,10 @@ extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_TLSGet
* \sa SDL_TLSSet
* \sa SDL_GetTLS
* \sa SDL_SetTLS
*/
extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
extern DECLSPEC SDL_TLSID SDLCALL SDL_CreateTLS(void);
/**
* Get the current thread's value associated with a thread local storage ID.
@ -401,10 +401,10 @@ extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_TLSCreate
* \sa SDL_TLSSet
* \sa SDL_CreateTLS
* \sa SDL_SetTLS
*/
extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
extern DECLSPEC void * SDLCALL SDL_GetTLS(SDL_TLSID id);
/**
* Set the current thread's value associated with a thread local storage ID.
@ -415,7 +415,7 @@ extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
* void destructor(void *value)
* ```
*
* where its parameter `value` is what was passed as `value` to SDL_TLSSet().
* where its parameter `value` is what was passed as `value` to SDL_SetTLS().
*
* \param id the thread local storage ID
* \param value the value to associate with the ID for the current thread
@ -426,17 +426,17 @@ extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_TLSCreate
* \sa SDL_TLSGet
* \sa SDL_CreateTLS
* \sa SDL_GetTLS
*/
extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
extern DECLSPEC int SDLCALL SDL_SetTLS(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
/**
* Cleanup all TLS data for this thread.
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC void SDLCALL SDL_TLSCleanup(void);
extern DECLSPEC void SDLCALL SDL_CleanupTLS(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -506,7 +506,7 @@ void SDL_Quit(void)
*/
SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
SDL_TLSCleanup();
SDL_CleanupTLS();
SDL_bInMainQuit = SDL_FALSE;
}

View File

@ -634,10 +634,10 @@ SDL3_0.0.0 {
SDL_StopTextInput;
SDL_SurfaceHasColorKey;
SDL_SurfaceHasRLE;
SDL_TLSCleanup;
SDL_TLSCreate;
SDL_TLSGet;
SDL_TLSSet;
SDL_CleanupTLS;
SDL_CreateTLS;
SDL_GetTLS;
SDL_SetTLS;
SDL_TextInputActive;
SDL_TextInputShown;
SDL_ThreadID;

View File

@ -658,10 +658,10 @@
#define SDL_StopTextInput SDL_StopTextInput_REAL
#define SDL_SurfaceHasColorKey SDL_SurfaceHasColorKey_REAL
#define SDL_SurfaceHasRLE SDL_SurfaceHasRLE_REAL
#define SDL_TLSCleanup SDL_TLSCleanup_REAL
#define SDL_TLSCreate SDL_TLSCreate_REAL
#define SDL_TLSGet SDL_TLSGet_REAL
#define SDL_TLSSet SDL_TLSSet_REAL
#define SDL_CleanupTLS SDL_CleanupTLS_REAL
#define SDL_CreateTLS SDL_CreateTLS_REAL
#define SDL_GetTLS SDL_GetTLS_REAL
#define SDL_SetTLS SDL_SetTLS_REAL
#define SDL_TextInputActive SDL_TextInputActive_REAL
#define SDL_TextInputShown SDL_TextInputShown_REAL
#define SDL_ThreadID SDL_ThreadID_REAL

View File

@ -713,10 +713,10 @@ SDL_DYNAPI_PROC(void,SDL_StartTextInput,(void),(),)
SDL_DYNAPI_PROC(void,SDL_StopTextInput,(void),(),)
SDL_DYNAPI_PROC(SDL_bool,SDL_SurfaceHasColorKey,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_SurfaceHasRLE,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_TLSCleanup,(void),(),)
SDL_DYNAPI_PROC(SDL_TLSID,SDL_TLSCreate,(void),(),return)
SDL_DYNAPI_PROC(void*,SDL_TLSGet,(SDL_TLSID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_TLSSet,(SDL_TLSID a, const void *b, void (SDLCALL *c)(void*)),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_CleanupTLS,(void),(),)
SDL_DYNAPI_PROC(SDL_TLSID,SDL_CreateTLS,(void),(),return)
SDL_DYNAPI_PROC(void*,SDL_GetTLS,(SDL_TLSID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetTLS,(SDL_TLSID a, const void *b, void (SDLCALL *c)(void*)),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_TextInputActive,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_TextInputShown,(void),(),return)
SDL_DYNAPI_PROC(SDL_threadID,SDL_ThreadID,(void),(),return)

View File

@ -26,13 +26,13 @@
#include "SDL_systhread.h"
#include "../SDL_error_c.h"
SDL_TLSID SDL_TLSCreate(void)
SDL_TLSID SDL_CreateTLS(void)
{
static SDL_AtomicInt SDL_tls_id;
return SDL_AtomicIncRef(&SDL_tls_id) + 1;
}
void *SDL_TLSGet(SDL_TLSID id)
void *SDL_GetTLS(SDL_TLSID id)
{
SDL_TLSData *storage;
@ -43,7 +43,7 @@ void *SDL_TLSGet(SDL_TLSID id)
return storage->array[id - 1].data;
}
int SDL_TLSSet(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *))
int SDL_SetTLS(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *))
{
SDL_TLSData *storage;
@ -76,7 +76,7 @@ int SDL_TLSSet(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *
return 0;
}
void SDL_TLSCleanup(void)
void SDL_CleanupTLS(void)
{
SDL_TLSData *storage;
@ -224,7 +224,7 @@ SDL_error *SDL_GetErrBuf(void)
const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
SDL_error *errbuf;
/* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails.
/* tls_being_created is there simply to prevent recursion if SDL_CreateTLS() fails.
It also means it's possible for another thread to also use SDL_global_errbuf,
but that's very unlikely and hopefully won't cause issues.
*/
@ -233,7 +233,7 @@ SDL_error *SDL_GetErrBuf(void)
if (!tls_errbuf) {
SDL_TLSID slot;
tls_being_created = SDL_TRUE;
slot = SDL_TLSCreate();
slot = SDL_CreateTLS();
tls_being_created = SDL_FALSE;
SDL_MemoryBarrierRelease();
tls_errbuf = slot;
@ -245,7 +245,7 @@ SDL_error *SDL_GetErrBuf(void)
}
SDL_MemoryBarrierAcquire();
errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf);
errbuf = (SDL_error *)SDL_GetTLS(tls_errbuf);
if (errbuf == ALLOCATION_IN_PROGRESS) {
return SDL_GetStaticErrBuf();
}
@ -258,16 +258,16 @@ SDL_error *SDL_GetErrBuf(void)
SDL_GetOriginalMemoryFunctions(NULL, NULL, &realloc_func, &free_func);
/* Mark that we're in the middle of allocating our buffer */
SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
SDL_SetTLS(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
errbuf = (SDL_error *)realloc_func(NULL, sizeof(*errbuf));
if (errbuf == NULL) {
SDL_TLSSet(tls_errbuf, NULL, NULL);
SDL_SetTLS(tls_errbuf, NULL, NULL);
return SDL_GetStaticErrBuf();
}
SDL_zerop(errbuf);
errbuf->realloc_func = realloc_func;
errbuf->free_func = free_func;
SDL_TLSSet(tls_errbuf, errbuf, SDL_FreeErrBuf);
SDL_SetTLS(tls_errbuf, errbuf, SDL_FreeErrBuf);
}
return errbuf;
#endif /* SDL_THREADS_DISABLED */
@ -290,7 +290,7 @@ void SDL_RunThread(SDL_Thread *thread)
*statusloc = userfunc(userdata);
/* Clean up thread-local storage */
SDL_TLSCleanup();
SDL_CleanupTLS();
/* Mark us as ready to be joined (or detached) */
if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {

View File

@ -37,13 +37,13 @@ HANDLE SDL_GetWaitableTimer()
HANDLE timer;
if (!TLS_timer_handle) {
TLS_timer_handle = SDL_TLSCreate();
TLS_timer_handle = SDL_CreateTLS();
}
timer = SDL_TLSGet(TLS_timer_handle);
timer = SDL_GetTLS(TLS_timer_handle);
if (!timer) {
timer = CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
if (timer) {
SDL_TLSSet(TLS_timer_handle, timer, SDL_CleanupWaitableTimer);
SDL_SetTLS(TLS_timer_handle, timer, SDL_CleanupWaitableTimer);
}
}
return timer;

View File

@ -521,8 +521,8 @@ int SDL_VideoInit(const char *driver_name)
_this->gl_config.dll_handle = NULL;
SDL_GL_ResetAttributes();
_this->current_glwin_tls = SDL_TLSCreate();
_this->current_glctx_tls = SDL_TLSCreate();
_this->current_glwin_tls = SDL_CreateTLS();
_this->current_glctx_tls = SDL_CreateTLS();
/* Initialize the video subsystem */
if (_this->VideoInit(_this) < 0) {
@ -4357,8 +4357,8 @@ SDL_GLContext SDL_GL_CreateContext(SDL_Window *window)
if (ctx) {
_this->current_glwin = window;
_this->current_glctx = ctx;
SDL_TLSSet(_this->current_glwin_tls, window, NULL);
SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
SDL_SetTLS(_this->current_glwin_tls, window, NULL);
SDL_SetTLS(_this->current_glctx_tls, ctx, NULL);
}
return ctx;
}
@ -4393,8 +4393,8 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context)
if (retval == 0) {
_this->current_glwin = window;
_this->current_glctx = context;
SDL_TLSSet(_this->current_glwin_tls, window, NULL);
SDL_TLSSet(_this->current_glctx_tls, context, NULL);
SDL_SetTLS(_this->current_glwin_tls, window, NULL);
SDL_SetTLS(_this->current_glctx_tls, context, NULL);
}
return retval;
}
@ -4405,7 +4405,7 @@ SDL_Window *SDL_GL_GetCurrentWindow(void)
SDL_UninitializedVideo();
return NULL;
}
return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls);
return (SDL_Window *)SDL_GetTLS(_this->current_glwin_tls);
}
SDL_GLContext SDL_GL_GetCurrentContext(void)
@ -4414,7 +4414,7 @@ SDL_GLContext SDL_GL_GetCurrentContext(void)
SDL_UninitializedVideo();
return NULL;
}
return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
return (SDL_GLContext)SDL_GetTLS(_this->current_glctx_tls);
}
SDL_EGLDisplay SDL_EGL_GetCurrentEGLDisplay(void)

View File

@ -58,9 +58,9 @@ ThreadFunc(void *data)
{
SDL_ThreadPriority prio = SDL_THREAD_PRIORITY_NORMAL;
SDL_TLSSet(tls, "baby thread", NULL);
SDL_SetTLS(tls, "baby thread", NULL);
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *)data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
(char *)data, SDL_ThreadID(), (const char *)SDL_GetTLS(tls));
while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *)data);
@ -132,10 +132,10 @@ int main(int argc, char *argv[])
return 0;
}
tls = SDL_TLSCreate();
tls = SDL_CreateTLS();
SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
SDL_SetTLS(tls, "main thread", NULL);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_GetTLS(tls));
alive = 1;
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
@ -148,7 +148,7 @@ int main(int argc, char *argv[])
alive = 0;
SDL_WaitThread(thread, NULL);
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_GetTLS(tls));
alive = 1;
(void)signal(SIGTERM, killed);