From 1760dc2a232bde2175606ba737938d3032f1e49d Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Tue, 5 Apr 2016 20:19:49 +0000 Subject: Fix Clang-tidy modernize-deprecated-headers warnings in remaining files; other minor fixes. Some Include What You Use suggestions were used too. Use anonymous namespaces in source files. Differential revision: http://reviews.llvm.org/D18778 llvm-svn: 265454 --- llvm/lib/Support/CrashRecoveryContext.cpp | 55 ++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp') diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 98865f5e065..1c5e8d93934 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -8,19 +8,23 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Config/config.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/ThreadLocal.h" -#include +#include "llvm/Support/Threading.h" +#include +#include + using namespace llvm; namespace { struct CrashRecoveryContextImpl; -static ManagedStatic< +ManagedStatic< sys::ThreadLocal > CurrentContext; struct CrashRecoveryContextImpl { @@ -42,6 +46,7 @@ public: Next = CurrentContext->get(); CurrentContext->set(this); } + ~CrashRecoveryContextImpl() { if (!SwitchedThread) CurrentContext->set(Next); @@ -70,14 +75,14 @@ public: } }; -} +ManagedStatic gCrashRecoveryContextMutex; +bool gCrashRecoveryEnabled = false; -static ManagedStatic gCrashRecoveryContextMutex; -static bool gCrashRecoveryEnabled = false; - -static ManagedStatic> +ManagedStatic> tlIsRecoveringFromCrash; +} // end anonymous namespace + CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} CrashRecoveryContext::~CrashRecoveryContext() { @@ -162,7 +167,9 @@ CrashRecoveryContext::unregisterCleanup(CrashRecoveryContextCleanup *cleanup) { // SetUnhandledExceptionFilter API, but there's a risk of that // being entirely overwritten (it's not a chain). -static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) +namespace { + +LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -190,7 +197,9 @@ static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) // CrashRecoveryContext at all. So we make use of a thread-local // exception table. The handles contained in here will either be // non-NULL, valid VEH handles, or NULL. -static sys::ThreadLocal sCurrentExceptionHandle; +sys::ThreadLocal sCurrentExceptionHandle; + +} // end anonymous namespace void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -239,14 +248,15 @@ void CrashRecoveryContext::Disable() { // reliable fashion -- if we get a signal outside of a crash recovery context we // simply disable crash recovery and raise the signal again. -#include +#include -static const int Signals[] = - { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; -static const unsigned NumSignals = array_lengthof(Signals); -static struct sigaction PrevActions[NumSignals]; +namespace { -static void CrashRecoverySignalHandler(int Signal) { +const int Signals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; +const unsigned NumSignals = array_lengthof(Signals); +struct sigaction PrevActions[NumSignals]; + +void CrashRecoverySignalHandler(int Signal) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -278,6 +288,8 @@ static void CrashRecoverySignalHandler(int Signal) { const_cast(CRCI)->HandleCrash(); } +} // end anonymous namespace + void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -334,14 +346,16 @@ void CrashRecoveryContext::HandleCrash() { CRCI->HandleCrash(); } +namespace { + // FIXME: Portability. -static void setThreadBackgroundPriority() { +void setThreadBackgroundPriority() { #ifdef __APPLE__ setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG); #endif } -static bool hasThreadBackgroundPriority() { +bool hasThreadBackgroundPriority() { #ifdef __APPLE__ return getpriority(PRIO_DARWIN_THREAD, 0) == 1; #else @@ -349,16 +363,14 @@ static bool hasThreadBackgroundPriority() { #endif } -namespace { struct RunSafelyOnThreadInfo { function_ref Fn; CrashRecoveryContext *CRC; bool UseBackgroundPriority; bool Result; }; -} -static void RunSafelyOnThread_Dispatch(void *UserData) { +void RunSafelyOnThread_Dispatch(void *UserData) { RunSafelyOnThreadInfo *Info = reinterpret_cast(UserData); @@ -367,6 +379,9 @@ static void RunSafelyOnThread_Dispatch(void *UserData) { Info->Result = Info->CRC->RunSafely(Info->Fn); } + +} // end anonymous namespace + bool CrashRecoveryContext::RunSafelyOnThread(function_ref Fn, unsigned RequestedStackSize) { bool UseBackgroundPriority = hasThreadBackgroundPriority(); -- cgit v1.2.3