Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()

Also renamed SDL_threadID to SDL_ThreadID and made it Uint64 for consistency with other ID types
This commit is contained in:
Sam Lantinga
2024-01-18 04:57:12 -08:00
parent d6a41f8f31
commit fc0c774976
32 changed files with 100 additions and 83 deletions

View File

@@ -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;
}

View File

@@ -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_* */

View File

@@ -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");
}

View File

@@ -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

View File

@@ -40,7 +40,7 @@ void SDL_SYS_SetupThread(const char *name)
return;
}
SDL_threadID SDL_ThreadID(void)
SDL_ThreadID SDL_GetCurrentThreadID(void)
{
return 0;
}

View File

@@ -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)

View File

@@ -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();

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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)