Rémi Bernon (@rbernon) commented about dlls/dinput/joystick_hid.c:
+static CRITICAL_SECTION joystick_crit; +static CRITICAL_SECTION_DEBUG joystick_critsect_debug = +{ + 0, 0, &joystick_crit, + { &joystick_critsect_debug.ProcessLocksList, &joystick_critsect_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": joystick_crit") } +}; +static CRITICAL_SECTION joystick_crit = { &joystick_critsect_debug, -1, 0, 0, 0, 0 }; + +/* Need to enter the CS to access this array. */ +static struct +{ + struct dinput_joystick_instance *joysticks; + unsigned int count; + SIZE_T size; +} dinput_joysticks; A struct list would be simpler than an array here IMO. Also I think the local cache as it is implemented might be prone to race conditions, when multiple processes are refreshing the device lists at the same time. The registry should be the primary source and updated from the enumerated devices, and then the local cache updated from the registry when necessary, not the other way around. But maybe we don't even need a cache and we could store the device path in the registry as well?
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10364#note_132761