Implement sys::SetInterruptFunction on Unix, stub it on win32 so that the
authorChris Lattner <sabre@nondot.org>
Tue, 2 Aug 2005 02:14:22 +0000 (02:14 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 2 Aug 2005 02:14:22 +0000 (02:14 +0000)
build will not fail

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22578 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Unix/Signals.inc
lib/System/Win32/Signals.inc

index a9af969d5ba85785c5b35acea0bc8708a5c24167..a643dbf972c2f4412f23ca4bd37067885a4dbb6d 100644 (file)
@@ -24,6 +24,9 @@
 
 namespace {
 
+/// InterruptFunction - The function to call if ctrl-c is pressed.
+void (*InterruptFunction)() = 0;
+
 std::vector<std::string> *FilesToRemove = 0 ;
 std::vector<llvm::sys::Path> *DirectoriesToRemove = 0;
 
@@ -116,8 +119,16 @@ RETSIGTYPE SignalHandler(int Sig) {
       DirectoriesToRemove->pop_back();
     }
 
-  if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd)
-    exit(1);   // If this is an interrupt signal, exit the program
+  if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
+    if (InterruptFunction) {
+      void (*IF)() = InterruptFunction;
+      InterruptFunction = 0;
+      IF();        // run the interrupt function.
+      return;
+    } else {
+      exit(1);   // If this is an interrupt signal, exit the program
+    }
+  }
 
   // Otherwise if it is a fault (like SEGV) output the stacktrace to
   // STDERR (if we can) and reissue the signal to die...
@@ -134,6 +145,11 @@ void RegisterHandler(int Signal) {
 
 namespace llvm {
 
+void sys::SetInterruptFunction(void (*IF)()) {
+  InterruptFunction = IF;
+  RegisterHandler(SIGINT);
+}
+
 // RemoveFileOnSignal - The public API
 void sys::RemoveFileOnSignal(const sys::Path &Filename) {
   if (FilesToRemove == 0)
index 07d399a50c886f28cc901e6864370ad8dfb506e0..a2c7ae2c307a4bc8b4ff7dd5341343fad6109346 100644 (file)
@@ -109,6 +109,10 @@ void sys::PrintStackTraceOnErrorSignal() {
   LeaveCriticalSection(&CriticalSection);
 }
 
+
+void sys::SetInterruptFunction(void (*IF)()) {
+  // Currently unimplemented.
+}
 }
 
 static void Cleanup() {