Skip to content

Commit

Permalink
wiiu/thread: Add missing NULL checks to mutex code
Browse files Browse the repository at this point in the history
According to  the changes in d59caff:
> [...] SDL has the concept of a NULL mutex, so the mutex functions have been changed not to report errors if a mutex hasn't been initialized.
> We do have mutexes that might be accessed when they are NULL, notably in the event system, so this is an important change.
  • Loading branch information
GaryOderNichts committed Nov 8, 2023
1 parent 0b420eb commit aaac091
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/thread/wiiu/SDL_sysmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,51 @@ SDL_CreateMutex(void)

/* Allocate the structure */
mutex = (OSMutex *) SDL_calloc(1, sizeof(OSMutex));
OSInitMutex(mutex);
if (mutex != NULL) {
OSInitMutex(mutex);
} else {
SDL_OutOfMemory();
}
return (SDL_mutex *)mutex;
}

void
SDL_DestroyMutex(SDL_mutex * mutex)
{
if (mutex) {
if (mutex != NULL) {
SDL_free(mutex);
}
}

/* Lock the mutex */
int
SDL_LockMutex(SDL_mutex * mutex)
SDL_LockMutex(SDL_mutex * mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn't know about NULL mutexes */
{
if (mutex == NULL) {
return 0;
}

OSLockMutex((OSMutex *)mutex);
return 0;
}

int
SDL_TryLockMutex(SDL_mutex * mutex)
{
if (mutex == NULL) {
return 0;
}

return OSTryLockMutex((OSMutex *)mutex) ? 0 : SDL_MUTEX_TIMEDOUT;
}

int
SDL_UnlockMutex(SDL_mutex * mutex)
SDL_UnlockMutex(SDL_mutex * mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn't know about NULL mutexes */
{
if (mutex == NULL) {
return 0;
}

OSUnlockMutex((OSMutex *)mutex);
return 0;
}
Expand Down

0 comments on commit aaac091

Please sign in to comment.