diff --git a/IRCDDBApp.cpp b/IRCDDBApp.cpp index 96ac2a2..190ddd5 100644 --- a/IRCDDBApp.cpp +++ b/IRCDDBApp.cpp @@ -177,7 +177,7 @@ void IRCDDBApp::rptrQTH(const std::string& callsign, double latitude, double lon CUtils::ReplaceChar(d2, ' ', '_'); 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; @@ -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()); } - d->moduleQTHURLMutex.unlock(); 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); CUtils::ReplaceChar(f, ',', '.'); - d->moduleQRGMutex.lock(); + std::lock_guard lockModuleQRG(d->moduleQRGMutex); d->moduleQRG[cs] = cs + std::string(" ") + f; CLog::logInfo("QRG: %s\n", d->moduleQRG[cs].c_str()); - d->moduleQRGMutex.unlock(); 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; CUtils::ReplaceChar(cs, ' ', '_'); - d->moduleWDMutex.lock(); + std::lock_guard lockModuleWD(d->moduleWDMutex); d->moduleWD[cs] = cs + std::string(" ") + text; - d->moduleWDMutex.unlock(); 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) { - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); std::string lnick = nick; CUtils::ToLower(lnick); @@ -325,7 +322,6 @@ void IRCDDBApp::userJoin(const std::string& nick, const std::string& name, const d->replyQ.putMessage(m2); } } - d->userMapMutex.unlock(); } void IRCDDBApp::userLeave(const std::string& nick) @@ -333,13 +329,12 @@ void IRCDDBApp::userLeave(const std::string& nick) std::string lnick = nick; CUtils::ToLower(lnick); - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); d->user.erase(lnick); if (d->currentServer.size()) { if (d->user.count(d->myNick) != 1) { CLog::logInfo("IRCDDBApp::userLeave: could not find own nick\n"); - d->userMapMutex.unlock(); return; } @@ -356,14 +351,12 @@ void IRCDDBApp::userLeave(const std::string& nick) } } } - d->userMapMutex.unlock(); } void IRCDDBApp::userListReset() { - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); d->user.clear(); - d->userMapMutex.unlock(); } void IRCDDBApp::setCurrentNick(const std::string& nick) @@ -386,7 +379,7 @@ void IRCDDBApp::setTopic(const std::string& topic) bool IRCDDBApp::findServerUser() { bool found = false; - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); std::map::iterator it; @@ -401,7 +394,6 @@ bool IRCDDBApp::findServerUser() } if (found) { - d->userMapMutex.unlock(); return true; } @@ -418,7 +410,6 @@ bool IRCDDBApp::findServerUser() } if (found) { - d->userMapMutex.unlock(); return true; } @@ -430,20 +421,18 @@ bool IRCDDBApp::findServerUser() break; } } - d->userMapMutex.unlock(); return found; } void IRCDDBApp::userChanOp(const std::string& nick, bool op) { - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); std::string lnick = nick; CUtils::ToLower(lnick); if (d->user.count(lnick) == 1) d->user[lnick].op = op; - d->userMapMutex.unlock(); } static const int numberOfTables = 2; @@ -457,7 +446,7 @@ std::string IRCDDBApp::getIPAddress(std::string& zonerp_cs) CUtils::ToLower(gw); CUtils::Trim(gw); - d->userMapMutex.lock(); + std::lock_guard lockUserMap(d->userMapMutex); for (int j=1; j <= 4; 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; } @@ -531,8 +519,7 @@ bool IRCDDBApp::findRepeater(const std::string& rptrCall) std::string s("NONE"); std::string zonerp_cs; - d->rptrMapMutex.lock(); - + std::lock_guard lockRptrMap(d->rptrMapMutex); if (1 == d->rptrMap.count(arearp_cs)) { IRCDDBAppRptrObject o = d->rptrMap[arearp_cs]; @@ -741,7 +728,7 @@ void IRCDDBApp::doUpdate(std::string& msg) return; // no valid key if (tableID == 1) { - d->rptrMapMutex.lock(); + std::lock_guard lockRptrMap(d->rptrMapMutex); IRCDDBAppRptrObject newRptr(dt, key, value, m_maxTime); d->rptrMap[key] = newRptr; @@ -759,9 +746,8 @@ void IRCDDBApp::doUpdate(std::string& msg) m2->addParam(getIPAddress(value)); d->replyQ.putMessage(m2); } - d->rptrMapMutex.unlock(); } else if (0==tableID && d->initReady) { - d->rptrMapMutex.lock(); + std::lock_guard lockRptrMap(d->rptrMapMutex); std::string userCallsign(key); std::string arearp_cs(value); std::string zonerp_cs; @@ -785,7 +771,6 @@ void IRCDDBApp::doUpdate(std::string& msg) m2->addParam(ip_addr); m2->addParam(tk + std::string(" ") + timeToken); d->replyQ.putMessage(m2); - d->rptrMapMutex.unlock(); } } } @@ -980,27 +965,28 @@ void IRCDDBApp::Entry() d->infoTimer--; if (0 == d->infoTimer) { - d->moduleQTHURLMutex.lock(); - for (auto it = d->moduleQTH.begin(); it != d->moduleQTH.end(); ++it) { - std::string value = it->second; - IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQTH: ") + value); - IRCMessageQueue *q = getSendQ(); - if (q != NULL) - q->putMessage(m); - } - d->moduleQTH.clear(); - - for (auto it = d->moduleURL.begin(); it != d->moduleURL.end(); ++it) { - std::string value = it->second; - IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRURL: ") + value); - IRCMessageQueue *q = getSendQ(); - if (q != NULL) - q->putMessage(m); + { // Scope for mutext locking + std::lock_guard lochQTHURL(d->moduleQTHURLMutex); + for (auto it = d->moduleQTH.begin(); it != d->moduleQTH.end(); ++it) { + std::string value = it->second; + IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQTH: ") + value); + IRCMessageQueue *q = getSendQ(); + if (q != NULL) + q->putMessage(m); + } + d->moduleQTH.clear(); + + for (auto it = d->moduleURL.begin(); it != d->moduleURL.end(); ++it) { + std::string value = it->second; + IRCMessage *m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRURL: ") + value); + IRCMessageQueue *q = getSendQ(); + if (q != NULL) + 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) { std::string value = it->second; IRCMessage* m = new IRCMessage(d->currentServer, std::string("IRCDDB RPTRQRG: ") + value); @@ -1009,7 +995,6 @@ void IRCDDBApp::Entry() q->putMessage(m); } d->moduleQRG.clear(); - d->moduleQRGMutex.unlock(); } } @@ -1017,7 +1002,7 @@ void IRCDDBApp::Entry() 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) { std::string value = it->second; @@ -1027,7 +1012,6 @@ void IRCDDBApp::Entry() q->putMessage(m); } d->moduleWD.clear(); - d->moduleWDMutex.unlock(); } } break; diff --git a/IRCDDBMultiClient.cpp b/IRCDDBMultiClient.cpp index 86ac8f4..7d76424 100644 --- a/IRCDDBMultiClient.cpp +++ b/IRCDDBMultiClient.cpp @@ -4,6 +4,7 @@ CIRCDDBClient - ircDDB client library in C++ Copyright (C) 2010-2011 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (C) 2011,2012 Jonathan Naylor, G4KLX +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCDDBMultiClient.h b/IRCDDBMultiClient.h index a0cafdf..172b529 100644 --- a/IRCDDBMultiClient.h +++ b/IRCDDBMultiClient.h @@ -4,6 +4,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010-2011 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (C) 2011,2012 Jonathan Naylor, G4KLX +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCMessage.cpp b/IRCMessage.cpp index 796a65d..8f6fb08 100644 --- a/IRCMessage.cpp +++ b/IRCMessage.cpp @@ -3,6 +3,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010-2011 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCMessage.h b/IRCMessage.h index 9755c87..e157405 100644 --- a/IRCMessage.h +++ b/IRCMessage.h @@ -3,6 +3,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCMessageQueue.cpp b/IRCMessageQueue.cpp index 7d80397..035e903 100644 --- a/IRCMessageQueue.cpp +++ b/IRCMessageQueue.cpp @@ -7,6 +7,9 @@ Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Completely rewritten by: Copyright (c) 2017 by Thomas A. Early N7TAE +Bug fixed by: +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or @@ -30,12 +33,11 @@ IRCMessageQueue::IRCMessageQueue() IRCMessageQueue::~IRCMessageQueue() { - accessMutex.lock(); + std::lock_guard lockAccessQueue(accessMutex); while (! m_queue.empty()) { delete m_queue.front(); m_queue.pop(); } - accessMutex.unlock(); } bool IRCMessageQueue::isEOF() @@ -50,35 +52,33 @@ void IRCMessageQueue::signalEOF() bool IRCMessageQueue::messageAvailable() { - accessMutex.lock(); + std::lock_guard lockAccessQueue(accessMutex); bool retv = ! m_queue.empty(); - accessMutex.unlock(); + return retv; } IRCMessage *IRCMessageQueue::peekFirst() { - accessMutex.lock(); + std::lock_guard lockAccessQueue(accessMutex); IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front(); - accessMutex.unlock(); return msg; } IRCMessage *IRCMessageQueue::getMessage() { - accessMutex.lock(); + std::lock_guard lockAccessQueue(accessMutex); IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front(); if (msg) m_queue.pop(); - accessMutex.unlock(); + return msg; } void IRCMessageQueue::putMessage(IRCMessage *m) { - accessMutex.lock(); + std::lock_guard lockAccessQueue(accessMutex); m_queue.push(m); - accessMutex.unlock(); } diff --git a/IRCMessageQueue.h b/IRCMessageQueue.h index f0edd76..3ab656b 100644 --- a/IRCMessageQueue.h +++ b/IRCMessageQueue.h @@ -1,12 +1,15 @@ /* CIRCDDB - ircDDB client library in C++ -Based on original code by: +Based on code by: Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Completely rewritten by: Copyright (c) 2017 by Thomas A. Early N7TAE +Bug fixed by: +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or diff --git a/IRCProtocol.cpp b/IRCProtocol.cpp index 2390404..0c43b50 100644 --- a/IRCProtocol.cpp +++ b/IRCProtocol.cpp @@ -3,6 +3,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010-2011 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCProtocol.h b/IRCProtocol.h index f8189ea..7f03d1b 100644 --- a/IRCProtocol.h +++ b/IRCProtocol.h @@ -3,6 +3,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCReceiver.cpp b/IRCReceiver.cpp index ca25604..b23128b 100644 --- a/IRCReceiver.cpp +++ b/IRCReceiver.cpp @@ -3,6 +3,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/IRCReceiver.h b/IRCReceiver.h index a4019d8..0768e2f 100644 --- a/IRCReceiver.h +++ b/IRCReceiver.h @@ -4,6 +4,7 @@ CIRCDDB - ircDDB client library in C++ Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de) Copyright (C) 2012 Jonathan Naylor, G4KLX Copyright (c) 2017 by Thomas A. Early N7TAE +Copyright (c) 2021 by Thomas Geoffrey Merck F4FXL / KC3FRA This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by