rawinput: Only access SDL_RAWINPUT_mutex if initialized We can also ditch the lock in RAWINPUT_JoystickQuit() now that the joystick subsystem quits drivers in reverse order. There's no chance of a racing call to RAWINPUT_WindowProc() anymore.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index 12dd1e7..d9ed3fd 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -1857,9 +1857,9 @@ RAWINPUT_WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LRESULT result = -1;
- SDL_LockMutex(SDL_RAWINPUT_mutex);
-
if (SDL_RAWINPUT_inited) {
+ SDL_LockMutex(SDL_RAWINPUT_mutex);
+
switch (msg) {
case WM_INPUT_DEVICE_CHANGE:
{
@@ -1903,9 +1903,9 @@ RAWINPUT_WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
result = 0;
break;
}
- }
- SDL_UnlockMutex(SDL_RAWINPUT_mutex);
+ SDL_UnlockMutex(SDL_RAWINPUT_mutex);
+ }
if (result >= 0) {
return result;
@@ -1920,8 +1920,6 @@ RAWINPUT_JoystickQuit(void)
return;
}
- SDL_LockMutex(SDL_RAWINPUT_mutex);
-
while (SDL_RAWINPUT_devices) {
RAWINPUT_DelDevice(SDL_RAWINPUT_devices, SDL_FALSE);
}
@@ -1932,7 +1930,6 @@ RAWINPUT_JoystickQuit(void)
SDL_RAWINPUT_inited = SDL_FALSE;
- SDL_UnlockMutex(SDL_RAWINPUT_mutex);
SDL_DestroyMutex(SDL_RAWINPUT_mutex);
SDL_RAWINPUT_mutex = NULL;
}