summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/CrashRecoveryContext.cpp
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2016-04-05 20:19:49 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2016-04-05 20:19:49 +0000
commit1760dc2a232bde2175606ba737938d3032f1e49d (patch)
tree3859bc6b8b21c8d5073ded16260d7a5b3ff99b8f /llvm/lib/Support/CrashRecoveryContext.cpp
parentf2fdd013a29b26791490e3a33beda1bacfeec182 (diff)
downloadbcm5719-llvm-1760dc2a232bde2175606ba737938d3032f1e49d.tar.gz
bcm5719-llvm-1760dc2a232bde2175606ba737938d3032f1e49d.zip
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
Diffstat (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp')
-rw-r--r--llvm/lib/Support/CrashRecoveryContext.cpp55
1 files changed, 35 insertions, 20 deletions
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 <setjmp.h>
+#include "llvm/Support/Threading.h"
+#include <cassert>
+#include <csetjmp>
+
using namespace llvm;
namespace {
struct CrashRecoveryContextImpl;
-static ManagedStatic<
+ManagedStatic<
sys::ThreadLocal<const CrashRecoveryContextImpl> > 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<sys::Mutex> gCrashRecoveryContextMutex;
+bool gCrashRecoveryEnabled = false;
-static ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex;
-static bool gCrashRecoveryEnabled = false;
-
-static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>>
+ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>>
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<const void> sCurrentExceptionHandle;
+sys::ThreadLocal<const void> 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 <signal.h>
+#include <csignal>
-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<CrashRecoveryContextImpl*>(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<void()> Fn;
CrashRecoveryContext *CRC;
bool UseBackgroundPriority;
bool Result;
};
-}
-static void RunSafelyOnThread_Dispatch(void *UserData) {
+void RunSafelyOnThread_Dispatch(void *UserData) {
RunSafelyOnThreadInfo *Info =
reinterpret_cast<RunSafelyOnThreadInfo*>(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<void()> Fn,
unsigned RequestedStackSize) {
bool UseBackgroundPriority = hasThreadBackgroundPriority();
OpenPOWER on IntegriCloud