From 91da15aa75f7e45bcac4ffeaef1b1c53f1f8149e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 21 Aug 2014 18:44:45 +0200 Subject: [PATCH] windows: intercept Ctrl+C to use nvprof --- cpu-miner.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cpu-miner.c b/cpu-miner.c index 8295d1a..38ae4d6 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -19,12 +19,13 @@ #include #include #include +#include #ifdef WIN32 #include #include +BOOL WINAPI ConsoleHandler(DWORD); #else #include -#include #include #if HAVE_SYS_SYSCTL_H #include @@ -1516,6 +1517,25 @@ static void signal_handler(int sig) break; } } +#else +BOOL WINAPI ConsoleHandler(DWORD dwType) +{ + switch (dwType) { + case CTRL_C_EVENT: + applog(LOG_INFO, "CTRL_C_EVENT received, exiting"); + cuda_devicereset(); + exit(0); + break; + case CTRL_BREAK_EVENT: + applog(LOG_INFO, "CTRL_BREAK_EVENT received, exiting"); + cuda_devicereset(); + exit(0); + break; + default: + return false; + } + return true; +} #endif #define PROGRAM_VERSION "1.3" @@ -1591,6 +1611,8 @@ int main(int argc, char *argv[]) } /* Always catch Ctrl+C */ signal(SIGINT, signal_handler); +#else + SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE); #endif if (num_processors == 0)