[llvm-commits] CVS: llvm/lib/System/Win32/Signals.inc
Jeff Cohen
jeffc at jolt-lang.org
Mon Aug 1 20:04:59 PDT 2005
Changes in directory llvm/lib/System/Win32:
Signals.inc updated: 1.17 -> 1.18
---
Log message:
Implement SetInterruptFunction for Windows.
---
Diffs of the changes: (+25 -1)
Signals.inc | 26 +++++++++++++++++++++++++-
1 files changed, 25 insertions(+), 1 deletion(-)
Index: llvm/lib/System/Win32/Signals.inc
diff -u llvm/lib/System/Win32/Signals.inc:1.17 llvm/lib/System/Win32/Signals.inc:1.18
--- llvm/lib/System/Win32/Signals.inc:1.17 Mon Aug 1 21:14:22 2005
+++ llvm/lib/System/Win32/Signals.inc Mon Aug 1 22:04:47 2005
@@ -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::SetInterruptFunction(void (*IF)()) {
- // Currently unimplemented.
+ InterruptFunction = IF;
+ RegisterHandler();
+ LeaveCriticalSection(&CriticalSection);
}
}
@@ -234,9 +239,28 @@
}
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;
}
More information about the llvm-commits
mailing list