Allow calling LLNotificationsUtil::add from any thread.

This makes LLStringUtil thread-safe by removing a rather unnecessary
LLFastTimer from LLStringUtil::format.

Same thing for LLTrans::getString and LLTrans::findString, where
even a comment stated that the author wasn't interested in measuring
cpu time at all. In this case I added some code back to make sure
that we're not calling LLTrans::getString() in an inner loop, which
was the reason that the LLFastTimer was added.

Made one string static to avoid 45000 look ups during login, which
kinda triggered the above test.

Finally, LLNotificationsUtil::add is made thread-safe by making
LLNotificationChannelBase::mItems thread-safe and defering a call
to LLNotifications::updateItem to the main thread when called
from another thread (using a little statemachine).
This commit is contained in:
Aleric Inglewood
2013-11-15 17:52:52 +01:00
parent 5f9c6f1b08
commit a8cded0cf6
5 changed files with 167 additions and 24 deletions

View File

@@ -91,15 +91,20 @@ bool LLTrans::parseStrings(const std::string& xml_filename, const std::set<std::
return true;
}
static LLFastTimer::DeclareTimer FTM_GET_TRANS("Translate string");
static LLAtomicU32 sStringTemplates_accesses;
int const access_increment = 1000;
static void log_sStringTemplates_accesses(void)
{
llinfos << "LLTrans::getString/findString called " << sStringTemplates_accesses << " in total." << llendl;
}
//static
std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
LLFastTimer timer(FTM_GET_TRANS);
// Singu note: make sure LLTrans isn't used in a tight loop.
if (sStringTemplates_accesses++ % access_increment == access_increment - 1) log_sStringTemplates_accesses();
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
@@ -125,9 +130,11 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::
//static
std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args)
{
// Don't care about time as much as call count. Make sure we're not
// calling LLTrans::getString() in an inner loop. JC
LLFastTimer timer(FTM_GET_TRANS);
// Singu note: make sure LLTrans isn't used in a tight loop.
if (sStringTemplates_accesses++ % access_increment == 0) log_sStringTemplates_accesses();
// Since sStringTemplates is read-only after it's initial initialization during start up,
// this function is already thread-safe.
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
@@ -146,8 +153,9 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args
//static
bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
{
LLFastTimer timer(FTM_GET_TRANS);
// Singu note: make sure LLTrans isn't used in a tight loop.
if (sStringTemplates_accesses++ % access_increment == 0) log_sStringTemplates_accesses();
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())
{
@@ -168,7 +176,8 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const
//static
bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD& msg_args)
{
//V3: LLFastTimer timer(FTM_GET_TRANS);
// Singu note: make sure LLTrans isn't used in a tight loop.
if (sStringTemplates_accesses++ % access_increment == 0) log_sStringTemplates_accesses();
template_map_t::iterator iter = sStringTemplates.find(xml_desc);
if (iter != sStringTemplates.end())