SDL: Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()

From fc0c77497649dc6569010ca1ef54e962c8812244 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 18 Jan 2024 04:57:12 -0800
Subject: [PATCH] Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()

Also renamed SDL_threadID to SDL_ThreadID and made it Uint64 for consistency with other ID types
---
 build-scripts/SDL_migration.cocci      |  9 ++++++++
 docs/README-migration.md               |  4 ++++
 include/SDL3/SDL_oldnames.h            |  2 ++
 include/SDL3/SDL_thread.h              |  8 +++----
 src/audio/wasapi/SDL_wasapi.c          |  2 +-
 src/dynapi/SDL_dynapi.sym              |  2 +-
 src/dynapi/SDL_dynapi_overrides.h      |  2 +-
 src/dynapi/SDL_dynapi_procs.h          |  4 ++--
 src/hidapi/SDL_hidapi.c                |  6 +++---
 src/thread/SDL_thread.c                | 14 ++++++------
 src/thread/SDL_thread_c.h              |  2 +-
 src/thread/generic/SDL_sysmutex.c      |  8 +++----
 src/thread/generic/SDL_sysrwlock.c     |  2 +-
 src/thread/generic/SDL_systhread.c     |  2 +-
 src/thread/n3ds/SDL_systhread.c        |  4 ++--
 src/thread/ngage/SDL_systhread.cpp     |  2 +-
 src/thread/ps2/SDL_systhread.c         |  4 ++--
 src/thread/psp/SDL_systhread.c         |  4 ++--
 src/thread/pthread/SDL_systhread.c     |  4 ++--
 src/thread/stdcpp/SDL_sysrwlock.cpp    |  8 +++----
 src/thread/stdcpp/SDL_systhread.cpp    | 10 ++++-----
 src/thread/vita/SDL_systhread.c        |  4 ++--
 src/thread/windows/SDL_sysrwlock_srw.c |  6 +++---
 src/thread/windows/SDL_systhread.c     |  4 ++--
 src/video/SDL_sysvideo.h               |  2 +-
 src/video/SDL_sysvideocapture.h        |  2 +-
 src/video/SDL_video.c                  |  4 ++--
 src/video/SDL_video_capture.c          |  2 +-
 test/testerror.c                       |  4 ++--
 test/testlock.c                        | 30 ++++++++++++++------------
 test/testrwlock.c                      | 18 ++++++++--------
 test/testthread.c                      |  4 ++--
 32 files changed, 100 insertions(+), 83 deletions(-)

diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 2e7f1e519e9f..768ec36c26a3 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -2909,3 +2909,12 @@ expression e1, e2, e3, e4;
 - SDL_AtomicCASPtr
 + SDL_AtomicCompareAndSwapPointer
   (...)
+@@
+@@
+- SDL_ThreadID
++ SDL_GetCurrentThreadID
+  (...)
+@@
+@@
+- SDL_threadID
++ SDL_ThreadID
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 10c484d147e9..1b1f493b88ad 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1406,6 +1406,10 @@ The following functions have been renamed:
 * SDL_TLSCreate() => SDL_CreateTLS()
 * SDL_TLSGet() => SDL_GetTLS()
 * SDL_TLSSet() => SDL_SetTLS()
+* SDL_ThreadID() => SDL_GetCurrentThreadID()
+
+The following symbols have been renamed:
+* SDL_threadID => SDL_ThreadID
 
 ## SDL_timer.h
 
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index ac779d0368f4..b923d73f3d5b 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -498,6 +498,7 @@
 #define SDL_TLSCreate SDL_CreateTLS
 #define SDL_TLSGet SDL_GetTLS
 #define SDL_TLSSet SDL_SetTLS
+#define SDL_threadID SDL_ThreadID
 
 /* ##SDL_timer.h */
 #define SDL_GetTicks64 SDL_GetTicks
@@ -976,6 +977,7 @@
 #define SDL_TLSCreate SDL_TLSCreate_renamed_SDL_CreateTLS
 #define SDL_TLSGet SDL_TLSGet_renamed_SDL_GetTLS
 #define SDL_TLSSet SDL_TLSSet_renamed_SDL_SetTLS
+#define SDL_threadID SDL_threadID_renamed_SDL_ThreadID
 
 /* ##SDL_timer.h */
 #define SDL_GetTicks64 SDL_GetTicks64_renamed_SDL_GetTicks
