More mutex clean up

pull/11/head
Geoffrey Merck 4 years ago
parent 1b7548f824
commit f967ffd747

@ -177,7 +177,7 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon
CUtils::ReplaceChar(d2, ' ', '_'); CUtils::ReplaceChar(d2, ' ', '_');
CUtils::ReplaceChar(cs, ' ', '_'); CUtils::ReplaceChar(cs, ' ', '_');
d->moduleQTHURLMutex.lock(); std::lock_guard lochQTHURL(d->moduleQTHURLMutex);
d->moduleQTH[cs] = cs + std::string(" ") + pos + std::string(" ") + d1 + std::string(" ") + d2; d->moduleQTH[cs] = cs + std::string(" ") + pos + std::string(" ") + d1 + std::string(" ") + d2;
@ -194,7 +194,6 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon
CLog::logInfo("URL: %s\n", d->moduleURL[cs].c_str()); CLog::logInfo("URL: %s\n", d->moduleURL[cs].c_str());
} }
d->moduleQTHURLMutex.unlock();
d->infoTimer = 5; // send info in 5 seconds d->infoTimer = 5; // send info in 5 seconds
} }
@ -208,10 +207,9 @@ void IRCDDBApp::rptrQRG(const std::string& callsign, double txFrequency, double
std::string f(fstr); std::string f(fstr);
CUtils::ReplaceChar(f, ',', '.'); CUtils::ReplaceChar(f, ',', '.');
d->moduleQRGMutex.lock(); std::lock_guard lockModuleQRG(d->moduleQRGMutex);
d->moduleQRG[cs] = cs + std::string(" ") + f; d->moduleQRG[cs] = cs + std::string(" ") + f;
CLog::logInfo("QRG: %s\n", d->moduleQRG[cs].c_str()); CLog::logInfo("QRG: %s\n", d->moduleQRG[cs].c_str());
d->moduleQRGMutex.unlock();
d->infoTimer = 5; // send info in 5 seconds d->infoTimer = 5; // send info in 5 seconds
} }
@ -229,9 +227,8 @@ void IRCDDBApp::kickWatchdog(const std::string& callsign, const std::string& s)
std::string cs = callsign; std::string cs = callsign;
CUtils::ReplaceChar(cs, ' ', '_'); CUtils::ReplaceChar(cs, ' ', '_');
d->moduleWDMutex.lock(); std::lock_guard lockModuleWD(d->moduleWDMutex);
d->moduleWD[cs] = cs + std::string(" ") + text; d->moduleWD[cs] = cs + std::string(" ") + text;
d->moduleWDMutex.unlock();
d->wdTimer = 60; d->wdTimer = 60;
} }
} }
@ -300,7 +297,7 @@ unsigned int IRCDDBApp::calculateUsn(const std::string& nick)
void IRCDDBApp::userJoin(const std::string& nick, const std::string& name, const std::string& host) void IRCDDBApp::userJoin(const std::string& nick, const std::string& name, const std::string& host)
{ {
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
std::string lnick = nick; std::string lnick = nick;
CUtils::ToLower(lnick); CUtils::ToLower(lnick);
@ -325,7 +322,6 @@ void IRCDDBApp::userJoin(const std::string& nick, const std::string& name, const
d->replyQ.putMessage(m2); d->replyQ.putMessage(m2);
} }
} }
d->userMapMutex.unlock();
} }
void IRCDDBApp::userLeave(const std::string& nick) void IRCDDBApp::userLeave(const std::string& nick)
@ -333,13 +329,12 @@ void IRCDDBApp::userLeave(const std::string& nick)
std::string lnick = nick; std::string lnick = nick;
CUtils::ToLower(lnick); CUtils::ToLower(lnick);
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
d->user.erase(lnick); d->user.erase(lnick);
if (d->currentServer.size()) { if (d->currentServer.size()) {
if (d->user.count(d->myNick) != 1) { if (d->user.count(d->myNick) != 1) {
CLog::logInfo("IRCDDBApp::userLeave: could not find own nick\n"); CLog::logInfo("IRCDDBApp::userLeave: could not find own nick\n");
d->userMapMutex.unlock();
return; return;
} }
@ -356,14 +351,12 @@ void IRCDDBApp::userLeave(const std::string& nick)
} }
} }
} }
d->userMapMutex.unlock();
} }
void IRCDDBApp::userListReset() void IRCDDBApp::userListReset()
{ {
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
d->user.clear(); d->user.clear();
d->userMapMutex.unlock();
} }
void IRCDDBApp::setCurrentNick(const std::string& nick) void IRCDDBApp::setCurrentNick(const std::string& nick)
@ -386,7 +379,7 @@ void IRCDDBApp::setTopic(const std::string& topic)
bool IRCDDBApp::findServerUser() bool IRCDDBApp::findServerUser()
{ {
bool found = false; bool found = false;
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
std::map<std::string, IRCDDBAppUserObject>::iterator it; std::map<std::string, IRCDDBAppUserObject>::iterator it;
@ -401,7 +394,6 @@ bool IRCDDBApp::findServerUser()
} }
if (found) { if (found) {
d->userMapMutex.unlock();
return true; return true;
} }
@ -418,7 +410,6 @@ bool IRCDDBApp::findServerUser()
} }
if (found) { if (found) {
d->userMapMutex.unlock();
return true; return true;
} }
@ -430,20 +421,18 @@ bool IRCDDBApp::findServerUser()
break; break;
} }
} }
d->userMapMutex.unlock();
return found; return found;
} }
void IRCDDBApp::userChanOp(const std::string& nick, bool op) void IRCDDBApp::userChanOp(const std::string& nick, bool op)
{ {
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
std::string lnick = nick; std::string lnick = nick;
CUtils::ToLower(lnick); CUtils::ToLower(lnick);
if (d->user.count(lnick) == 1) if (d->user.count(lnick) == 1)
d->user[lnick].op = op; d->user[lnick].op = op;
d->userMapMutex.unlock();
} }
static const int numberOfTables = 2; static const int numberOfTables = 2;
@ -457,7 +446,7 @@ std::string IRCDDBApp::getIPAddress(std::string& zonerp_cs)
CUtils::ToLower(gw); CUtils::ToLower(gw);
CUtils::Trim(gw); CUtils::Trim(gw);
d->userMapMutex.lock(); std::lock_guard lockUserMap(d->userMapMutex);
for (int j=1; j <= 4; j++) { for (int j=1; j <= 4; j++) {
std::string ircUser = gw + std::string("-") + std::to_string(j); std::string ircUser = gw + std::string("-") + std::to_string(j);
@ -470,7 +459,6 @@ std::string IRCDDBApp::getIPAddress(std::string& zonerp_cs)
} }
} }
} }
d->userMapMutex.unlock();
return ipAddr; return ipAddr;
} }
@ -977,7 +965,8 @@ void IRCDDBApp::Entry()
d->infoTimer--; d->infoTimer--;
if (0 == d->infoTimer) { if (0 == d->infoTimer) {
d->moduleQTHURLMutex.lock(); { // Scope for mutext locking
std::lock_guard lochQTHURL(d->moduleQTHURLMutex);
for (auto it = d->moduleQTH.begin(); it != d->moduleQTH.end(); ++it) { for (auto it = d->moduleQTH.begin(); it != d->moduleQTH.end(); ++it) {
std::string value = it->second; std::string value = it->second;
IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQTH: ") + value); IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQTH: ") + value);
@ -995,9 +984,9 @@ void IRCDDBApp::Entry()
q->putMessage(m); q->putMessage(m);
} }
d->moduleURL.clear(); d->moduleURL.clear();
d->moduleQTHURLMutex.unlock(); }
d->moduleQRGMutex.lock(); std::lock_guard lockModuleQRG(d->moduleQRGMutex);
for (auto it = d->moduleQRG.begin(); it != d->moduleQRG.end(); ++it) { for (auto it = d->moduleQRG.begin(); it != d->moduleQRG.end(); ++it) {
std::string value = it->second; std::string value = it->second;
IRCMessage* m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQRG: ") + value); IRCMessage* m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQRG: ") + value);
@ -1006,7 +995,6 @@ void IRCDDBApp::Entry()
q->putMessage(m); q->putMessage(m);
} }
d->moduleQRG.clear(); d->moduleQRG.clear();
d->moduleQRGMutex.unlock();
} }
} }
@ -1014,7 +1002,7 @@ void IRCDDBApp::Entry()
d->wdTimer--; d->wdTimer--;
if (0 == d->wdTimer) { if (0 == d->wdTimer) {
d->moduleWDMutex.lock(); std::lock_guard lockModuleWD(d->moduleWDMutex);
for (auto it = d->moduleWD.begin(); it != d->moduleWD.end(); ++it) { for (auto it = d->moduleWD.begin(); it != d->moduleWD.end(); ++it) {
std::string value = it->second; std::string value = it->second;
@ -1024,7 +1012,6 @@ void IRCDDBApp::Entry()
q->putMessage(m); q->putMessage(m);
} }
d->moduleWD.clear(); d->moduleWD.clear();
d->moduleWDMutex.unlock();
} }
} }
break; break;

