[llvm-commits] [llvm] r74227 - /llvm/trunk/lib/Support/PrettyStackTrace.cpp
Owen Anderson
resistor at mac.com
Thu Jun 25 16:31:34 PDT 2009
Author: resistor
Date: Thu Jun 25 18:31:33 2009
New Revision: 74227
URL: http://llvm.org/viewvc/llvm-project?rev=74227&view=rev
Log:
Support thread-local pretty stack traces.
Modified:
llvm/trunk/lib/Support/PrettyStackTrace.cpp
Modified: llvm/trunk/lib/Support/PrettyStackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PrettyStackTrace.cpp?rev=74227&r1=74226&r2=74227&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PrettyStackTrace.cpp (original)
+++ llvm/trunk/lib/Support/PrettyStackTrace.cpp Thu Jun 25 18:31:33 2009
@@ -15,11 +15,12 @@
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
+#include "llvm/System/ThreadLocal.h"
#include "llvm/ADT/SmallString.h"
using namespace llvm;
// FIXME: This should be thread local when llvm supports threads.
-static const PrettyStackTraceEntry *PrettyStackTraceHead = 0;
+static sys::ThreadLocal<const PrettyStackTraceEntry> PrettyStackTraceHead;
static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
unsigned NextID = 0;
@@ -34,12 +35,12 @@
/// PrintCurStackTrace - Print the current stack trace to the specified stream.
static void PrintCurStackTrace(raw_ostream &OS) {
// Don't print an empty trace.
- if (PrettyStackTraceHead == 0) return;
+ if (PrettyStackTraceHead.get() == 0) return;
// If there are pretty stack frames registered, walk and emit them.
OS << "Stack dump:\n";
- PrintStack(PrettyStackTraceHead, OS);
+ PrintStack(PrettyStackTraceHead.get(), OS);
OS.flush();
}
@@ -84,14 +85,14 @@
HandlerRegistered = HandlerRegistered;
// Link ourselves.
- NextEntry = PrettyStackTraceHead;
- PrettyStackTraceHead = this;
+ NextEntry = PrettyStackTraceHead.get();
+ PrettyStackTraceHead.set(this);
}
PrettyStackTraceEntry::~PrettyStackTraceEntry() {
- assert(PrettyStackTraceHead == this &&
+ assert(PrettyStackTraceHead.get() == this &&
"Pretty stack trace entry destruction is out of order");
- PrettyStackTraceHead = getNextEntry();
+ PrettyStackTraceHead.set(getNextEntry());
}
void PrettyStackTraceString::print(raw_ostream &OS) const {
More information about the llvm-commits
mailing list