diff --git a/include/SDL3/SDL_thread.h b/include/SDL3/SDL_thread.h
index 3fe881e5d344..9f10ec0a5045 100644
--- a/include/SDL3/SDL_thread.h
+++ b/include/SDL3/SDL_thread.h
@@ -50,7 +50,7 @@ struct SDL_Thread;
 typedef struct SDL_Thread SDL_Thread;
 
 /* The SDL thread ID */
-typedef unsigned long SDL_threadID;
+typedef Uint64 SDL_ThreadID;
 
 /* Thread local storage ID, 0 is the invalid ID */
 typedef unsigned int SDL_TLSID;
@@ -269,7 +269,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
  *
  * \sa SDL_GetThreadID
  */
-extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
+extern DECLSPEC SDL_ThreadID SDLCALL SDL_GetCurrentThreadID(void);
 
 /**
  * Get the thread identifier for the specified thread.
@@ -284,9 +284,9 @@ extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
  *
  * \since This function is available since SDL 3.0.0.
  *
- * \sa SDL_ThreadID
+ * \sa SDL_GetCurrentThreadID
  */
-extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
+extern DECLSPEC SDL_ThreadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
 
 /**
  * Set the priority for the current thread.
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index 5eae508b3ea1..23acd00d7d05 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -93,7 +93,7 @@ static void ManagementThreadMainloop(void)
 int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_on_result)
 {
     // We want to block for a result, but we are already running from the management thread! Just run the task now so we don't deadlock.
-    if ((wait_on_result) && (SDL_ThreadID() == SDL_GetThreadID(ManagementThread))) {
+    if ((wait_on_result) && (SDL_GetCurrentThreadID() == SDL_GetThreadID(ManagementThread))) {
         *wait_on_result = task(userdata);
         return 0;  // completed!
     }
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index be517c11b4c4..a2ee7d22de92 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -613,7 +613,7 @@ SDL3_0.0.0 {
     SDL_SurfaceHasRLE;
     SDL_TextInputActive;
     SDL_TextInputShown;
-    SDL_ThreadID;
+    SDL_GetCurrentThreadID;
     SDL_TryLockMutex;
     SDL_TryLockRWLockForReading;
     SDL_TryLockRWLockForWriting;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index ca74790f485c..c1ff1b86642b 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -636,7 +636,7 @@
 #define SDL_SurfaceHasRLE SDL_SurfaceHasRLE_REAL
 #define SDL_TextInputActive SDL_TextInputActive_REAL
 #define SDL_TextInputShown SDL_TextInputShown_REAL
-#define SDL_ThreadID SDL_ThreadID_REAL
+#define SDL_GetCurrentThreadID SDL_GetCurrentThreadID_REAL
 #define SDL_TryLockMutex SDL_TryLockMutex_REAL
 #define SDL_TryLockRWLockForReading SDL_TryLockRWLockForReading_REAL
 #define SDL_TryLockRWLockForWriting SDL_TryLockRWLockForWriting_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 55421f113310..9030305e8827 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -403,7 +403,7 @@ SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),retu
 SDL_DYNAPI_PROC(int,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(int,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return)
-SDL_DYNAPI_PROC(SDL_threadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
+SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return)
 SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return)
 SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return)
@@ -678,7 +678,7 @@ 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(SDL_bool,SDL_TextInputActive,(void),(),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_TextInputShown,(void),(),return)
-SDL_DYNAPI_PROC(SDL_threadID,SDL_ThreadID,(void),(),return)
+SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetCurrentThreadID,(void),(),return)
 SDL_DYNAPI_PROC(int,SDL_TryLockMutex,(SDL_Mutex *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_TryLockRWLockForReading,(SDL_RWLock *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_TryLockRWLockForWriting,(SDL_RWLock *a),(a),return)
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index 97a60c4280ba..e215c826f3ea 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -101,7 +101,7 @@ static struct
     Uint64 m_unLastDetect;
 
 #if defined(__WIN32__) || defined(__WINGDK__)
-    SDL_threadID m_nThreadID;
+    SDL_ThreadID m_nThreadID;
     WNDCLASSEXA m_wndClass;
     HWND m_hwndMsg;
     HDEVNOTIFY m_hNotify;
@@ -230,7 +230,7 @@ static void HIDAPI_InitializeDiscovery(void)
     SDL_HIDAPI_discovery.m_unLastDetect = 0;
 
 #if defined(__WIN32__) || defined(__WINGDK__)
-    SDL_HIDAPI_discovery.m_nThreadID = SDL_ThreadID();
+    SDL_HIDAPI_discovery.m_nThreadID = SDL_GetCurrentThreadID();
 
     SDL_zero(SDL_HIDAPI_discovery.m_wndClass);
     SDL_HIDAPI_discovery.m_wndClass.hInstance = GetModuleHandle(NULL);
@@ -380,7 +380,7 @@ static void HIDAPI_UpdateDiscovery(void)
 #if defined(__WIN32__) || defined(__WINGDK__)
 #if 0 /* just let the usual SDL_PumpEvents loop dispatch these, fixing bug 4286. --ryan. */
     /* We'll only get messages on the same thread that created the window */
