From 30579c8cd7b1b83f1d5fc91a20d7333b123c5238 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 8 Oct 2022 09:32:09 -0700
Subject: [PATCH] Don't try to create a semaphore for the mutex implementation
if threads are disabled
Fixes https://github.com/libsdl-org/SDL/issues/6344
(cherry picked from commit 17b43b0fdd38733889edd8124b96285b1eae0e74)
---
src/thread/generic/SDL_sysmutex.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c
index 42965aa8bfdc..12cc580411d5 100644
--- a/src/thread/generic/SDL_sysmutex.c
+++ b/src/thread/generic/SDL_sysmutex.c
@@ -40,7 +40,9 @@ SDL_CreateMutex(void)
SDL_mutex *mutex;
/* Allocate mutex memory */
- mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
+
+#if !SDL_THREADS_DISABLED
if (mutex) {
/* Create the mutex semaphore, with initial value 1 */
mutex->sem = SDL_CreateSemaphore(1);
@@ -53,6 +55,8 @@ SDL_CreateMutex(void)
} else {
SDL_OutOfMemory();
}
+#endif /* !SDL_THREADS_DISABLED */
+
return mutex;
}