From a515f51ac0001d9173dfc5bb338c536ec1eb14bc Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 31 Dec 2022 09:17:02 -0800
Subject: [PATCH] Removed public joystick locking API
All joystick functions are thread-safe and you can now get an atomic list of joysticks with SDL_GetJoysticks()
Fixes https://github.com/libsdl-org/SDL/issues/6956
---
docs/README-migration.md | 4 +++-
include/SDL3/SDL_joystick.h | 21 ---------------------
src/dynapi/SDL_dynapi.sym | 2 --
src/dynapi/SDL_dynapi_overrides.h | 2 --
src/dynapi/SDL_dynapi_procs.h | 2 --
src/joystick/SDL_joystick_c.h | 10 ++++++++++
6 files changed, 13 insertions(+), 28 deletions(-)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 8fb141428ab4..24e06265c6d4 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -346,6 +346,7 @@ The following symbols have been renamed:
* SDL_JOYSTICK_TYPE_GAMECONTROLLER => SDL_JOYSTICK_TYPE_GAMEPAD
The following functions have been removed:
+* SDL_LockJoysticks()
* SDL_JoystickEventState() - replaced with SDL_SetJoystickEventsEnabled() and SDL_JoystickEventsEnabled()
* SDL_JoystickGetDeviceGUID() - replaced with SDL_GetJoystickInstanceGUID()
* SDL_JoystickGetDeviceInstanceID()
@@ -356,7 +357,8 @@ The following functions have been removed:
* SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor()
* SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName()
* SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath()
-* SDL_NumJoysticks - replaced with SDL_GetJoysticks()
+* SDL_NumJoysticks() - replaced with SDL_GetJoysticks()
+* SDL_UnlockJoysticks()
## SDL_keycode.h
diff --git a/include/SDL3/SDL_joystick.h b/include/SDL3/SDL_joystick.h
index 5e75df8874a1..214f90255a09 100644
--- a/include/SDL3/SDL_joystick.h
+++ b/include/SDL3/SDL_joystick.h
@@ -64,9 +64,6 @@ extern "C" {
/**
* The joystick structure used to identify an SDL joystick
*/
-#ifdef SDL_THREAD_SAFETY_ANALYSIS
-extern SDL_mutex *SDL_joystick_lock;
-#endif
struct SDL_Joystick;
typedef struct SDL_Joystick SDL_Joystick;
@@ -118,24 +115,6 @@ typedef enum
/* Function prototypes */
-/**
- * Locking for atomic access to the joystick API
- *
- * The SDL joystick functions are thread-safe, however you can lock the joysticks
- * while processing to guarantee that the joystick list won't change and joystick
- * and gamepad events will not be delivered.
- *
- * \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
-
-/**
- * Unlocking for atomic access to the joystick API
- *
- * \since This function is available since SDL 3.0.0.
- */
-extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
-
/**
* Get a list of currently connected joysticks.
*
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 3c32b62b77d1..0d22987c4936 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -450,7 +450,6 @@ SDL3_0.0.0 {
SDL_LoadWAV_RW;
SDL_LockAudio;
SDL_LockAudioDevice;
- SDL_LockJoysticks;
SDL_LockMutex;
SDL_LockSurface;
SDL_LockTexture;
@@ -677,7 +676,6 @@ SDL3_0.0.0 {
SDL_UnloadObject;
SDL_UnlockAudio;
SDL_UnlockAudioDevice;
- SDL_UnlockJoysticks;
SDL_UnlockMutex;
SDL_UnlockSurface;
SDL_UnlockTexture;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 5c9f68d10439..b88702ce8082 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -476,7 +476,6 @@
#define SDL_LoadWAV_RW SDL_LoadWAV_RW_REAL
#define SDL_LockAudio SDL_LockAudio_REAL
#define SDL_LockAudioDevice SDL_LockAudioDevice_REAL
-#define SDL_LockJoysticks SDL_LockJoysticks_REAL
#define SDL_LockMutex SDL_LockMutex_REAL
#define SDL_LockSurface SDL_LockSurface_REAL
#define SDL_LockTexture SDL_LockTexture_REAL
@@ -703,7 +702,6 @@
#define SDL_UnloadObject SDL_UnloadObject_REAL
#define SDL_UnlockAudio SDL_UnlockAudio_REAL
#define SDL_UnlockAudioDevice SDL_UnlockAudioDevice_REAL
-#define SDL_UnlockJoysticks SDL_UnlockJoysticks_REAL
#define SDL_UnlockMutex SDL_UnlockMutex_REAL
#define SDL_UnlockSurface SDL_UnlockSurface_REAL
#define SDL_UnlockTexture SDL_UnlockTexture_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index fa0eba740d78..c7682df04140 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -543,7 +543,6 @@ SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_AudioSpec*,SDL_LoadWAV_RW,(SDL_RWops *a, int b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(void,SDL_LockAudio,(void),(),)
SDL_DYNAPI_PROC(void,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),)
-SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),)
SDL_DYNAPI_PROC(int,SDL_LockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_LockTexture,(SDL_Texture *a, const SDL_Rect *b, void **c, int *d),(a,b,c,d),return)
@@ -757,7 +756,6 @@ SDL_DYNAPI_PROC(int,SDL_TryLockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnloadObject,(void *a),(a),)
SDL_DYNAPI_PROC(void,SDL_UnlockAudio,(void),(),)
SDL_DYNAPI_PROC(void,SDL_UnlockAudioDevice,(SDL_AudioDeviceID a),(a),)
-SDL_DYNAPI_PROC(void,SDL_UnlockJoysticks,(void),(),)
SDL_DYNAPI_PROC(int,SDL_UnlockMutex,(SDL_mutex *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_UnlockSurface,(SDL_Surface *a),(a),)
SDL_DYNAPI_PROC(void,SDL_UnlockTexture,(SDL_Texture *a),(a),)
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index 976b1a0daff0..d01fafbd6211 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -43,6 +43,16 @@ extern SDL_bool SDL_JoysticksInitialized(void);
/* Return whether the joystick system is shutting down */
extern SDL_bool SDL_JoysticksQuitting(void);
+#ifdef SDL_THREAD_SAFETY_ANALYSIS
+extern SDL_mutex *SDL_joystick_lock;
+#endif
+
+/* Locking for atomic access to the joystick API */
+extern void SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
+
+/* Unlocking for atomic access to the joystick API */
+extern void SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
+
/* Return whether the joysticks are currently locked */
extern SDL_bool SDL_JoysticksLocked(void);