summaryrefslogtreecommitdiff
path: root/lib/System
diff options
context:
space:
mode:
authorJeff Cohen <jeffc@jolt-lang.org>2005-08-02 03:04:47 +0000
committerJeff Cohen <jeffc@jolt-lang.org>2005-08-02 03:04:47 +0000
commitee841a1a8735805f84d609ae105bec92525033c6 (patch)
treeeed9ac550077e4c88f72eba8cc868898990c0dbb /lib/System
parent7e608bbb5dfe4f827e64e91b0bb68a1d95d737ae (diff)
downloadllvm-ee841a1a8735805f84d609ae105bec92525033c6.tar.gz
llvm-ee841a1a8735805f84d609ae105bec92525033c6.tar.bz2
llvm-ee841a1a8735805f84d609ae105bec92525033c6.tar.xz
Implement SetInterruptFunction for Windows.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22582 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/Win32/Signals.inc26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc
index a2c7ae2c30..cf5cb40d4d 100644
--- a/lib/System/Win32/Signals.inc
+++ b/lib/System/Win32/Signals.inc
@@ -29,6 +29,9 @@
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;
@@ -111,7 +114,9 @@ void sys::PrintStackTraceOnErrorSignal() {
void sys::SetInterruptFunction(void (*IF)()) {
- // Currently unimplemented.
+ InterruptFunction = IF;
+ RegisterHandler();
+ LeaveCriticalSection(&CriticalSection);
}
}
@@ -234,9 +239,28 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
}
static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) {
+ EnterCriticalSection(&CriticalSection);
Cleanup();
+ // 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.
+ LeaveCriticalSection(&CriticalSection);
return FALSE;
}