From 9dfe0ca9a0228c4fa75c8a3e51840696cc6b4960 Mon Sep 17 00:00:00 2001 From: Adam Moss Date: Fri, 22 May 2009 09:58:47 +0000 Subject: svn merge -r121194:121210 svn+ssh://svn.lindenlab.com/svn/linden/branches/viewer/viewer-1.23.onetwo-merge-1 QAR-1531 viewer 1.23rc1+1.23rc2 merge to trunk --- indra/llcommon/llerror.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'indra/llcommon/llerror.cpp') diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index d671decccb..b135dafb3c 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -1223,9 +1223,62 @@ namespace LLError char** LLCallStacks::sBuffer = NULL ; S32 LLCallStacks::sIndex = 0 ; + class CallStacksLogLock + { + public: + CallStacksLogLock(); + ~CallStacksLogLock(); + bool ok() const { return mOK; } + private: + bool mLocked; + bool mOK; + }; + + CallStacksLogLock::CallStacksLogLock() + : mLocked(false), mOK(false) + { + if (!gCallStacksLogMutexp) + { + mOK = true; + return; + } + + const int MAX_RETRIES = 5; + for (int attempts = 0; attempts < MAX_RETRIES; ++attempts) + { + apr_status_t s = apr_thread_mutex_trylock(gCallStacksLogMutexp); + if (!APR_STATUS_IS_EBUSY(s)) + { + mLocked = true; + mOK = true; + return; + } + + ms_sleep(1); + } + + // We're hosed, we can't get the mutex. Blah. + std::cerr << "CallStacksLogLock::CallStacksLogLock: failed to get mutex for log" + << std::endl; + } + + CallStacksLogLock::~CallStacksLogLock() + { + if (mLocked) + { + apr_thread_mutex_unlock(gCallStacksLogMutexp); + } + } + //static void LLCallStacks::push(const char* function, const int line) { + CallStacksLogLock lock; + if (!lock.ok()) + { + return; + } + if(!sBuffer) { sBuffer = new char*[512] ; @@ -1261,6 +1314,12 @@ namespace LLError //static void LLCallStacks::end(std::ostringstream* _out) { + CallStacksLogLock lock; + if (!lock.ok()) + { + return; + } + if(!sBuffer) { sBuffer = new char*[512] ; @@ -1283,6 +1342,12 @@ namespace LLError //static void LLCallStacks::print() { + CallStacksLogLock lock; + if (!lock.ok()) + { + return; + } + if(sIndex > 0) { llinfos << " ************* PRINT OUT LL CALL STACKS ************* " << llendl ; -- cgit v1.2.3