diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2021-05-12 12:02:57 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2021-05-12 12:02:57 -0400 |
commit | 5b96ee0e10923a00ddb3836d4dc3c5f912ca4330 (patch) | |
tree | 4eff331f4bbfa8841c1a63b3fd9dedc93323e221 /indra/llcommon/llerror.cpp | |
parent | 147c66d67ce83778fc3f102dd132ec095e6032fc (diff) |
SL-10297: Eliminate llerror.cpp's Globals::messageStream and bool.
Instead of a single std::ostringstream instance shared by all callers, even
those on different threads, make each of the relevant lllog_test_() and
llcallstacks macros instantiate independent (stack) std::ostringstream
objects. lllog_test_() is called by LL_DEBUGS(), LLINFOS(), LL_WARNS(),
LL_ERRS(), LL_VLOGS() et al.
Eliminate LLError::Log::out(), whose sole function was to arbitrate use of
that shared std::ostringstream. Amusingly, if the lock couldn't be locked or
if messageStreamInUse was set, out() would allocate a new (heap!)
std::ostringstream anyway, which would then have to be freed by flush().
Make both LLError::Log::flush() overloads accept const std::ostringstream&.
Make LL_ENDL pass the local _out instance. This eliminates the need to check
whether the passed std::ostringstream* references the shared instance and
(if so) reset it or (if not) delete it.
Make LLError::LLCallStacks::insert() accept the local _out instance as non-
const std::ostream&, rather than acquiring and returning std::ostringstream*.
Make end() accept the local instance as const std::ostringstream&.
Diffstat (limited to 'indra/llcommon/llerror.cpp')
-rw-r--r-- | indra/llcommon/llerror.cpp | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 9d775dcef3..f7594ed815 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -442,8 +442,6 @@ namespace protected: Globals(); public: - std::ostringstream messageStream; - bool messageStreamInUse; std::string mFatalMessage; void addCallSite(LLError::CallSite&); @@ -453,12 +451,7 @@ namespace CallSiteVector callSites; }; - Globals::Globals() - : messageStream(), - messageStreamInUse(false), - callSites() - { - } + Globals::Globals() {} Globals* Globals::getInstance() { @@ -1359,25 +1352,7 @@ namespace LLError } - std::ostringstream* Log::out() - { - LLMutexTrylock lock(getMutex<LOG_MUTEX>(),5); - - if (lock.isLocked()) - { - Globals* g = Globals::getInstance(); - - if (!g->messageStreamInUse) - { - g->messageStreamInUse = true; - return &g->messageStream; - } - } - - return new std::ostringstream; - } - - void Log::flush(std::ostringstream* out, char* message) + void Log::flush(const std::ostringstream& out, char* message) { LLMutexTrylock lock(getMutex<LOG_MUTEX>(),5); if (!lock.isLocked()) @@ -1385,31 +1360,18 @@ namespace LLError return; } - if(strlen(out->str().c_str()) < 128) + if(strlen(out.str().c_str()) < 128) { - strcpy(message, out->str().c_str()); + strcpy(message, out.str().c_str()); } else { - strncpy(message, out->str().c_str(), 127); + strncpy(message, out.str().c_str(), 127); message[127] = '\0' ; } - - Globals* g = Globals::getInstance(); - if (out == &g->messageStream) - { - g->messageStream.clear(); - g->messageStream.str(""); - g->messageStreamInUse = false; - } - else - { - delete out; - } - return ; } - void Log::flush(std::ostringstream* out, const CallSite& site) + void Log::flush(const std::ostringstream& out, const CallSite& site) { LLMutexTrylock lock(getMutex<LOG_MUTEX>(),5); if (!lock.isLocked()) @@ -1420,18 +1382,7 @@ namespace LLError Globals* g = Globals::getInstance(); SettingsConfigPtr s = Settings::getInstance()->getSettingsConfig(); - std::string message = out->str(); - if (out == &g->messageStream) - { - g->messageStream.clear(); - g->messageStream.str(""); - g->messageStreamInUse = false; - } - else - { - delete out; - } - + std::string message = out.str(); if (site.mPrintOnce) { @@ -1600,15 +1551,13 @@ namespace LLError } //static - std::ostringstream* LLCallStacks::insert(const char* function, const int line) + void LLCallStacks::insert(std::ostream& out, const char* function, const int line) { - std::ostringstream* _out = LLError::Log::out(); - *_out << function << " line " << line << " " ; - return _out ; + out << function << " line " << line << " " ; } //static - void LLCallStacks::end(std::ostringstream* _out) + void LLCallStacks::end(const std::ostringstream& out) { LLMutexTrylock lock(getMutex<STACKS_MUTEX>(), 5); if (!lock.isLocked()) @@ -1626,7 +1575,7 @@ namespace LLError clear() ; } - LLError::Log::flush(_out, sBuffer[sIndex++]) ; + LLError::Log::flush(out, sBuffer[sIndex++]) ; } //static |