From 6ae8c73acad76fdf9660ca88b5c07722eaf0a8e8 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 17 Aug 2009 17:07:22 +0000 Subject: [PATCH] Add locking around signal handler registration. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79254 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Unix/Signals.inc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/System/Unix/Signals.inc b/lib/System/Unix/Signals.inc index e385e0c5566..d39e1e99a0c 100644 --- a/lib/System/Unix/Signals.inc +++ b/lib/System/Unix/Signals.inc @@ -14,6 +14,7 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/System/Mutex.h" #include #include #if HAVE_EXECINFO_H @@ -33,6 +34,8 @@ using namespace llvm; static RETSIGTYPE SignalHandler(int Sig); // defined below. +static SmartMutex 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(); FilesToRemove->push_back(Filename); + SignalsMutex.release(); + RegisterHandlers(); return false; } -- 2.34.1