/// being killed, and the interrupt function automatically disabled. Note
/// that interrupt functions are not allowed to call any non-reentrant
/// functions. An null interrupt function pointer disables the current
/// being killed, and the interrupt function automatically disabled. Note
/// that interrupt functions are not allowed to call any non-reentrant
/// functions. An null interrupt function pointer disables the current
- /// installed function.
+ /// installed function. Note also that the handler may be executed on a
+ /// different thread on some platforms.
/// @brief Register a function to be called when ctrl-c is pressed.
void SetInterruptFunction(void (*IF)());
} // End sys namespace
/// @brief Register a function to be called when ctrl-c is pressed.
void SetInterruptFunction(void (*IF)());
} // End sys namespace
static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep);
static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType);
static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep);
static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType);
+// InterruptFunction - The function to call if ctrl-c is pressed.
+static void (*InterruptFunction)() = 0;
+
static std::vector<llvm::sys::Path> *FilesToRemove = NULL;
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
static bool RegisteredUnhandledExceptionFilter = false;
static std::vector<llvm::sys::Path> *FilesToRemove = NULL;
static std::vector<llvm::sys::Path> *DirectoriesToRemove = NULL;
static bool RegisteredUnhandledExceptionFilter = false;
void sys::SetInterruptFunction(void (*IF)()) {
void sys::SetInterruptFunction(void (*IF)()) {
- // Currently unimplemented.
+ InterruptFunction = IF;
+ RegisterHandler();
+ LeaveCriticalSection(&CriticalSection);
}
static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) {
}
static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) {
+ EnterCriticalSection(&CriticalSection);
+ // If an interrupt function has been set, go and run one it; otherwise,
+ // the process dies.
+ void (*IF)() = InterruptFunction;
+ InterruptFunction = 0; // Don't run it on another CTRL-C.
+
+ if (IF) {
+ try {
+ IF(); // Run it now.
+ } catch (...) {
+ // Kill the process on an exception.
+ LeaveCriticalSection(&CriticalSection);
+ return FALSE;
+ }
+ LeaveCriticalSection(&CriticalSection);
+ return TRUE; // Don't kill the process.
+ }
+
// Allow normal processing to take place; i.e., the process dies.
// Allow normal processing to take place; i.e., the process dies.
+ LeaveCriticalSection(&CriticalSection);