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 22
22
#include < signal.h>
23
23
#include < unistd.h>
24
24
#elif defined (_WIN32)
25
+ #define WIN32_LEAN_AND_MEAN
26
+ #define NOMINMAX
27
+ #include < windows.h>
25
28
#include < signal.h>
26
29
#endif
27
30
@@ -240,7 +243,10 @@ int main(int argc, char ** argv) {
240
243
sigint_action.sa_flags = 0 ;
241
244
sigaction (SIGINT, &sigint_action, NULL );
242
245
#elif defined (_WIN32)
243
- signal (SIGINT, sigint_handler);
246
+ auto console_ctrl_handler = [](DWORD ctrl_type) -> BOOL {
247
+ return (ctrl_type == CTRL_C_EVENT) ? (sigint_handler (SIGINT), true ) : false ;
248
+ };
249
+ SetConsoleCtrlHandler (static_cast <PHANDLER_ROUTINE>(console_ctrl_handler), true );
244
250
#endif
245
251
246
252
fprintf (stderr, " %s: interactive mode on.\n " , __func__);
@@ -519,11 +525,6 @@ int main(int argc, char ** argv) {
519
525
// potentially set color to indicate we are taking user input
520
526
set_console_color (con_st, CONSOLE_COLOR_USER_INPUT);
521
527
522
- #if defined (_WIN32)
523
- // Windows: must reactivate sigint handler after each signal
524
- signal (SIGINT, sigint_handler);
525
- #endif
526
-
527
528
if (params.instruct ) {
528
529
printf (" \n > " );
529
530
}
@@ -607,10 +608,6 @@ int main(int argc, char ** argv) {
607
608
}
608
609
}
609
610
610
- #if defined (_WIN32)
611
- signal (SIGINT, SIG_DFL);
612
- #endif
613
-
614
611
llama_print_timings (ctx);
615
612
llama_free (ctx);
616
613
You can’t perform that action at this time.
0 commit comments