Revamped joystick locking

This makes the joystick locking more robust by holding the lock while updating joysticks.

The lock should be held when calling any SDL joystick function on a different thread than the one calling SDL_PumpEvents() and SDL_JoystickUpdate().

It is now possible to hold the lock while reinitializing the joystick subsystem, however any open joysticks will become invalid and potentially cause crashes if used afterwards.

Fixes https://github.com/libsdl-org/SDL/issues/6063
This commit is contained in:
Sam Lantinga 2022-08-30 11:42:13 -07:00
parent ff233fe306
commit 40bd4feedc
5 changed files with 138 additions and 115 deletions

View file

@ -124,6 +124,11 @@ typedef enum
* the API functions that take a joystick index will be valid, and joystick
* and game controller events will not be delivered.
*
* As of SDL 2.26.0, you can take the joystick lock around reinitializing
* the joystick subsystem, to prevent other threads from seeing joysticks
* in an uninitialized state. However, all open joysticks will be closed
* and calling SDL functions using them will potentially cause a crash.
*
* \since This function is available since SDL 2.0.7.
*/
extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);