diff options
author | stijn <stijn@ignitron.net> | 2015-12-21 10:17:37 +0100 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-12-21 20:51:27 +0200 |
commit | a5aa03acaff46aaaac0d0c3462cbd968b0a1df59 (patch) | |
tree | 0252ed884d478df0576df4041b1e2989299d7f5f /windows/init.c | |
parent | 1b7f62241023fdd000ee011824679a34d615c722 (diff) |
windows: Better handling of Ctrl-C
This builds upon the changes made in 2195046365c. Using signal() does not
produce reliable results so SetConsoleCtrlHandler is used, and the handler
is installed only once during initialization instead of removing it in
mp_hal_set_interrupt_char when it is not strictly needed anymore, since
removing it might lead to Ctrl-C events being missed because they are
fired on a seperate thread which might only become alive after the handler
was removed.
Diffstat (limited to 'windows/init.c')
-rw-r--r-- | windows/init.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/windows/init.c b/windows/init.c index 5e96af046..d4533f9b4 100644 --- a/windows/init.c +++ b/windows/init.c @@ -26,9 +26,13 @@ #include <stdlib.h> #include <stdio.h> +#include <windows.h> #include "sleep.h" +extern BOOL WINAPI console_sighandler(DWORD evt); + void init() { + SetConsoleCtrlHandler(console_sighandler, TRUE); init_sleep(); #ifdef __MINGW32__ putenv("PRINTF_EXPONENT_DIGITS=2"); @@ -40,5 +44,6 @@ void init() { } void deinit() { + SetConsoleCtrlHandler(console_sighandler, FALSE); deinit_sleep(); } |