[icinga-checkins] icinga.org: icinga2/master: Use TLS for last exception stack trace.

git at icinga.org git at icinga.org
Fri Mar 8 14:44:14 CET 2013


Module: icinga2
Branch: master
Commit: 756d465ca9b3c157feebc464cee53e11d229b384
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=756d465ca9b3c157feebc464cee53e11d229b384

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Mar  8 14:41:01 2013 +0100

Use TLS for last exception stack trace.

---

 lib/base/exception.cpp |   13 ++++++-------
 lib/base/exception.h   |    2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp
index 810c336..f533d16 100644
--- a/lib/base/exception.cpp
+++ b/lib/base/exception.cpp
@@ -21,7 +21,7 @@
 
 using namespace icinga;
 
-StackTrace *Exception::m_StackTrace = NULL;
+boost::thread_specific_ptr<StackTrace> Exception::m_LastStackTrace;
 
 /**
  * Retrieves the error code for the exception.
@@ -146,11 +146,13 @@ void __cxa_throw(void *obj, void *pvtinfo, void (*dest)(void *))
 	if (tinfo->__is_pointer_p())
 		thrown_ptr = *(void **)thrown_ptr;
 
+	StackTrace trace;
+	Exception::SetLastStackTrace(trace);
+
 	/* Check if thrown_ptr inherits from boost::exception. */
 	if (boost_exc->__do_catch(tinfo, &thrown_ptr, 1)) {
 		boost::exception *ex = (boost::exception *)thrown_ptr;
 
-		StackTrace trace;
 		*ex << StackTraceErrorInfo(trace);
 	}
 
@@ -160,14 +162,11 @@ void __cxa_throw(void *obj, void *pvtinfo, void (*dest)(void *))
 
 StackTrace *Exception::GetLastStackTrace(void)
 {
-	return m_StackTrace;
+	return m_LastStackTrace.get();
 }
 
 void Exception::SetLastStackTrace(const StackTrace& trace)
 {
-	if (m_StackTrace)
-		delete m_StackTrace;
-
-	m_StackTrace = new StackTrace(trace);
+	m_LastStackTrace.reset(new StackTrace(trace));
 }
 
diff --git a/lib/base/exception.h b/lib/base/exception.h
index 8d73357..8af7e83 100644
--- a/lib/base/exception.h
+++ b/lib/base/exception.h
@@ -65,7 +65,7 @@ private:
 	String m_Message;
 	int m_Code;
 
-	static StackTrace *m_StackTrace;
+	static boost::thread_specific_ptr<StackTrace> m_LastStackTrace;
 };
 
 typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;





More information about the icinga-checkins mailing list