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:
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user