Re: [AD] About the Win2k bug |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
Well, it looks like I finally got it, with the help of some very patient testers (thanks again to them) ! The Win2k bug was actually double: a synchronization problem between the WinUI keyboard handler and the DirectInput one, and a timer problem partially due to the cross-platform keyboard code. About the latter: the DirectInput keyboard handler doesn't provide any support for autorepeat so it relies on the emulation code in src/keyboard.c This code uses a timer to detect autorepeat, but sort of a 'dynamic' timer: *each time* a key is struck, the timer is destroyed then re-installed. (Is there any reason for not using a 'static' timer ?) Now there are two timer drivers in the Windows port: a multi-threaded one (default) and a single-threaded one. With the MT driver: 1 timer == 1 thread (for example, the test program runs no less than 8 threads), so that *each time* a key is struck, a thread is killed and a new thread with the time critical priority is created ! Rather oddly, this mechanism flawlessly works under Win9x but not under Win2k. Therefore I made the single-threaded driver the default. While it solves the Win2k problem, I think having a single time critical thread for handling all the timers is rather clever and resource saving. This ends up limiting the number of threads in an Allegro program to 5: - primary thread (with the main() function): normal priority - window thread (general purpose messages): normal priority - mouse thread: above normal priority - keyboard thread: above normal priority - timers thread: time critical priority I don't finally know if it's worth it to merge the three input threads in a single one since, when the user doesn't interact with the program, they are idle and use 0% CPU time. The patch is attached. It fixes the Win2k bug, changes the DirectInput keyboard cooperative level to FOREGROUND, so that the application doesn't get the keystrokes any longer when it is in the background, and fixes a minor mouse pointer glitch in fullscreen mode. -- Eric Botcazou ebotcazou@xxxxxxxxxx
Attachment:
win2k_bugfix.zip
Description: Zip compressed data
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |