forked from Green-Sky/tomato
sdl (master post 3.1 preview) Merge commit 'e4f454091a943345938608570b104400f62fd625'
This commit is contained in:
18
external/sdl/SDL/test/testrwlock.c
vendored
18
external/sdl/SDL/test/testrwlock.c
vendored
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user