Browse Source

Removed SDL_ATOMIC_DISABLED

It turns out that because we redefine SDL functions internally, it is safe to call SDL mutex functions while initializing the jump table
Sam Lantinga 1 year ago
parent
commit
31f34e9504
4 changed files with 17 additions and 31 deletions
  1. 0 2
      CMakeLists.txt
  2. 0 1
      include/build_config/SDL_build_config.h.cmake
  3. 17 21
      src/atomic/SDL_spinlock.c
  4. 0 7
      src/dynapi/SDL_dynapi.c

+ 0 - 2
CMakeLists.txt

@@ -210,7 +210,6 @@ if(EMSCRIPTEN)
 
   set(SDL_ASSEMBLY_DEFAULT OFF)
   set(SDL_SHARED_AVAILABLE OFF)
-  set(SDL_ATOMIC_DEFAULT OFF)
 endif()
 
 if(VITA OR PSP OR PS2 OR N3DS OR RISCOS)
@@ -238,7 +237,6 @@ if(SDL_SHARED_DEFAULT AND SDL_STATIC_DEFAULT AND SDL_SHARED_AVAILABLE)
 endif()
 
 set(SDL_SUBSYSTEMS
-  Atomic
   Audio
   Video
   Render

+ 0 - 1
include/build_config/SDL_build_config.h.cmake

@@ -256,7 +256,6 @@
 #cmakedefine SDL_VIDEO_CAPTURE
 
 /* Allow disabling of core subsystems */
-#cmakedefine SDL_ATOMIC_DISABLED @SDL_ATOMIC_DISABLED@
 #cmakedefine SDL_AUDIO_DISABLED @SDL_AUDIO_DISABLED@
 #cmakedefine SDL_FILE_DISABLED @SDL_FILE_DISABLED@
 #cmakedefine SDL_JOYSTICK_DISABLED @SDL_JOYSTICK_DISABLED@

+ 17 - 21
src/atomic/SDL_spinlock.c

@@ -59,25 +59,7 @@ extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
 /* This function is where all the magic happens... */
 SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
 {
-#ifdef SDL_ATOMIC_DISABLED
-    /* Terrible terrible damage */
-    static SDL_Mutex *_spinlock_mutex;
-
-    if (!_spinlock_mutex) {
-        /* Race condition on first lock... */
-        _spinlock_mutex = SDL_CreateMutex();
-    }
-    SDL_LockMutex(_spinlock_mutex);
-    if (*lock == 0) {
-        *lock = 1;
-        SDL_UnlockMutex(_spinlock_mutex);
-        return SDL_TRUE;
-    } else {
-        SDL_UnlockMutex(_spinlock_mutex);
-        return SDL_FALSE;
-    }
-
-#elif defined(HAVE_GCC_ATOMICS) || defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
+#if defined(HAVE_GCC_ATOMICS) || defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
     return __sync_lock_test_and_set(lock, 1) == 0;
 
 #elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
@@ -160,8 +142,22 @@ SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
     }
     return res;
 #else
-#error Please implement for your platform.
-    return SDL_FALSE;
+    /* Terrible terrible damage */
+    static SDL_Mutex *_spinlock_mutex;
+
+    if (!_spinlock_mutex) {
+        /* Race condition on first lock... */
+        _spinlock_mutex = SDL_CreateMutex();
+    }
+    SDL_LockMutex(_spinlock_mutex);
+    if (*lock == 0) {
+        *lock = 1;
+        SDL_UnlockMutex(_spinlock_mutex);
+        return SDL_TRUE;
+    } else {
+        SDL_UnlockMutex(_spinlock_mutex);
+        return SDL_FALSE;
+    }
 #endif
 }
 

+ 0 - 7
src/dynapi/SDL_dynapi.c

@@ -535,22 +535,15 @@ static void SDL_InitDynamicAPI(void)
      */
     static SDL_bool already_initialized = SDL_FALSE;
 
-    /* SDL_AtomicLock calls SDL mutex functions to emulate if
-       SDL_ATOMIC_DISABLED, which we can't do here, so in such a
-       configuration, you're on your own. */
-    #ifndef SDL_ATOMIC_DISABLED
     static SDL_SpinLock lock = 0;
     SDL_AtomicLock_REAL(&lock);
-    #endif
 
     if (!already_initialized) {
         SDL_InitDynamicAPILocked();
         already_initialized = SDL_TRUE;
     }
 
-    #ifndef SDL_ATOMIC_DISABLED
     SDL_AtomicUnlock_REAL(&lock);
-    #endif
 }
 
 #else /* SDL_DYNAMIC_API */