I didn't look at the threading issue, but there is at least one part of that patch that looks wrong to me:
In joydev_enum_deviceW():
- if (id != 0)
return FALSE;
- if (id >= have_joydevs) {
- return -1;
- }
I think that should return FALSE rather than -1 (TRUE).