mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-28 07:29:09 +00:00
thread: Locking mutexes and rwlocks are now void functions.
Almost nothing checks these return values, and there's no reason a valid lock should fail to operate. The cases where a lock isn't valid (it's a bogus pointer, it was previously destroyed, a thread is unlocking a lock it doesn't own, etc) are undefined behavior and always were, and should be treated as an application bug. Reference Issue #8096.
This commit is contained in:
parent
082ef41566
commit
899eb0d042
21 changed files with 496 additions and 746 deletions
|
@ -80,17 +80,12 @@ Run(void *data)
|
|||
SDL_Log("Thread %lu: starting up", SDL_ThreadID());
|
||||
while (!SDL_AtomicGet(&doterminate)) {
|
||||
SDL_Log("Thread %lu: ready to work\n", SDL_ThreadID());
|
||||
if (SDL_LockMutex(mutex) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
SDL_LockMutex(mutex);
|
||||
SDL_Log("Thread %lu: start work!\n", SDL_ThreadID());
|
||||
SDL_Delay(1 * worktime);
|
||||
SDL_Log("Thread %lu: work done!\n", SDL_ThreadID());
|
||||
if (SDL_UnlockMutex(mutex) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
SDL_UnlockMutex(mutex);
|
||||
|
||||
/* If this sleep isn't done, then threads may starve */
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue