From 22b5ceb0c77c508bcdaffad958272a58ea3b5a07 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Fri, 24 Apr 2026 22:52:17 -0500
Subject: [PATCH] atomic: Fix infinite recursion in SDL_CompilerBarrier()
fallback
On some platforms, SDL_MemoryBarrierRelease() is defined to
SDL_CompilerBarrier(). If SDL_CompilerBarrier() is also defined to
the fallback spinlock acquire/release, then we will infinitely
recurse in SDL_UnlockSpinlock(). Avoid this by not unlocking the
temporary spinlock we create.
(cherry picked from commit 66e98b5598d840b3e4d767ace145b197bc0a9962)
---
include/SDL3/SDL_atomic.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/SDL3/SDL_atomic.h b/include/SDL3/SDL_atomic.h
index b6094b2550519..f1a8e0638d446 100644
--- a/include/SDL3/SDL_atomic.h
+++ b/include/SDL3/SDL_atomic.h
@@ -169,8 +169,9 @@ void _ReadWriteBarrier(void);
extern __inline void SDL_CompilerBarrier(void);
#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
#else
+/* We don't unlock here to avoid possible infinite recursion */
#define SDL_CompilerBarrier() \
-{ SDL_SpinLock _tmp = 0; SDL_LockSpinlock(&_tmp); SDL_UnlockSpinlock(&_tmp); }
+{ SDL_SpinLock _tmp = 0; SDL_LockSpinlock(&_tmp); }
#endif
/**