diff options
author | Dylan Noblesmith <nobled@dreamwidth.org> | 2014-08-23 23:07:14 +0000 |
---|---|---|
committer | Dylan Noblesmith <nobled@dreamwidth.org> | 2014-08-23 23:07:14 +0000 |
commit | c4c5180fb408e0eb3be50a7990aab110fcb0889c (patch) | |
tree | 5ffd003a5b9f764c1d584aac63e3108d5408b168 /llvm/lib/Support | |
parent | ffb55639e785d518bd06a4cb68cf163d820d31d6 (diff) | |
download | bcm5719-llvm-c4c5180fb408e0eb3be50a7990aab110fcb0889c.tar.gz bcm5719-llvm-c4c5180fb408e0eb3be50a7990aab110fcb0889c.zip |
Support: add llvm::unique_lock
Based on the STL class of the same name, it guards a mutex
while also allowing it to be unlocked conditionally before
destruction.
This eliminates the last naked usages of mutexes in LLVM and
clang.
It also uncovered and fixed a bug in callExternalFunction()
when compiled without USE_LIBFFI, where the mutex would never
be unlocked if the end of the function was reached.
llvm-svn: 216338
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/Unix/Signals.inc | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index 34c39c9ad92..c820553665d 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -15,6 +15,7 @@ #include "Unix.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Mutex.h" +#include "llvm/Support/UniqueLock.h" #include <algorithm> #include <string> #include <vector> @@ -162,25 +163,25 @@ static RETSIGTYPE SignalHandler(int Sig) { sigfillset(&SigMask); sigprocmask(SIG_UNBLOCK, &SigMask, nullptr); - SignalsMutex.lock(); - RemoveFilesToRemove(); - - if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) { - if (InterruptFunction) { - void (*IF)() = InterruptFunction; - SignalsMutex.unlock(); - InterruptFunction = nullptr; - IF(); // run the interrupt function. + { + unique_lock<SmartMutex<true>> Guard(SignalsMutex); + RemoveFilesToRemove(); + + if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) { + if (InterruptFunction) { + void (*IF)() = InterruptFunction; + Guard.unlock(); + InterruptFunction = nullptr; + IF(); // run the interrupt function. + return; + } + + Guard.unlock(); + raise(Sig); // Execute the default handler. return; - } - - SignalsMutex.unlock(); - raise(Sig); // Execute the default handler. - return; + } } - SignalsMutex.unlock(); - // Otherwise if it is a fault (like SEGV) run any handler. for (unsigned i = 0, e = CallBacksToRun.size(); i != e; ++i) CallBacksToRun[i].first(CallBacksToRun[i].second); |