Don't try to create a semaphore for the mutex implementation if threads are disabled

Fixes https://github.com/libsdl-org/SDL/issues/6344
This commit is contained in:
Sam Lantinga 2022-10-08 09:32:09 -07:00
parent 33050fea39
commit 17b43b0fdd
1 changed files with 5 additions and 1 deletions

View File

@ -40,7 +40,9 @@ SDL_CreateMutex(void)
SDL_mutex *mutex; SDL_mutex *mutex;
/* Allocate mutex memory */ /* Allocate mutex memory */
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
#if !SDL_THREADS_DISABLED
if (mutex) { if (mutex) {
/* Create the mutex semaphore, with initial value 1 */ /* Create the mutex semaphore, with initial value 1 */
mutex->sem = SDL_CreateSemaphore(1); mutex->sem = SDL_CreateSemaphore(1);
@ -53,6 +55,8 @@ SDL_CreateMutex(void)
} else { } else {
SDL_OutOfMemory(); SDL_OutOfMemory();
} }
#endif /* !SDL_THREADS_DISABLED */
return mutex; return mutex;
} }