diff options
| author | Owen Anderson <resistor@mac.com> | 2009-08-17 17:07:22 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2009-08-17 17:07:22 +0000 |
| commit | 820739dccc9c7b7d118c45d605c5e989f622c387 (patch) | |
| tree | b8c8e34b6647953c0acb0af87126e8753a22acb7 /llvm/lib/System | |
| parent | bd3c03371331f17afdb24c7c0bfbf123b97b8056 (diff) | |
| download | bcm5719-llvm-820739dccc9c7b7d118c45d605c5e989f622c387.tar.gz bcm5719-llvm-820739dccc9c7b7d118c45d605c5e989f622c387.zip | |
Add locking around signal handler registration.
llvm-svn: 79254
Diffstat (limited to 'llvm/lib/System')
| -rw-r--r-- | llvm/lib/System/Unix/Signals.inc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/System/Unix/Signals.inc b/llvm/lib/System/Unix/Signals.inc index e385e0c5566..d39e1e99a0c 100644 --- a/llvm/lib/System/Unix/Signals.inc +++ b/llvm/lib/System/Unix/Signals.inc @@ -14,6 +14,7 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/System/Mutex.h" #include <vector> #include <algorithm> #if HAVE_EXECINFO_H @@ -33,6 +34,8 @@ using namespace llvm; static RETSIGTYPE SignalHandler(int Sig); // defined below. +static SmartMutex<true> SignalsMutex; + /// InterruptFunction - The function to call if ctrl-c is pressed. static void (*InterruptFunction)() = 0; @@ -113,6 +116,7 @@ static RETSIGTYPE SignalHandler(int Sig) { sigfillset(&SigMask); sigprocmask(SIG_UNBLOCK, &SigMask, 0); + SignalsMutex.acquire(); if (FilesToRemove != 0) while (!FilesToRemove->empty()) { FilesToRemove->back().eraseFromDisk(true); @@ -122,14 +126,19 @@ static RETSIGTYPE SignalHandler(int Sig) { if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) { if (InterruptFunction) { void (*IF)() = InterruptFunction; + SignalsMutex.release(); InterruptFunction = 0; IF(); // run the interrupt function. return; } + + SignalsMutex.release(); raise(Sig); // Execute the default handler. return; } + SignalsMutex.release(); + // Otherwise if it is a fault (like SEGV) run any handler. if (CallBacksToRun) for (unsigned i = 0, e = CallBacksToRun->size(); i != e; ++i) @@ -139,18 +148,23 @@ static RETSIGTYPE SignalHandler(int Sig) { void llvm::sys::SetInterruptFunction(void (*IF)()) { + SignalsMutex.acquire(); InterruptFunction = IF; + SignalsMutex.release(); RegisterHandlers(); } // RemoveFileOnSignal - The public API bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { + SignalsMutex.acquire(); if (FilesToRemove == 0) FilesToRemove = new std::vector<sys::Path>(); FilesToRemove->push_back(Filename); + SignalsMutex.release(); + RegisterHandlers(); return false; } |

