Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()

Also renamed SDL_threadID to SDL_ThreadID and made it Uint64 for consistency with other ID types
main
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

@ -2909,3 +2909,12 @@ expression e1, e2, e3, e4;
- SDL_AtomicCASPtr
+ SDL_AtomicCompareAndSwapPointer
(...)
@@
@@
- SDL_ThreadID
+ SDL_GetCurrentThreadID
(...)
@@
@@
- SDL_threadID
+ SDL_ThreadID

View File

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

View File

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

View File

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

View File

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

View File

@ -613,7 +613,7 @@ SDL3_0.0.0 {
SDL_SurfaceHasRLE;
SDL_TextInputActive;
SDL_TextInputShown;
SDL_ThreadID;
SDL_GetCurrentThreadID;
SDL_TryLockMutex;
SDL_TryLockRWLockForReading;
SDL_TryLockRWLockForWriting;

View File

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

View File

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

View File

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

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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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