File tree 1 file changed +7
-10
lines changed 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 21
21
#include < signal.h>
22
22
#include < unistd.h>
23
23
#elif defined (_WIN32)
24
+ #define WIN32_LEAN_AND_MEAN
25
+ #define NOMINMAX
26
+ #include < windows.h>
24
27
#include < signal.h>
25
28
#endif
26
29
@@ -261,7 +264,10 @@ int main(int argc, char ** argv) {
261
264
sigint_action.sa_flags = 0 ;
262
265
sigaction (SIGINT, &sigint_action, NULL );
263
266
#elif defined (_WIN32)
264
- signal (SIGINT, sigint_handler);
267
+ auto console_ctrl_handler = [](DWORD ctrl_type) -> BOOL {
268
+ return (ctrl_type == CTRL_C_EVENT) ? (sigint_handler (SIGINT), true ) : false ;
269
+ };
270
+ SetConsoleCtrlHandler (static_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
265
271
#endif
266
272
267
273
fprintf (stderr, " %s: interactive mode on.\n " , __func__);
@@ -539,11 +545,6 @@ int main(int argc, char ** argv) {
539
545
// potentially set color to indicate we are taking user input
540
546
set_console_color (con_st, CONSOLE_COLOR_USER_INPUT);
541
547
542
- #if defined (_WIN32)
543
- // Windows: must reactivate sigint handler after each signal
544
- signal (SIGINT, sigint_handler);
545
- #endif
546
-
547
548
if (params.instruct ) {
548
549
printf (" \n > " );
549
550
}
@@ -627,10 +628,6 @@ int main(int argc, char ** argv) {
627
628
}
628
629
}
629
630
630
- #if defined (_WIN32)
631
- signal (SIGINT, SIG_DFL);
632
- #endif
633
-
634
631
llama_print_timings (ctx);
635
632
llama_free (ctx);
636
633
You can’t perform that action at this time.
0 commit comments