llvm.org GIT mirror llvm / a8fa798
CrashRecovery: Add CrashRecoveryContext::GetCurrent(), so clients can find the active context from anywhere. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111308 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
2 changed file(s) with 16 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
5252 /// \brief Disable crash recovery.
5353 static void Disable();
5454
55 /// \brief Return the active context, if the code is currently executing in a
56 /// thread which is in a protected context.
57 static CrashRecoveryContext *GetCurrent();
58
5559 /// \brief Execute the provide callback function (with the given arguments) in
5660 /// a protected context.
5761 ///
2222 static sys::ThreadLocal CurrentContext;
2323
2424 struct CrashRecoveryContextImpl {
25 CrashRecoveryContext *CRC;
2526 std::string Backtrace;
2627 ::jmp_buf JumpBuffer;
2728 volatile unsigned Failed : 1;
2829
2930 public:
30 CrashRecoveryContextImpl() : Failed(false) {
31 CrashRecoveryContextImpl(CrashRecoveryContext *CRC) : CRC(CRC),
32 Failed(false) {
3133 CurrentContext.set(this);
3234 }
3335 ~CrashRecoveryContextImpl() {
5355 CrashRecoveryContext::~CrashRecoveryContext() {
5456 CrashRecoveryContextImpl *CRCI = (CrashRecoveryContextImpl *) Impl;
5557 delete CRCI;
58 }
59
60 CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
61 const CrashRecoveryContextImpl *CRCI = CurrentContext.get();
62 if (!CRCI)
63 return 0;
64
65 return CRCI->CRC;
5666 }
5767
5868 #ifdef LLVM_ON_WIN32
163173 // If crash recovery is disabled, do nothing.
164174 if (gCrashRecoveryEnabled) {
165175 assert(!Impl && "Crash recovery context already initialized!");
166 CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl;
176 CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl(this);
167177 Impl = CRCI;
168178
169179 if (setjmp(CRCI->JumpBuffer) != 0) {