WinRT: prevented a potential race condition in the XInput backend

The race condition could've been triggered on device removal.
main
David Ludwig 2013-12-25 14:42:38 -05:00
parent 8db33416a2
commit ca867fc92d
1 changed files with 4 additions and 2 deletions

View File

@ -106,25 +106,27 @@ DeviceDetectionThreadMain(void * _data)
*/ */
/* See if any new devices are connected. */ /* See if any new devices are connected. */
SDL_LockMutex(g_DeviceInfoLock);
for (i = 0; i < XUSER_MAX_COUNT; ++i) { for (i = 0; i < XUSER_MAX_COUNT; ++i) {
if (!g_XInputData[i].isDeviceConnected && if (!g_XInputData[i].isDeviceConnected &&
!g_XInputData[i].isDeviceConnectionEventPending && !g_XInputData[i].isDeviceConnectionEventPending &&
!g_XInputData[i].isDeviceRemovalEventPending) !g_XInputData[i].isDeviceRemovalEventPending)
{ {
SDL_UnlockMutex(g_DeviceInfoLock);
result = XInputGetCapabilities(i, 0, &tempXInputCaps); result = XInputGetCapabilities(i, 0, &tempXInputCaps);
SDL_LockMutex(g_DeviceInfoLock);
if (result == ERROR_SUCCESS) { if (result == ERROR_SUCCESS) {
/* Yes, a device is connected. Mark it as such. /* Yes, a device is connected. Mark it as such.
Others will be told about this (via an Others will be told about this (via an
SDL_JOYDEVICEADDED event) in the next call to SDL_JOYDEVICEADDED event) in the next call to
SDL_SYS_JoystickDetect. SDL_SYS_JoystickDetect.
*/ */
SDL_LockMutex(g_DeviceInfoLock);
g_XInputData[i].isDeviceConnected = SDL_TRUE; g_XInputData[i].isDeviceConnected = SDL_TRUE;
g_XInputData[i].isDeviceConnectionEventPending = SDL_TRUE; g_XInputData[i].isDeviceConnectionEventPending = SDL_TRUE;
SDL_UnlockMutex(g_DeviceInfoLock);
} }
} }
} }
SDL_UnlockMutex(g_DeviceInfoLock);
} }
return 0; return 0;