[Commits] SDL: assert: allow assertions to work on platforms without threads.

libsdl.org revision control commits-owner at libsdl.org
Fri May 19 09:54:26 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/b00c4088f687
changeset: 11015:b00c4088f687
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Fri May 19 12:54:17 2017 -0400
description:
assert: allow assertions to work on platforms without threads.

Partially fixes Bugzilla #3459.

diffstat:

 src/SDL_assert.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r 4210074a33c8 -r b00c4088f687 src/SDL_assert.c
--- a/src/SDL_assert.c	Fri May 19 12:40:55 2017 -0400
+++ b/src/SDL_assert.c	Fri May 19 12:54:17 2017 -0400
@@ -53,7 +53,10 @@
  */
 static SDL_assert_data *triggered_assertions = NULL;
 
+#ifndef SDL_THREADS_DISABLED
 static SDL_mutex *assertion_mutex = NULL;
+#endif
+
 static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
 static void *assertion_userdata = NULL;
 
@@ -265,10 +268,11 @@
 SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
                     int line)
 {
+    SDL_assert_state state = SDL_ASSERTION_IGNORE;
     static int assertion_running = 0;
+
+#ifndef SDL_THREADS_DISABLED
     static SDL_SpinLock spinlock = 0;
-    SDL_assert_state state = SDL_ASSERTION_IGNORE;
-
     SDL_AtomicLock(&spinlock);
     if (assertion_mutex == NULL) { /* never called SDL_Init()? */
         assertion_mutex = SDL_CreateMutex();
@@ -282,6 +286,7 @@
     if (SDL_LockMutex(assertion_mutex) < 0) {
         return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
     }
+#endif
 
     /* doing this because Visual C is upset over assigning in the macro. */
     if (data->trigger_count == 0) {
@@ -325,7 +330,10 @@
     }
 
     assertion_running--;
+
+#ifndef SDL_THREADS_DISABLED
     SDL_UnlockMutex(assertion_mutex);
+#endif
 
     return state;
 }
@@ -334,10 +342,12 @@
 void SDL_AssertionsQuit(void)
 {
     SDL_GenerateAssertionReport();
+#ifndef SDL_THREADS_DISABLED
     if (assertion_mutex != NULL) {
         SDL_DestroyMutex(assertion_mutex);
         assertion_mutex = NULL;
     }
+#endif
 }
 
 void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)


More information about the commits mailing list