From: Yaron Keren Date: Wed, 22 Jul 2015 19:01:14 +0000 (+0000) Subject: De-duplicate Unix & Windows CallBacksToRun X-Git-Tag: android-x86-7.1-r4~45570 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1d5c214e8467074ffb2bcbffde2af49698265c00;p=android-x86%2Fexternal-llvm.git De-duplicate Unix & Windows CallBacksToRun Move CallBacksToRun into the common Signals.cpp, create RunCallBacksToRun() and use these in both Unix/Signals.inc and Windows/Signals.inc. Lots of potential code to be merged here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242925 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp index a11789372d9..598ef50175a 100644 --- a/lib/Support/Signals.cpp +++ b/lib/Support/Signals.cpp @@ -12,8 +12,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Signals.h" #include "llvm/Config/config.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Signals.h" + +#include namespace llvm { using namespace sys; @@ -23,6 +26,15 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// +static ManagedStatic>> + CallBacksToRun; +void RunCallBacksToRun() { + if (!CallBacksToRun.isConstructed()) + return; + for (auto &I : *CallBacksToRun) + I.first(I.second); + CallBacksToRun->clear(); +} } // Include the platform-specific parts of this class. diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 68e10435c7f..caccf7b377c 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -17,7 +17,6 @@ #include "llvm/Support/Format.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Program.h" @@ -25,7 +24,6 @@ #include "llvm/Support/raw_ostream.h" #include #include -#include #if HAVE_EXECINFO_H # include // For backtrace(). #endif @@ -58,8 +56,6 @@ static ManagedStatic > SignalsMutex; static void (*InterruptFunction)() = nullptr; static ManagedStatic> FilesToRemove; -static ManagedStatic>> - CallBacksToRun; // IntSigs - Signals that represent requested termination. There's no bug // or failure, or if there is, it's not our direct responsibility. For whatever @@ -205,11 +201,7 @@ static RETSIGTYPE SignalHandler(int Sig) { } // Otherwise if it is a fault (like SEGV) run any handler. - if (CallBacksToRun.isConstructed()) { - auto &CallBacksToRunRef = *CallBacksToRun; - for (unsigned i = 0, e = CallBacksToRun->size(); i != e; ++i) - CallBacksToRunRef[i].first(CallBacksToRunRef[i].second); - } + RunCallBacksToRun(); #ifdef __s390__ // On S/390, certain signals are delivered with PSW Address pointing to diff --git a/lib/Support/Windows/Signals.inc b/lib/Support/Windows/Signals.inc index 5c8c23978ac..c8bc646fd2c 100644 --- a/lib/Support/Windows/Signals.inc +++ b/lib/Support/Windows/Signals.inc @@ -14,7 +14,6 @@ #include #include #include -#include #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" @@ -164,6 +163,8 @@ static bool load64BitDebugHelp(void) { return fStackWalk64 && fSymInitialize && fSymSetOptions; } +using namespace llvm; + // Forward declare. static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep); static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); @@ -172,7 +173,6 @@ static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); static void (*InterruptFunction)() = 0; static std::vector *FilesToRemove = NULL; -static std::vector > *CallBacksToRun = 0; static bool RegisteredUnhandledExceptionFilter = false; static bool CleanupExecuted = false; static PTOP_LEVEL_EXCEPTION_FILTER OldFilter = NULL; @@ -436,8 +436,6 @@ void llvm::sys::SetInterruptFunction(void (*IF)()) { /// to the process. The handler can have a cookie passed to it to identify /// what instance of the handler it is. void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { - if (CallBacksToRun == 0) - CallBacksToRun = new std::vector >(); CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie)); RegisterHandler(); LeaveCriticalSection(&CriticalSection); @@ -454,17 +452,12 @@ static void Cleanup() { CleanupExecuted = true; // FIXME: open files cannot be deleted. - if (FilesToRemove != NULL) while (!FilesToRemove->empty()) { llvm::sys::fs::remove(FilesToRemove->back()); FilesToRemove->pop_back(); } - - if (CallBacksToRun) - for (auto &I : *CallBacksToRun) - I.first(I.second); - + RunCallBacksToRun(); LeaveCriticalSection(&CriticalSection); }