I’ve been working on an emulator, currently doing my development on Ubuntu. In my main thread, for each frame I loop over SDL_PollEvent before updating the screen.
This normally works fine, however, I’ve noticed that when adding a new joystick to the computer, seen with both Bluetooth and USB, my display locks up for around half a second.
I’ve narrowed this down to some of what happens in SDL_PollEvent:
- In SDL_UDEV_Poll, there is a call to SDL_Delay(100). This delay occurs three times when I attach my USB gamepad. (maybe instead this should just note the add-time and wait for a future call to SDL_UDEV_Poll instead of using a delay?)
- In MaybeAddDevice (both in SDL_sysjoystick.c and SDL_syshaptic.c), we open each
/dev/input/event25. This adds up to four calls to the open syscall, taking around 60ms each on my system.
I’d like to remove this temporary lock-up that my GUI has when plugging in a gamepad.
The documentation around SDL_PollEvent / SDL_PumpEvents suggests that they need to be called from the same thread that set up the video, although at least for these operations I can’t see why the joystick polling couldn’t be pushed off into another thread.
Has this type of issue come up before, and what would be the recommended solution?