Skip to content

Commit

Permalink
Removed public joystick locking API
Browse files Browse the repository at this point in the history
All joystick functions are thread-safe and you can now get an atomic list of joysticks with SDL_GetJoysticks()

Fixes libsdl-org#6956
  • Loading branch information
slouken committed Dec 31, 2022
1 parent 324c0b7 commit dd9e950
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
4 changes: 3 additions & 1 deletion docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
21 changes: 0 additions & 21 deletions include/SDL3/SDL_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ SDL3_0.0.0 {
SDL_LoadWAV_RW;
SDL_LockAudio;
SDL_LockAudioDevice;
SDL_LockJoysticks;
SDL_LockMutex;
SDL_LockSurface;
SDL_LockTexture;
Expand Down Expand Up @@ -677,7 +676,6 @@ SDL3_0.0.0 {
SDL_UnloadObject;
SDL_UnlockAudio;
SDL_UnlockAudioDevice;
SDL_UnlockJoysticks;
SDL_UnlockMutex;
SDL_UnlockSurface;
SDL_UnlockTexture;
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),)
Expand Down
10 changes: 10 additions & 0 deletions src/joystick/SDL_joystick_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit dd9e950

Please sign in to comment.