summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-23 05:42:29 +0000
committerChris Lattner <sabre@nondot.org>2009-03-23 05:42:29 +0000
commitf299a68ee0445efcb7ac25d49cafa3d2af58c343 (patch)
treea050f0451e04477ec6a28ebee91a8a0a140563d4 /llvm/lib/System/Unix
parent772de0ae2d5364db9ea005a86aead0b50dabd83d (diff)
downloadbcm5719-llvm-f299a68ee0445efcb7ac25d49cafa3d2af58c343.tar.gz
bcm5719-llvm-f299a68ee0445efcb7ac25d49cafa3d2af58c343.zip
factorize signal registration, part of PR3848.
llvm-svn: 67508
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r--llvm/lib/System/Unix/Signals.inc33
1 files changed, 23 insertions, 10 deletions
diff --git a/llvm/lib/System/Unix/Signals.inc b/llvm/lib/System/Unix/Signals.inc
index e031e85b425..60e3a26314e 100644
--- a/llvm/lib/System/Unix/Signals.inc
+++ b/llvm/lib/System/Unix/Signals.inc
@@ -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 KillSigs[] = {
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 @@ static RETSIGTYPE SignalHandler(int Sig) {
(*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 @@ bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
FilesToRemove->push_back(Filename);
- std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
- std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
+ RegisterHandlers();
return false;
}
@@ -126,7 +139,7 @@ void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) {
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();
}
OpenPOWER on IntegriCloud