-    if (SDL_ThreadID() == SDL_HIDAPI_discovery.m_nThreadID) {
+    if (SDL_GetCurrentThreadID() == SDL_HIDAPI_discovery.m_nThreadID) {
         MSG msg;
         while (PeekMessage(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0, PM_NOREMOVE)) {
             if (GetMessageA(&msg, SDL_HIDAPI_discovery.m_hwndMsg, 0, 0) != 0) {
diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c
index 9b28f6b8e34b..6468387e884b 100644
--- a/src/thread/SDL_thread.c
+++ b/src/thread/SDL_thread.c
@@ -105,7 +105,7 @@ void SDL_CleanupTLS(void)
 
 typedef struct SDL_TLSEntry
 {
-    SDL_threadID thread;
+    SDL_ThreadID thread;
     SDL_TLSData *storage;
     struct SDL_TLSEntry *next;
 } SDL_TLSEntry;
@@ -115,7 +115,7 @@ static SDL_TLSEntry *SDL_generic_TLS;
 
 SDL_TLSData *SDL_Generic_GetTLSData(void)
 {
-    SDL_threadID thread = SDL_ThreadID();
+    SDL_ThreadID thread = SDL_GetCurrentThreadID();
     SDL_TLSEntry *entry;
     SDL_TLSData *storage = NULL;
 
@@ -153,7 +153,7 @@ SDL_TLSData *SDL_Generic_GetTLSData(void)
 
 int SDL_Generic_SetTLSData(SDL_TLSData *data)
 {
-    SDL_threadID thread = SDL_ThreadID();
+    SDL_ThreadID thread = SDL_GetCurrentThreadID();
     SDL_TLSEntry *prev, *entry;
 
     /* SDL_Generic_GetTLSData() is always called first, so we can assume SDL_generic_TLS_mutex */
@@ -287,7 +287,7 @@ void SDL_RunThread(SDL_Thread *thread)
     SDL_SYS_SetupThread(thread->name);
 
     /* Get the thread id */
-    thread->threadid = SDL_ThreadID();
+    thread->threadid = SDL_GetCurrentThreadID();
 
     /* Run the function */
     *statusloc = userfunc(userdata);
@@ -409,14 +409,14 @@ SDL_Thread *SDL_CreateThreadInternal(int(SDLCALL *fn)(void *), const char *name,
 #endif
 }
 
-SDL_threadID SDL_GetThreadID(SDL_Thread *thread)
+SDL_ThreadID SDL_GetThreadID(SDL_Thread *thread)
 {
-    SDL_threadID id;
+    SDL_ThreadID id;
 
     if (thread) {
         id = thread->threadid;
     } else {
-        id = SDL_ThreadID();
+        id = SDL_GetCurrentThreadID();
     }
     return id;
 }
diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h
index 7d4e245aee09..6f88a9572db5 100644
--- a/src/thread/SDL_thread_c.h
+++ b/src/thread/SDL_thread_c.h
@@ -59,7 +59,7 @@ typedef enum SDL_ThreadState
 /* This is the system-independent thread info structure */
 struct SDL_Thread
 {
-    SDL_threadID threadid;
+    SDL_ThreadID threadid;
     SYS_ThreadHandle handle;
     int status;
     SDL_AtomicInt state; /* SDL_THREAD_STATE_* */
diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c
index a56427038ad0..b4d3068e6774 100644
--- a/src/thread/generic/SDL_sysmutex.c
+++ b/src/thread/generic/SDL_sysmutex.c
@@ -27,7 +27,7 @@
 struct SDL_Mutex
 {
     int recursive;
-    SDL_threadID owner;
+    SDL_ThreadID owner;
     SDL_Semaphore *sem;
 };
 
@@ -65,7 +65,7 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS  // clang doe
 {
 #ifndef SDL_THREADS_DISABLED
     if (mutex != NULL) {
-        SDL_threadID this_thread = SDL_ThreadID();
+        SDL_ThreadID this_thread = SDL_GetCurrentThreadID();
         if (mutex->owner == this_thread) {
             ++mutex->recursive;
         } else {
@@ -86,7 +86,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
     int retval = 0;
 #ifndef SDL_THREADS_DISABLED
     if (mutex) {
-        SDL_threadID this_thread = SDL_ThreadID();
+        SDL_ThreadID this_thread = SDL_GetCurrentThreadID();
         if (mutex->owner == this_thread) {
             ++mutex->recursive;
         } else {
@@ -110,7 +110,7 @@ void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS  // clang d
 #ifndef SDL_THREADS_DISABLED
     if (mutex != NULL) {
         // If we don't own the mutex, we can't unlock it
-        if (SDL_ThreadID() != mutex->owner) {
+        if (SDL_GetCurrentThreadID() != mutex->owner) {
             SDL_assert(!"Tried to unlock a mutex we don't own!");
             return; // (undefined behavior!) SDL_SetError("mutex not owned by this thread");
         }
diff --git a/src/thread/generic/SDL_sysrwlock.c b/src/thread/generic/SDL_sysrwlock.c
index f41c28d7b332..29efccdfbd39 100644
--- a/src/thread/generic/SDL_sysrwlock.c
+++ b/src/thread/generic/SDL_sysrwlock.c
@@ -48,7 +48,7 @@ struct SDL_RWLock
 #else
     SDL_Mutex *lock;
     SDL_Condition *condition;
-    SDL_threadID writer_thread;
+    SDL_ThreadID writer_thread;
     SDL_AtomicInt reader_count;
     SDL_AtomicInt writer_count;
 #endif
diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c
index 3e455850ba5c..5a2a3a71b0ca 100644
--- a/src/thread/generic/SDL_systhread.c
+++ b/src/thread/generic/SDL_systhread.c
@@ -40,7 +40,7 @@ void SDL_SYS_SetupThread(const char *name)
     return;
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
     return 0;
 }
diff --git a/src/thread/n3ds/SDL_systhread.c b/src/thread/n3ds/SDL_systhread.c
index d99fca5a2f7f..5a279e0eaa9d 100644
--- a/src/thread/n3ds/SDL_systhread.c
+++ b/src/thread/n3ds/SDL_systhread.c
@@ -87,11 +87,11 @@ void SDL_SYS_SetupThread(const char *name)
     return;
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
     u32 thread_ID = 0;
     svcGetThreadId(&thread_ID, CUR_THREAD_HANDLE);
-    return (SDL_threadID)thread_ID;
+    return (SDL_ThreadID)thread_ID;
 }
 
 int SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority)
diff --git a/src/thread/ngage/SDL_systhread.cpp b/src/thread/ngage/SDL_systhread.cpp
index e57ff6f29bfd..ded1ce35ad37 100644
--- a/src/thread/ngage/SDL_systhread.cpp
+++ b/src/thread/ngage/SDL_systhread.cpp
@@ -78,7 +78,7 @@ void SDL_SYS_SetupThread(const char *name)
     return;
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
     RThread current;
     TThreadId id = current.Id();
diff --git a/src/thread/ps2/SDL_systhread.c b/src/thread/ps2/SDL_systhread.c
index c6e4f6819971..2c3a57e5211c 100644
--- a/src/thread/ps2/SDL_systhread.c
+++ b/src/thread/ps2/SDL_systhread.c
@@ -98,9 +98,9 @@ void SDL_SYS_SetupThread(const char *name)
     /* Do nothing. */
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
-    return (SDL_threadID)GetThreadId();
+    return (SDL_ThreadID)GetThreadId();
 }
 
 void SDL_SYS_WaitThread(SDL_Thread *thread)
diff --git a/src/thread/psp/SDL_systhread.c b/src/thread/psp/SDL_systhread.c
index a6f6bf72be68..558a3282dd37 100644
--- a/src/thread/psp/SDL_systhread.c
+++ b/src/thread/psp/SDL_systhread.c
@@ -65,9 +65,9 @@ void SDL_SYS_SetupThread(const char *name)
     /* Do nothing. */
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
-    return (SDL_threadID)sceKernelGetThreadId();
+    return (SDL_ThreadID)sceKernelGetThreadId();
 }
 
 void SDL_SYS_WaitThread(SDL_Thread *thread)
diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c
index 4a8b84b97063..0ed72f23b4e4 100644
--- a/src/thread/pthread/SDL_systhread.c
+++ b/src/thread/pthread/SDL_systhread.c
@@ -168,9 +168,9 @@ void SDL_SYS_SetupThread(const char *name)
 #endif
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
-    return (SDL_threadID)pthread_self();
+    return (SDL_ThreadID)pthread_self();
 }
 
 int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
diff --git a/src/thread/stdcpp/SDL_sysrwlock.cpp b/src/thread/stdcpp/SDL_sysrwlock.cpp
index 9bb7c1d79f9a..8737ded329bf 100644
--- a/src/thread/stdcpp/SDL_sysrwlock.cpp
+++ b/src/thread/stdcpp/SDL_sysrwlock.cpp
@@ -27,7 +27,7 @@
 struct SDL_RWLock
 {
     std::shared_mutex cpp_mutex;
-    SDL_threadID write_owner;
+    SDL_ThreadID write_owner;
 };
 
 extern "C" SDL_RWLock *SDL_CreateRWLock(void)
@@ -68,7 +68,7 @@ extern "C" void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFET
     if (rwlock) {
         try {
             rwlock->cpp_mutex.lock();
-            rwlock->write_owner = SDL_ThreadID();
+            rwlock->write_owner = SDL_GetCurrentThreadID();
         } catch (std::system_error &ex) {
             SDL_assert(!"Error trying to lock rwlock for writing");  // assume we're in a lot of trouble if this assert fails.
             //return SDL_SetError("unable to lock a C++ rwlock: code=%d; %s", ex.code(), ex.what());
@@ -94,7 +94,7 @@ extern "C" int SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock)
         if (rwlock->cpp_mutex.try_lock() == false) {
             retval = SDL_RWLOCK_TIMEDOUT;
         } else {
-            rwlock->write_owner = SDL_ThreadID();
+            rwlock->write_owner = SDL_GetCurrentThreadID();
         }
     }
     return retval;
@@ -103,7 +103,7 @@ extern "C" int SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock)
 extern "C" void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS  // clang doesn't know about NULL mutexes
 {
     if (rwlock) {
-        if (rwlock->write_owner == SDL_ThreadID()) {
+        if (rwlock->write_owner == SDL_GetCurrentThreadID()) {
             rwlock->write_owner = 0;
             rwlock->cpp_mutex.unlock();
         } else {
diff --git a/src/thread/stdcpp/SDL_systhread.cpp b/src/thread/stdcpp/SDL_systhread.cpp
index 29004ad2636c..0dd8152b840b 100644
--- a/src/thread/stdcpp/SDL_systhread.cpp
+++ b/src/thread/stdcpp/SDL_systhread.cpp
@@ -59,19 +59,19 @@ extern "C" void
 SDL_SYS_SetupThread(const char *name)
 {
     // Make sure a thread ID gets assigned ASAP, for debugging purposes:
-    SDL_ThreadID();
+    SDL_GetCurrentThreadID();
     return;
 }
 
-extern "C" SDL_threadID
-SDL_ThreadID(void)
+extern "C" SDL_ThreadID
+SDL_GetCurrentThreadID(void)
 {
 #ifdef __WINRT__
     return GetCurrentThreadId();
 #else
     // HACK: Mimic a thread ID, if one isn't otherwise available.
-    static thread_local SDL_threadID current_thread_id = 0;
-    static SDL_threadID next_thread_id = 1;
+    static thread_local SDL_ThreadID current_thread_id = 0;
+    static SDL_ThreadID next_thread_id = 1;
     static std::mutex next_thread_id_mutex;
 
     if (current_thread_id == 0) {
diff --git a/src/thread/vita/SDL_systhread.c b/src/thread/vita/SDL_systhread.c
index fd6dad9df0ff..545083fe04f6 100644
--- a/src/thread/vita/SDL_systhread.c
+++ b/src/thread/vita/SDL_systhread.c
@@ -92,9 +92,9 @@ void SDL_SYS_SetupThread(const char *name)
     /* Do nothing. */
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
-    return (SDL_threadID)sceKernelGetThreadId();
+    return (SDL_ThreadID)sceKernelGetThreadId();
 }
 
 void SDL_SYS_WaitThread(SDL_Thread *thread)
diff --git a/src/thread/windows/SDL_sysrwlock_srw.c b/src/thread/windows/SDL_sysrwlock_srw.c
index a02cfff281c9..a972f455fe07 100644
--- a/src/thread/windows/SDL_sysrwlock_srw.c
+++ b/src/thread/windows/SDL_sysrwlock_srw.c
@@ -82,7 +82,7 @@ static SDL_rwlock_impl_t SDL_rwlock_impl_active = { 0 };
 typedef struct SDL_rwlock_srw
 {
     SRWLOCK srw;
-    SDL_threadID write_owner;
+    SDL_ThreadID write_owner;
 } SDL_rwlock_srw;
 
 static SDL_RWLock *SDL_CreateRWLock_srw(void)
@@ -116,7 +116,7 @@ static void SDL_LockRWLockForWriting_srw(SDL_RWLock *_rwlock) SDL_NO_THREAD_SAFE
     SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock;
     if (rwlock != NULL) {
         pAcquireSRWLockExclusive(&rwlock->srw);
-        rwlock->write_owner = SDL_ThreadID();
+        rwlock->write_owner = SDL_GetCurrentThreadID();
     }
 }
 
@@ -144,7 +144,7 @@ static void SDL_UnlockRWLock_srw(SDL_RWLock *_rwlock) SDL_NO_THREAD_SAFETY_ANALY
 {
     SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock;
     if (rwlock != NULL) {
-        if (rwlock->write_owner == SDL_ThreadID()) {
+        if (rwlock->write_owner == SDL_GetCurrentThreadID()) {
             rwlock->write_owner = 0;
             pReleaseSRWLockExclusive(&rwlock->srw);
         } else {
diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c
index 693700beab61..7d4a2364976c 100644
--- a/src/thread/windows/SDL_systhread.c
+++ b/src/thread/windows/SDL_systhread.c
@@ -162,9 +162,9 @@ void SDL_SYS_SetupThread(const char *name)
     }
 }
 
-SDL_threadID SDL_ThreadID(void)
+SDL_ThreadID SDL_GetCurrentThreadID(void)
 {
-    return (SDL_threadID)GetCurrentThreadId();
+    return (SDL_ThreadID)GetCurrentThreadId();
 }
 
 int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 0273f1ad8b6a..8e5e766900d5 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -334,7 +334,7 @@ struct SDL_VideoDevice
 
     /* * * */
     /* Data common to all drivers */
-    SDL_threadID thread;
+    SDL_ThreadID thread;
     SDL_bool checked_texture_framebuffer;
     SDL_bool is_dummy;
     SDL_bool suspend_screensaver;
diff --git a/src/video/SDL_sysvideocapture.h b/src/video/SDL_sysvideocapture.h
index e7ba6e96b056..9db178e60099 100644
--- a/src/video/SDL_sysvideocapture.h
+++ b/src/video/SDL_sysvideocapture.h
@@ -51,7 +51,7 @@ struct SDL_VideoCaptureDevice
 
     /* A thread to feed the video_capture device */
     SDL_Thread *thread;
-    SDL_threadID threadid;
+    SDL_ThreadID threadid;
 
     /* Queued buffers (if app not using callback). */
     SDL_ListNode *buffer_queue;
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 1bd3055c6522..1aa3c0d23aaf 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -532,7 +532,7 @@ int SDL_VideoInit(const char *driver_name)
     pre_driver_error. */
     _this = video;
     _this->name = bootstrap[i]->name;
-    _this->thread = SDL_ThreadID();
+    _this->thread = SDL_GetCurrentThreadID();
 
     /* Set some very sane GL defaults */
     _this->gl_config.driver_loaded = 0;
@@ -618,7 +618,7 @@ SDL_VideoDevice *SDL_GetVideoDevice(void)
 
 SDL_bool SDL_OnVideoThread(void)
 {
-    return (_this && SDL_ThreadID() == _this->thread);
+    return (_this && SDL_GetCurrentThreadID() == _this->thread);
 }
 
 SDL_bool SDL_IsVideoContextExternal(void)
diff --git a/src/video/SDL_video_capture.c b/src/video/SDL_video_capture.c
index 01fbb49d5a29..1d05b4423e9e 100644
--- a/src/video/SDL_video_capture.c
+++ b/src/video/SDL_video_capture.c
@@ -396,7 +396,7 @@ SDL_CaptureVideoThread(void *devicep)
 #endif
 
     /* Perform any thread setup */
-    device->threadid = SDL_ThreadID();
+    device->threadid = SDL_GetCurrentThreadID();
 
     /* Init state */
     while (!SDL_AtomicGet(&device->enabled)) {
diff --git a/test/testerror.c b/test/testerror.c
index 6792d7d44420..3171403756bb 100644
--- a/test/testerror.c
+++ b/test/testerror.c
@@ -35,8 +35,8 @@ static int SDLCALL
 ThreadFunc(void *data)
 {
     /* Set the child thread error string */
-    SDL_SetError("Thread %s (%lu) had a problem: %s",
-                 (char *)data, SDL_ThreadID(), "nevermind");
+    SDL_SetError("Thread %s (%" SDL_PRIu64 ") had a problem: %s",
+                 (char *)data, SDL_GetCurrentThreadID(), "nevermind");
     while (alive) {
         SDL_Log("Thread '%s' is alive!\n", (char *)data);
         SDL_Delay(1 * 1000);
diff --git a/test/testlock.c b/test/testlock.c
index 2437bd277676..4a496b2be0bf 100644
--- a/test/testlock.c
+++ b/test/testlock.c
@@ -22,7 +22,7 @@
 #include <SDL3/SDL_test.h>
 
 static SDL_Mutex *mutex = NULL;
-static SDL_threadID mainthread;
+static SDL_ThreadID mainthread;
 static SDL_AtomicInt doterminate;
 static int nb_threads = 6;
 static SDL_Thread **threads;
@@ -42,7 +42,7 @@ SDL_Quit_Wrapper(void)
 
 static void printid(void)
 {
-    SDL_Log("Thread %lu:  exiting\n", SDL_ThreadID());
+    SDL_Log("Thread %" SDL_PRIu64 ":  exiting\n", SDL_GetCurrentThreadID());
 }
 
 static void terminate(int sig)
@@ -53,9 +53,9 @@ static void terminate(int sig)
 
 static void closemutex(int sig)
 {
-    SDL_threadID id = SDL_ThreadID();
+    SDL_ThreadID id = SDL_GetCurrentThreadID();
     int i;
-    SDL_Log("Thread %lu:  Cleaning up...\n", id == mainthread ? 0 : id);
+    SDL_Log("Thread %" SDL_PRIu64 ":  Cleaning up...\n", id == mainthread ? 0 : id);
     SDL_AtomicSet(&doterminate, 1);
     if (threads) {
         for (i = 0; i < nb_threads; ++i) {
@@ -74,26 +74,28 @@ static void closemutex(int sig)
 static int SDLCALL
 Run(void *data)
 {
-    if (SDL_ThreadID() == mainthread) {
+    SDL_ThreadID current_thread = SDL_GetCurrentThreadID();
+
+    if (current_thread == mainthread) {
         (void)signal(SIGTERM, closemutex);
     }
-    SDL_Log("Thread %lu: starting up", SDL_ThreadID());
+    SDL_Log("Thread %" SDL_PRIu64 ": starting up", current_thread);
     while (!SDL_AtomicGet(&doterminate)) {
-        SDL_Log("Thread %lu: ready to work\n", SDL_ThreadID());
+        SDL_Log("Thread %" SDL_PRIu64 ": ready to work\n", current_thread);
         SDL_LockMutex(mutex);
-        SDL_Log("Thread %lu: start work!\n", SDL_ThreadID());
+        SDL_Log("Thread %" SDL_PRIu64 ": start work!\n", current_thread);
         SDL_Delay(1 * worktime);
-        SDL_Log("Thread %lu: work done!\n", SDL_ThreadID());
+        SDL_Log("Thread %" SDL_PRIu64 ": work done!\n", current_thread);
         SDL_UnlockMutex(mutex);
 
         /* If this sleep isn't done, then threads may starve */
         SDL_Delay(10);
     }
-    if (SDL_ThreadID() == mainthread && SDL_AtomicGet(&doterminate)) {
-        SDL_Log("Thread %lu: raising SIGTERM\n", SDL_ThreadID());
+    if (current_thread == mainthread && SDL_AtomicGet(&doterminate)) {
+        SDL_Log("Thread %" SDL_PRIu64 ": raising SIGTERM\n", current_thread);
         (void)raise(SIGTERM);
     }
-    SDL_Log("Thread %lu: exiting!\n", SDL_ThreadID());
+    SDL_Log("Thread %" SDL_PRIu64 ": exiting!\n", current_thread);
     return 0;
 }
 
@@ -187,8 +189,8 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
-    mainthread = SDL_ThreadID();
-    SDL_Log("Main thread: %lu\n", mainthread);
+    mainthread = SDL_GetCurrentThreadID();
+    SDL_Log("Main thread: %" SDL_PRIu64 "\n", mainthread);
     (void)atexit(printid);
     for (i = 0; i < nb_threads; ++i) {
         char name[64];
diff --git a/test/testrwlock.c b/test/testrwlock.c
index c3c8ebb09088..51e49338b3ae 100644
--- a/test/testrwlock.c
+++ b/test/testrwlock.c
@@ -19,7 +19,7 @@
 #include <SDL3/SDL_test.h>
 
 static SDL_RWLock *rwlock = NULL;
-static SDL_threadID mainthread;
+static SDL_ThreadID mainthread;
 static SDL_AtomicInt doterminate;
 static int nb_threads = 6;
 static SDL_Thread **threads;
@@ -30,20 +30,20 @@ static SDLTest_CommonState *state;
 
 static void DoWork(const int workticks)  /* "Work" */
 {
-    const SDL_threadID tid = SDL_ThreadID();
+    const SDL_ThreadID tid = SDL_GetCurrentThreadID();
     const SDL_bool is_reader = tid != mainthread;
     const char *typestr = is_reader ? "Reader" : "Writer";
 
-    SDL_Log("%s Thread %lu: ready to work\n", typestr, (unsigned long) tid);
+    SDL_Log("%s Thread %" SDL_PRIu64 ": ready to work\n", typestr, tid);
     if (is_reader) {
         SDL_LockRWLockForReading(rwlock);
     } else {
         SDL_LockRWLockForWriting(rwlock);
     }
 
-    SDL_Log("%s Thread %lu: start work!\n", typestr, (unsigned long) tid);
+    SDL_Log("%s Thread %" SDL_PRIu64 ": start work!\n", typestr, tid);
     SDL_Delay(workticks);
-    SDL_Log("%s Thread %lu: work done!\n", typestr, (unsigned long) tid);
+    SDL_Log("%s Thread %" SDL_PRIu64 ": work done!\n", typestr, tid);
     SDL_UnlockRWLock(rwlock);
 
     /* If this sleep isn't done, then threads may starve */
@@ -53,11 +53,11 @@ static void DoWork(const int workticks)  /* "Work" */
 static int SDLCALL
 ReaderRun(void *data)
 {
-    SDL_Log("Reader Thread %lu: starting up", SDL_ThreadID());
+    SDL_Log("Reader Thread %" SDL_PRIu64 ": starting up", SDL_GetCurrentThreadID());
     while (!SDL_AtomicGet(&doterminate)) {
         DoWork(worktime);
     }
-    SDL_Log("Reader Thread %lu: exiting!\n", SDL_ThreadID());
+    SDL_Log("Reader Thread %" SDL_PRIu64 ": exiting!\n", SDL_GetCurrentThreadID());
     return 0;
 }
 
@@ -148,8 +148,8 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    mainthread = SDL_ThreadID();
-    SDL_Log("Writer thread: %lu\n", mainthread);
+    mainthread = SDL_GetCurrentThreadID();
+    SDL_Log("Writer thread: %" SDL_PRIu64 "\n", mainthread);
     for (i = 0; i < nb_threads; ++i) {
         char name[64];
         (void)SDL_snprintf(name, sizeof(name), "Reader%d", i);
diff --git a/test/testthread.c b/test/testthread.c
index be1a6779de62..274516e5020b 100644
--- a/test/testthread.c
+++ b/test/testthread.c
@@ -59,8 +59,8 @@ ThreadFunc(void *data)
     SDL_ThreadPriority prio = SDL_THREAD_PRIORITY_NORMAL;
 
     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_GetTLS(tls));
+    SDL_Log("Started thread %s: My thread id is %" SDL_PRIu64 ", thread data = %s\n",
+            (char *)data, SDL_GetCurrentThreadID(), (const char *)SDL_GetTLS(tls));
     while (alive) {
         SDL_Log("Thread '%s' is alive!\n", (char *)data);