forked from Green-Sky/tomato
Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'
This commit is contained in:
29
external/sdl/SDL/test/testrwlock.c
vendored
29
external/sdl/SDL/test/testrwlock.c
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@ -33,22 +33,21 @@ static void DoWork(const int workticks) /* "Work" */
|
||||
const SDL_threadID tid = SDL_ThreadID();
|
||||
const SDL_bool is_reader = tid != mainthread;
|
||||
const char *typestr = is_reader ? "Reader" : "Writer";
|
||||
int rc;
|
||||
|
||||
SDL_Log("%s Thread %lu: ready to work\n", typestr, (unsigned long) tid);
|
||||
rc = is_reader ? SDL_LockRWLockForReading(rwlock) : SDL_LockRWLockForWriting(rwlock);
|
||||
if (rc < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s Thread %lu: Couldn't lock rwlock: %s", typestr, (unsigned long) tid, SDL_GetError());
|
||||
if (is_reader) {
|
||||
SDL_LockRWLockForReading(rwlock);
|
||||
} else {
|
||||
SDL_Log("%s Thread %lu: start work!\n", typestr, (unsigned long) tid);
|
||||
SDL_Delay(workticks);
|
||||
SDL_Log("%s Thread %lu: work done!\n", typestr, (unsigned long) tid);
|
||||
if (SDL_UnlockRWLock(rwlock) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s Thread %lu: Couldn't unlock rwlock: %s", typestr, (unsigned long) tid, SDL_GetError());
|
||||
}
|
||||
/* If this sleep isn't done, then threads may starve */
|
||||
SDL_Delay(10);
|
||||
SDL_LockRWLockForWriting(rwlock);
|
||||
}
|
||||
|
||||
SDL_Log("%s Thread %lu: start work!\n", typestr, (unsigned long) tid);
|
||||
SDL_Delay(workticks);
|
||||
SDL_Log("%s Thread %lu: work done!\n", typestr, (unsigned long) tid);
|
||||
SDL_UnlockRWLock(rwlock);
|
||||
|
||||
/* If this sleep isn't done, then threads may starve */
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
@ -68,7 +67,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (state == NULL) {
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -142,7 +141,7 @@ int main(int argc, char *argv[])
|
||||
SDL_AtomicSet(&doterminate, 0);
|
||||
|
||||
rwlock = SDL_CreateRWLock();
|
||||
if (rwlock == NULL) {
|
||||
if (!rwlock) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create rwlock: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
|
Reference in New Issue
Block a user