@ -30,12 +30,11 @@ IRCMessageQueue::IRCMessageQueue()
IRCMessageQueue::~IRCMessageQueue() IRCMessageQueue::~IRCMessageQueue()
{ {
accessMutex.lock(); std::lock_guard lockAccessQueue(accessMutex);
while (! m_queue.empty()) { while (! m_queue.empty()) {
delete m_queue.front(); delete m_queue.front();
m_queue.pop(); m_queue.pop();
} }
accessMutex.unlock();
} }
bool IRCMessageQueue::isEOF() bool IRCMessageQueue::isEOF()
@ -50,35 +49,33 @@ void IRCMessageQueue::signalEOF()
bool IRCMessageQueue::messageAvailable() bool IRCMessageQueue::messageAvailable()
{ {
accessMutex.lock(); std::lock_guard lockAccessQueue(accessMutex);
bool retv = ! m_queue.empty(); bool retv = ! m_queue.empty();
accessMutex.unlock();
return retv; return retv;
} }
IRCMessage *IRCMessageQueue::peekFirst() IRCMessage *IRCMessageQueue::peekFirst()
{ {
accessMutex.lock(); std::lock_guard lockAccessQueue(accessMutex);
IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front(); IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front();
accessMutex.unlock();
return msg; return msg;
} }
IRCMessage *IRCMessageQueue::getMessage() IRCMessage *IRCMessageQueue::getMessage()
{ {
accessMutex.lock(); std::lock_guard lockAccessQueue(accessMutex);
IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front(); IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front();
if (msg) if (msg)
m_queue.pop(); m_queue.pop();
accessMutex.unlock();
return msg; return msg;
} }
void IRCMessageQueue::putMessage(IRCMessage *m) void IRCMessageQueue::putMessage(IRCMessage *m)
{ {
accessMutex.lock(); std::lock_guard lockAccessQueue(accessMutex);
m_queue.push(m); m_queue.push(m);
accessMutex.unlock();
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.