From cf1d8e2dfdcb1ab4d34c82b63650f35a05d5b442 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 31 Aug 2024 07:20:37 -0700
Subject: [PATCH] Renamed SDL_AtomicSetPtr() and SDL_AtomicGetPtr()
Fixes https://github.com/libsdl-org/SDL/issues/10601
---
build-scripts/SDL_migration.cocci | 10 ++++++++++
docs/README-migration.md | 2 ++
include/SDL3/SDL_atomic.h | 12 ++++++------
include/SDL3/SDL_oldnames.h | 4 ++++
src/atomic/SDL_atomic.c | 4 ++--
src/audio/SDL_audio.c | 2 +-
src/audio/wasapi/SDL_wasapi.c | 12 ++++++------
src/dynapi/SDL_dynapi.sym | 4 ++--
src/dynapi/SDL_dynapi_overrides.h | 4 ++--
src/dynapi/SDL_dynapi_procs.h | 4 ++--
10 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 4141f6b7f13f3..31e9d8faa5f9f 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -3623,3 +3623,13 @@ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAltern
)
- == -1
)
+@@
+@@
+- SDL_AtomicSetPtr
++ SDL_AtomicSetPointer
+ (...)
+@@
+@@
+- SDL_AtomicGetPtr
++ SDL_AtomicGetPointer
+ (...)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index a820d42ac978b..430b15a2b6a65 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -88,7 +88,9 @@ The following structures have been renamed:
The following functions have been renamed:
* SDL_AtomicCAS() => SDL_AtomicCompareAndSwap()
* SDL_AtomicCASPtr() => SDL_AtomicCompareAndSwapPointer()
+* SDL_AtomicGetPtr() => SDL_AtomicGetPointer()
* SDL_AtomicLock() => SDL_LockSpinlock()
+* SDL_AtomicSetPtr() => SDL_AtomicSetPointer()
* SDL_AtomicTryLock() => SDL_TryLockSpinlock()
* SDL_AtomicUnlock() => SDL_UnlockSpinlock()
diff --git a/include/SDL3/SDL_atomic.h b/include/SDL3/SDL_atomic.h
index fbf01c4bc98ac..f159bcd27506b 100644
--- a/include/SDL3/SDL_atomic.h
+++ b/include/SDL3/SDL_atomic.h
@@ -455,8 +455,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_AtomicInt *a, int v);
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AtomicCompareAndSwap
- * \sa SDL_AtomicGetPtr
- * \sa SDL_AtomicSetPtr
+ * \sa SDL_AtomicGetPointer
+ * \sa SDL_AtomicSetPointer
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, void *oldval, void *newval);
@@ -475,9 +475,9 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AtomicCompareAndSwapPointer(void **a, v
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
- * \sa SDL_AtomicGetPtr
+ * \sa SDL_AtomicGetPointer
*/
-extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPtr(void **a, void *v);
+extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPointer(void **a, void *v);
/**
* Get the value of a pointer atomically.
@@ -493,9 +493,9 @@ extern SDL_DECLSPEC void * SDLCALL SDL_AtomicSetPtr(void **a, void *v);
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AtomicCompareAndSwapPointer
- * \sa SDL_AtomicSetPtr
+ * \sa SDL_AtomicSetPointer
*/
-extern SDL_DECLSPEC void * SDLCALL SDL_AtomicGetPtr(void **a);
+extern SDL_DECLSPEC void * SDLCALL SDL_AtomicGetPointer(void **a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index a91fb8bda5e24..558bcce9846fc 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -40,7 +40,9 @@
/* ##SDL_atomic.h */
#define SDL_AtomicCAS SDL_AtomicCompareAndSwap
#define SDL_AtomicCASPtr SDL_AtomicCompareAndSwapPointer
+#define SDL_AtomicGetPtr SDL_AtomicGetPointer
#define SDL_AtomicLock SDL_LockSpinlock
+#define SDL_AtomicSetPtr SDL_AtomicSetPointer
#define SDL_AtomicTryLock SDL_TryLockSpinlock
#define SDL_AtomicUnlock SDL_UnlockSpinlock
#define SDL_atomic_t SDL_AtomicInt
@@ -659,7 +661,9 @@
/* ##SDL_atomic.h */
#define SDL_AtomicCAS SDL_AtomicCAS_renamed_SDL_AtomicCompareAndSwap
#define SDL_AtomicCASPtr SDL_AtomicCASPtr_renamed_SDL_AtomicCompareAndSwapPointer
+#define SDL_AtomicGetPtr SDL_AtomicGetPtr_renamed_SDL_AtomicGetPointer
#define SDL_AtomicLock SDL_AtomicLock_renamed_SDL_LockSpinlock
+#define SDL_AtomicSetPtr SDL_AtomicSetPtr_renamed_SDL_AtomicSetPointer
#define SDL_AtomicTryLock SDL_AtomicTryLock_renamed_SDL_TryLockSpinlock
#define SDL_AtomicUnlock SDL_AtomicUnlock_renamed_SDL_UnlockSpinlock
#define SDL_atomic_t SDL_atomic_t_renamed_SDL_AtomicInt
diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c
index 49351a89e9c89..2816d6d4ecb58 100644
--- a/src/atomic/SDL_atomic.c
+++ b/src/atomic/SDL_atomic.c
@@ -201,7 +201,7 @@ int SDL_AtomicSet(SDL_AtomicInt *a, int v)
#endif
}
-void *SDL_AtomicSetPtr(void **a, void *v)
+void *SDL_AtomicSetPointer(void **a, void *v)
{
#ifdef HAVE_MSC_ATOMICS
return _InterlockedExchangePointer(a, v);
@@ -267,7 +267,7 @@ int SDL_AtomicGet(SDL_AtomicInt *a)
#endif
}
-void *SDL_AtomicGetPtr(void **a)
+void *SDL_AtomicGetPointer(void **a)
{
#ifdef HAVE_ATOMIC_LOAD_N
return __atomic_load_n(a, __ATOMIC_SEQ_CST);
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 86478ac178629..92bb8e5ecd578 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -390,7 +390,7 @@ static SDL_LogicalAudioDevice *ObtainLogicalAudioDevice(SDL_AudioDeviceID devid,
// to make sure the correct physical device gets locked, in case we're in a race with the default changing.
while (true) {
SDL_LockMutex(device->lock);
- SDL_AudioDevice *recheck_device = (SDL_AudioDevice *) SDL_AtomicGetPtr((void **) &logdev->physical_device);
+ SDL_AudioDevice *recheck_device = (SDL_AudioDevice *) SDL_AtomicGetPointer((void **) &logdev->physical_device);
if (device == recheck_device) {
break;
}
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index 434d077429ecd..cf3b86b0a7bf4 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -74,11 +74,11 @@ static void ManagementThreadMainloop(void)
{
SDL_LockMutex(ManagementThreadLock);
ManagementThreadPendingTask *task;
- while (((task = (ManagementThreadPendingTask *)SDL_AtomicGetPtr((void **)&ManagementThreadPendingTasks)) != NULL) || !SDL_AtomicGet(&ManagementThreadShutdown)) {
+ while (((task = (ManagementThreadPendingTask *)SDL_AtomicGetPointer((void **)&ManagementThreadPendingTasks)) != NULL) || !SDL_AtomicGet(&ManagementThreadShutdown)) {
if (!task) {
SDL_WaitCondition(ManagementThreadCondition, ManagementThreadLock); // block until there's something to do.
} else {
- SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, task->next); // take task off the pending list.
+ SDL_AtomicSetPointer((void **) &ManagementThreadPendingTasks, task->next); // take task off the pending list.
SDL_UnlockMutex(ManagementThreadLock); // let other things add to the list while we chew on this task.
task->result = task->fn(task->userdata); // run this task.
if (task->task_complete_sem) { // something waiting on result?
@@ -127,14 +127,14 @@ bool WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, b
// add to end of task list.
ManagementThreadPendingTask *prev = NULL;
- for (ManagementThreadPendingTask *i = (ManagementThreadPendingTask *)SDL_AtomicGetPtr((void **)&ManagementThreadPendingTasks); i; i = i->next) {
+ for (ManagementThreadPendingTask *i = (ManagementThreadPendingTask *)SDL_AtomicGetPointer((void **)&ManagementThreadPendingTasks); i; i = i->next) {
prev = i;
}
if (prev) {
prev->next = pending;
} else {
- SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, pending);
+ SDL_AtomicSetPointer((void **) &ManagementThreadPendingTasks, pending);
}
// task is added to the end of the pending list, let management thread rip!
@@ -210,7 +210,7 @@ static bool InitManagementThread(void)
return false;
}
- SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, NULL);
+ SDL_AtomicSetPointer((void **) &ManagementThreadPendingTasks, NULL);
SDL_AtomicSet(&ManagementThreadShutdown, 0);
ManagementThread = SDL_CreateThreadWithStackSize(ManagementThreadEntry, "SDLWASAPIMgmt", 256 * 1024, &mgmtdata); // !!! FIXME: maybe even smaller stack size?
if (!ManagementThread) {
@@ -242,7 +242,7 @@ static void DeinitManagementThread(void)
ManagementThread = NULL;
}
- SDL_assert(SDL_AtomicGetPtr((void **) &ManagementThreadPendingTasks) == NULL);
+ SDL_assert(SDL_AtomicGetPointer((void **) &ManagementThreadPendingTasks) == NULL);
SDL_DestroyCondition(ManagementThreadCondition);
SDL_DestroyMutex(ManagementThreadLock);
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index abb44c5d0114f..c25df415e3a2f 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -18,9 +18,9 @@ SDL3_0.0.0 {
SDL_AtomicCompareAndSwap;
SDL_AtomicCompareAndSwapPointer;
SDL_AtomicGet;
- SDL_AtomicGetPtr;
+ SDL_AtomicGetPointer;
SDL_AtomicSet;
- SDL_AtomicSetPtr;
+ SDL_AtomicSetPointer;
SDL_AttachVirtualJoystick;
SDL_AudioDevicePaused;
SDL_BeginGPUComputePass;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 03fb431f658a5..3ad39a267c76f 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -43,9 +43,9 @@
#define SDL_AtomicCompareAndSwap SDL_AtomicCompareAndSwap_REAL
#define SDL_AtomicCompareAndSwapPointer SDL_AtomicCompareAndSwapPointer_REAL
#define SDL_AtomicGet SDL_AtomicGet_REAL
-#define SDL_AtomicGetPtr SDL_AtomicGetPtr_REAL
+#define SDL_AtomicGetPointer SDL_AtomicGetPointer_REAL
#define SDL_AtomicSet SDL_AtomicSet_REAL
-#define SDL_AtomicSetPtr SDL_AtomicSetPtr_REAL
+#define SDL_AtomicSetPointer SDL_AtomicSetPointer_REAL
#define SDL_AttachVirtualJoystick SDL_AttachVirtualJoystick_REAL
#define SDL_AudioDevicePaused SDL_AudioDevicePaused_REAL
#define SDL_BeginGPUComputePass SDL_BeginGPUComputePass_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index bb15db652e139..768bf9cbecd04 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -63,9 +63,9 @@ SDL_DYNAPI_PROC(int,SDL_AtomicAdd,(SDL_AtomicInt *a, int b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCompareAndSwap,(SDL_AtomicInt *a, int b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCompareAndSwapPointer,(void **a, void *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_AtomicGet,(SDL_AtomicInt *a),(a),return)
-SDL_DYNAPI_PROC(void*,SDL_AtomicGetPtr,(void **a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_AtomicGetPointer,(void **a),(a),return)
SDL_DYNAPI_PROC(int,SDL_AtomicSet,(SDL_AtomicInt *a, int b),(a,b),return)
-SDL_DYNAPI_PROC(void*,SDL_AtomicSetPtr,(void **a, void *b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_AtomicSetPointer,(void **a, void *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystick,(const SDL_VirtualJoystickDesc *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_AudioDevicePaused,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(SDL_GPUComputePass*,SDL_BeginGPUComputePass,(SDL_GPUCommandBuffer *a, SDL_GPUStorageTextureWriteOnlyBinding *b, Uint32 c, SDL_GPUStorageBufferWriteOnlyBinding *d, Uint32 e),(a,b,c,d,e),return)