mirror of
https://github.com/yawut/SDL.git
synced 2026-09-09 09:36:14 -05:00
wiiu/thread: Add missing NULL checks to mutex code
According to the changes in d59caffe2c:
> [...] 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.
This commit is contained in:
committed by
Dave Murphy
parent
cd53049e56
commit
7b058bd042
@@ -34,22 +34,30 @@ 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;
|
||||
}
|
||||
@@ -57,12 +65,20 @@ SDL_LockMutex(SDL_mutex * mutex)
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user