diff options
Diffstat (limited to 'indra/llcommon/llerror.cpp')
-rw-r--r-- | indra/llcommon/llerror.cpp | 148 |
1 files changed, 19 insertions, 129 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 17d8164289..3db6705985 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -1096,6 +1096,9 @@ namespace } namespace { + LLMutex gLogMutex; + LLMutex gCallStacksLogMutex; + bool checkLevelMap(const LevelMap& map, const std::string& key, LLError::ELevel& level) { @@ -1135,56 +1138,6 @@ namespace { } return found_level; } - - class LogLock - { - public: - LogLock(); - ~LogLock(); - bool ok() const { return mOK; } - private: - bool mLocked; - bool mOK; - }; - - LogLock::LogLock() - : mLocked(false), mOK(false) - { - if (!gLogMutexp) - { - mOK = true; - return; - } - - const int MAX_RETRIES = 5; - for (int attempts = 0; attempts < MAX_RETRIES; ++attempts) - { - apr_status_t s = apr_thread_mutex_trylock(gLogMutexp); - if (!APR_STATUS_IS_EBUSY(s)) - { - mLocked = true; - mOK = true; - return; - } - - ms_sleep(1); - //apr_thread_yield(); - // Just yielding won't necessarily work, I had problems with - // this on Linux - doug 12/02/04 - } - - // We're hosed, we can't get the mutex. Blah. - std::cerr << "LogLock::LogLock: failed to get mutex for log" - << std::endl; - } - - LogLock::~LogLock() - { - if (mLocked) - { - apr_thread_mutex_unlock(gLogMutexp); - } - } } namespace LLError @@ -1192,8 +1145,8 @@ namespace LLError bool Log::shouldLog(CallSite& site) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex, 5); + if (!lock.isLocked()) { return false; } @@ -1243,11 +1196,11 @@ namespace LLError std::ostringstream* Log::out() { - LogLock lock; + LLMutexTrylock lock(&gLogMutex,5); // If we hit a logging request very late during shutdown processing, // when either of the relevant LLSingletons has already been deleted, // DO NOT resurrect them. - if (lock.ok() && ! (Settings::wasDeleted() || Globals::wasDeleted())) + if (lock.isLocked() && ! (Settings::wasDeleted() || Globals::wasDeleted())) { Globals* g = Globals::getInstance(); @@ -1263,8 +1216,8 @@ namespace LLError void Log::flush(std::ostringstream* out, char* message) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex,5); + if (!lock.isLocked()) { return; } @@ -1303,8 +1256,8 @@ namespace LLError void Log::flush(std::ostringstream* out, const CallSite& site) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex,5); + if (!lock.isLocked()) { return; } @@ -1469,69 +1422,6 @@ namespace LLError char** LLCallStacks::sBuffer = NULL ; S32 LLCallStacks::sIndex = 0 ; -#define SINGLE_THREADED 1 - - class CallStacksLogLock - { - public: - CallStacksLogLock(); - ~CallStacksLogLock(); - -#if SINGLE_THREADED - bool ok() const { return true; } -#else - bool ok() const { return mOK; } - private: - bool mLocked; - bool mOK; -#endif - }; - -#if SINGLE_THREADED - CallStacksLogLock::CallStacksLogLock() - { - } - CallStacksLogLock::~CallStacksLogLock() - { - } -#else - 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); - } - } -#endif - //static void LLCallStacks::allocateStackBuffer() { @@ -1560,8 +1450,8 @@ namespace LLError //static void LLCallStacks::push(const char* function, const int line) { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1595,8 +1485,8 @@ namespace LLError //static void LLCallStacks::end(std::ostringstream* _out) { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1617,8 +1507,8 @@ namespace LLError //static void LLCallStacks::print() { - CallStacksLogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gCallStacksLogMutex, 5); + if (!lock.isLocked()) { return; } @@ -1655,8 +1545,8 @@ namespace LLError bool debugLoggingEnabled(const std::string& tag) { - LogLock lock; - if (!lock.ok()) + LLMutexTrylock lock(&gLogMutex, 5); + if (!lock.isLocked()) { return false; } |