[llvm-commits] [llvm] r67508 - /llvm/trunk/lib/System/Unix/Signals.inc

Chris Lattner sabre at nondot.org
Sun Mar 22 22:42:29 PDT 2009


Author: lattner
Date: Mon Mar 23 00:42:29 2009
New Revision: 67508

URL: http://llvm.org/viewvc/llvm-project?rev=67508&view=rev
Log:
factorize signal registration, part of PR3848.

Modified:
    llvm/trunk/lib/System/Unix/Signals.inc

Modified: llvm/trunk/lib/System/Unix/Signals.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Signals.inc?rev=67508&r1=67507&r2=67508&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Signals.inc (original)
+++ llvm/trunk/lib/System/Unix/Signals.inc Mon Mar 23 00:42:29 2009
@@ -31,6 +31,8 @@
 #endif
 using namespace llvm;
 
+static RETSIGTYPE SignalHandler(int Sig);  // defined below.
+
 /// InterruptFunction - The function to call if ctrl-c is pressed.
 static void (*InterruptFunction)() = 0;
 
@@ -55,18 +57,34 @@
 static const int *const KillSigsEnd =
   KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
 
+// Just call signal
+static void RegisterHandler(int Signal) {
+   signal(Signal, SignalHandler); 
+}
+
+static void RegisterHandlers() {
+  std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
+  std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
+}
+
 static void UnregisterHandler(int Signal) {
-   signal(Signal, SIG_DFL); 
+ signal(Signal, SIG_DFL); 
+}
+
+static void UnregisterHandlers() {
+  std::for_each(KillSigs, KillSigsEnd, UnregisterHandler);
+  std::for_each(IntSigs, IntSigsEnd, UnregisterHandler);
 }
 
 
+
 // SignalHandler - The signal handler that runs.
 static RETSIGTYPE SignalHandler(int Sig) {
   // Restore the signal behavior to default, so that the program actually
   // crashes when we return and the signal reissues.  This also ensures that if
   // we crash in our signal handler that the program will terminate immediately
   // instead of recursing in the signal handler.
-  std::for_each(KillSigs, KillSigsEnd, UnregisterHandler);
+  UnregisterHandlers();
 
   // Unmask all potentially blocked kill signals.
   sigset_t SigMask;
@@ -95,15 +113,11 @@
       (*CallBacksToRun)[i].first((*CallBacksToRun)[i].second);
 }
 
-// Just call signal
-static void RegisterHandler(int Signal) {
-   signal(Signal, SignalHandler); 
-}
 
 
 void llvm::sys::SetInterruptFunction(void (*IF)()) {
   InterruptFunction = IF;
-  RegisterHandler(SIGINT);
+  RegisterHandlers();
 }
 
 // RemoveFileOnSignal - The public API
@@ -114,8 +128,7 @@
 
   FilesToRemove->push_back(Filename);
 
-  std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
-  std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
+  RegisterHandlers();
   return false;
 }
 
@@ -126,7 +139,7 @@
   if (CallBacksToRun == 0)
     CallBacksToRun = new std::vector<std::pair<void(*)(void*), void*> >();
   CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie));
-  std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
+  RegisterHandlers();
 }
 
 





More information about the llvm-commits mailing list