diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2022-06-29 16:31:35 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2022-08-03 14:35:30 +0200 |
commit | d4cab870940692bfda2433de83d1a4d0349bc9aa (patch) | |
tree | 9c5034e30a6572f82994b70d3626a9ab213fd1c8 /llvm/lib/Support/CrashRecoveryContext.cpp | |
parent | 05b3aadfff13fda6c586d9dd811f69c1f38260f5 (diff) | |
download | llvm-d4cab870940692bfda2433de83d1a4d0349bc9aa.zip llvm-d4cab870940692bfda2433de83d1a4d0349bc9aa.tar.gz llvm-d4cab870940692bfda2433de83d1a4d0349bc9aa.tar.bz2 |
ManagedStatic: remove from CrashRecoveryContext
Differential Revision: https://reviews.llvm.org/D129126
Diffstat (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp')
-rw-r--r-- | llvm/lib/Support/CrashRecoveryContext.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 292ba63..ae58418 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -10,7 +10,6 @@ #include "llvm/Config/llvm-config.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ExitCodes.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/ThreadLocal.h" #include "llvm/Support/thread.h" @@ -23,8 +22,10 @@ namespace { struct CrashRecoveryContextImpl; -static ManagedStatic< - sys::ThreadLocal<const CrashRecoveryContextImpl> > CurrentContext; +sys::ThreadLocal<const CrashRecoveryContextImpl> &getCurrentContext() { + static sys::ThreadLocal<const CrashRecoveryContextImpl> CurrentContext; + return CurrentContext; +} struct CrashRecoveryContextImpl { // When threads are disabled, this links up all active @@ -42,12 +43,12 @@ struct CrashRecoveryContextImpl { public: CrashRecoveryContextImpl(CrashRecoveryContext *CRC) noexcept : CRC(CRC), Failed(false), SwitchedThread(false), ValidJumpBuffer(false) { - Next = CurrentContext->get(); - CurrentContext->set(this); + Next = getCurrentContext().get(); + getCurrentContext().set(this); } ~CrashRecoveryContextImpl() { if (!SwitchedThread) - CurrentContext->set(Next); + getCurrentContext().set(Next); } /// Called when the separate crash-recovery thread was finished, to @@ -65,7 +66,7 @@ public: void HandleCrash(int RetCode, uintptr_t Context) { // Eliminate the current context entry, to avoid re-entering in case the // cleanup code crashes. - CurrentContext->set(Next); + getCurrentContext().set(Next); assert(!Failed && "Crash recovery context already failed!"); Failed = true; @@ -83,13 +84,20 @@ public: // this occurs when using SEH on Windows with MSVC or clang-cl. } }; -} // namespace -static ManagedStatic<std::mutex> gCrashRecoveryContextMutex; +std::mutex &getCrashRecoveryContextMutex() { + static std::mutex CrashRecoveryContextMutex; + return CrashRecoveryContextMutex; +} + static bool gCrashRecoveryEnabled = false; -static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> - tlIsRecoveringFromCrash; +sys::ThreadLocal<const CrashRecoveryContext> &getIsRecoveringFromCrash() { + static sys::ThreadLocal<const CrashRecoveryContext> IsRecoveringFromCrash; + return IsRecoveringFromCrash; +} + +} // namespace static void installExceptionOrSignalHandlers(); static void uninstallExceptionOrSignalHandlers(); @@ -106,8 +114,8 @@ CrashRecoveryContext::CrashRecoveryContext() { CrashRecoveryContext::~CrashRecoveryContext() { // Reclaim registered resources. CrashRecoveryContextCleanup *i = head; - const CrashRecoveryContext *PC = tlIsRecoveringFromCrash->get(); - tlIsRecoveringFromCrash->set(this); + const CrashRecoveryContext *PC = getIsRecoveringFromCrash().get(); + getIsRecoveringFromCrash().set(this); while (i) { CrashRecoveryContextCleanup *tmp = i; i = tmp->next; @@ -115,21 +123,21 @@ CrashRecoveryContext::~CrashRecoveryContext() { tmp->recoverResources(); delete tmp; } - tlIsRecoveringFromCrash->set(PC); + getIsRecoveringFromCrash().set(PC); CrashRecoveryContextImpl *CRCI = (CrashRecoveryContextImpl *) Impl; delete CRCI; } bool CrashRecoveryContext::isRecoveringFromCrash() { - return tlIsRecoveringFromCrash->get() != nullptr; + return getIsRecoveringFromCrash().get() != nullptr; } CrashRecoveryContext *CrashRecoveryContext::GetCurrent() { if (!gCrashRecoveryEnabled) return nullptr; - const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); + const CrashRecoveryContextImpl *CRCI = getCurrentContext().get(); if (!CRCI) return nullptr; @@ -137,7 +145,7 @@ CrashRecoveryContext *CrashRecoveryContext::GetCurrent() { } void CrashRecoveryContext::Enable() { - std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex); + std::lock_guard<std::mutex> L(getCrashRecoveryContextMutex()); // FIXME: Shouldn't this be a refcount or something? if (gCrashRecoveryEnabled) return; @@ -146,7 +154,7 @@ void CrashRecoveryContext::Enable() { } void CrashRecoveryContext::Disable() { - std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex); + std::lock_guard<std::mutex> L(getCrashRecoveryContextMutex()); if (!gCrashRecoveryEnabled) return; gCrashRecoveryEnabled = false; @@ -199,7 +207,7 @@ static void uninstallExceptionOrSignalHandlers() {} // occur inside the __except evaluation block static int ExceptionFilter(_EXCEPTION_POINTERS *Except) { // Lookup the current thread local recovery object. - const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); + const CrashRecoveryContextImpl *CRCI = getCurrentContext().get(); if (!CRCI) { // Something has gone horribly wrong, so let's just tell everyone @@ -276,7 +284,7 @@ static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) } // Lookup the current thread local recovery object. - const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); + const CrashRecoveryContextImpl *CRCI = getCurrentContext().get(); if (!CRCI) { // Something has gone horribly wrong, so let's just tell everyone @@ -350,7 +358,7 @@ static struct sigaction PrevActions[NumSignals]; static void CrashRecoverySignalHandler(int Signal) { // Lookup the current thread local recovery object. - const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); + const CrashRecoveryContextImpl *CRCI = getCurrentContext().get(); if (!CRCI) { // We didn't find a crash recovery context -- this means either we got a |