From: Maxim Mamontov Date: Wed, 5 Jan 2011 15:25:43 +0000 (+0200) Subject: При роботі з повідомленнями прибрано зайві блокування і перевірки X-Git-Tag: 2.407-rc3~207 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/c03710e5962e640d8a8e23cd9144e753ff282a50 При роботі з повідомленнями прибрано зайві блокування і перевірки --- diff --git a/projects/stargazer/user.cpp b/projects/stargazer/user.cpp index 50046fa5..b68c632a 100644 --- a/projects/stargazer/user.cpp +++ b/projects/stargazer/user.cpp @@ -1153,7 +1153,19 @@ int USER::AddMessage(STG_MSG * msg) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (SendMessage(*msg) == 0) +if (SendMessage(*msg)) + { + if (store->AddMessage(msg, login)) + { + errorStr = store->GetStrError(); + STG_LOGGER & WriteServLog = GetStgLogger(); + WriteServLog("Error adding message %s", errorStr.c_str()); + WriteServLog("%s", store->GetStrError().c_str()); + return -1; + } + messages.push_back(*msg); + } +else { if (msg->header.repeat > 0) { @@ -1175,46 +1187,26 @@ if (SendMessage(*msg) == 0) messages.push_back(*msg); } } -else - { - if (store->AddMessage(msg, login)) - { - errorStr = store->GetStrError(); - STG_LOGGER & WriteServLog = GetStgLogger(); - WriteServLog("Error adding message %s", errorStr.c_str()); - WriteServLog("%s", store->GetStrError().c_str()); - return -1; - } - messages.push_back(*msg); - } return 0; } //----------------------------------------------------------------------------- int USER::SendMessage(const STG_MSG & msg) { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); - -if (authorizedBy.empty()) - { - return -1; - } - +// No lock `cause we are already locked from caller int ret = -1; -set::iterator it; - -it = authorizedBy.begin(); +set::iterator it(authorizedBy.begin()); while (it != authorizedBy.end()) { - if ((*it)->SendMessage(msg, currIP) == 0) + if (!(*it++)->SendMessage(msg, currIP)) ret = 0; - ++it; } return ret; } //----------------------------------------------------------------------------- int USER::ScanMessage() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +// No lock `cause we are already locked from caller +// We need not check for the authorizedBy `cause it has already checked by caller /*vector hdrsList; @@ -1268,7 +1260,7 @@ while (it != messages.end()) { if (SendMessage(*it)) { - break; + return -1; } it->header.repeat--; if (it->header.repeat < 0)