mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-05 01:16:26 +00:00
Added support for clang thread-safety analysis
The annotations have been added to SDL_mutex.h and have been made public so applications can enable this for their own code. Clang assumes that locking and unlocking can't fail, but SDL has the concept of a NULL mutex, so the mutex functions have been changed not to report errors if a mutex hasn't been initialized. We do have mutexes that might be accessed when they are NULL, notably in the event system, so this is an important change. This commit cleans up a bunch of rare race conditions in the joystick and game controller code so now everything should be completely protected by the joystick lock. To test this, change the compiler to "clang -Wthread-safety -Werror=thread-safety -DSDL_THREAD_SAFETY_ANALYSIS"
This commit is contained in:
@@ -481,6 +481,8 @@ int SDL_SYS_HapticMouse(void)
|
||||
int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -497,6 +499,8 @@ int SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
|
||||
int SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
{
|
||||
#ifdef SDL_JOYSTICK_LINUX
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return 0;
|
||||
}
|
||||
@@ -520,6 +524,8 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
|
||||
int ret;
|
||||
SDL_hapticlist_item *item;
|
||||
|
||||
SDL_AssertJoysticksLocked();
|
||||
|
||||
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user