CE-Programming / CEmu

Third-party TI-84 Plus CE / TI-83 Premium CE emulator, focused on developer features
https://ce-programming.github.io/CEmu
Other
1.05k stars 77 forks source link

Keypress emulation is not thread-safe #486

Closed calc84maniac closed 1 month ago

calc84maniac commented 1 month ago

Currently, the emu_keypad_event function is called from the GUI thread, and it unsafely modifies internal data used by the emulator thread (not the least of which is by calling interrupt functions, which could cause any interrupt to be dropped, or worse, if a race condition occurs).

My current idea of a solution for this is to have the emu_keypad_event function only update the keymap arrays (which can be turned into arrays of atomics) and add an additional state to the cpu.abort atomic (which is capable of interrupting the CPU emulation), signaling the main emulation loop to safely process updates to the keymap ASAP.