From 5144dd4d9c83813ae83dae19ac34df89fcc3d67f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 8 Feb 2022 17:12:23 +0100 Subject: [PATCH] #21 add thread name, kill all child threads --- BaseCommon/Thread.cpp | 6 +++++- BaseCommon/Thread.h | 4 +++- Common/APRSHandlerThread.cpp | 4 ++-- Common/DPlusAuthenticator.cpp | 3 ++- Common/IcomRepeaterProtocolHandler.cpp | 3 ++- DStarGateway/DStarGatewayThread.cpp | 9 ++++++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/BaseCommon/Thread.cpp b/BaseCommon/Thread.cpp index f2ea928..5ca7564 100644 --- a/BaseCommon/Thread.cpp +++ b/BaseCommon/Thread.cpp @@ -18,10 +18,12 @@ #include #include "Thread.h" +#include "Log.h" using namespace std; -CThread::CThread() +CThread::CThread(const std::string& name) : +m_name(name) { } @@ -53,5 +55,7 @@ void CThread::Wait() void CThread::EntryRunner(CThread * thread) { + assert(thread != nullptr); thread->Entry(); + CLog::logTrace("Exiting %s thread", thread->m_name.c_str()); } \ No newline at end of file diff --git a/BaseCommon/Thread.h b/BaseCommon/Thread.h index 4715f8d..70aa762 100644 --- a/BaseCommon/Thread.h +++ b/BaseCommon/Thread.h @@ -23,10 +23,11 @@ #define Thread_H #include +#include class CThread { public: - CThread(); + CThread(const std::string& name); virtual ~CThread(); void Create(); void Run(); @@ -39,6 +40,7 @@ protected: private: static void EntryRunner(CThread * thread); + std::string m_name; std::thread m_thread; }; diff --git a/Common/APRSHandlerThread.cpp b/Common/APRSHandlerThread.cpp index 1d6b099..e3098c6 100644 --- a/Common/APRSHandlerThread.cpp +++ b/Common/APRSHandlerThread.cpp @@ -37,7 +37,7 @@ const unsigned int APRS_READ_TIMEOUT = 1U; const unsigned int APRS_KEEP_ALIVE_TIMEOUT = 60U; CAPRSHandlerThread::CAPRSHandlerThread(const std::string& callsign, const std::string& password, const std::string& address, const std::string& hostname, unsigned int port) : -CThread(), +CThread("APRS"), m_username(callsign), m_password(password), m_ssid(callsign), @@ -65,7 +65,7 @@ m_clientName(FULL_PRODUCT_NAME) } CAPRSHandlerThread::CAPRSHandlerThread(const std::string& callsign, const std::string& password, const std::string& address, const std::string& hostname, unsigned int port, const std::string& filter) : -CThread(), +CThread("APRS"), m_username(callsign), m_password(password), m_ssid(callsign), diff --git a/Common/DPlusAuthenticator.cpp b/Common/DPlusAuthenticator.cpp index e67ccf7..fc436a6 100644 --- a/Common/DPlusAuthenticator.cpp +++ b/Common/DPlusAuthenticator.cpp @@ -34,6 +34,7 @@ const unsigned int OPENDSTAR_PORT = 20001U; const unsigned int TCP_TIMEOUT = 10U; CDPlusAuthenticator::CDPlusAuthenticator(const std::string& loginCallsign, const std::string& gatewayCallsign, const std::string& address, CCacheManager* cache) : +CThread("DPlus"), m_loginCallsign(loginCallsign), m_gatewayCallsign(gatewayCallsign), m_address(address), @@ -106,7 +107,7 @@ void* CDPlusAuthenticator::Entry() void CDPlusAuthenticator::stop() { m_killed = true; - + CLog::logInfo("Stopping DPpus Authenticator"); Wait(); } diff --git a/Common/IcomRepeaterProtocolHandler.cpp b/Common/IcomRepeaterProtocolHandler.cpp index d6e20f8..7f3aa1e 100644 --- a/Common/IcomRepeaterProtocolHandler.cpp +++ b/Common/IcomRepeaterProtocolHandler.cpp @@ -32,6 +32,7 @@ const unsigned int LOOP_DELAY = 5UL; const unsigned int LOOP_TICKS = 200U; CIcomRepeaterProtocolHandler::CIcomRepeaterProtocolHandler(const std::string& address, unsigned int port, const std::string& icomAddress, unsigned int icomPort) : +CThread("Icom Protocol Handler"), m_socket(address, port), m_icomAddress(), m_icomPort(icomPort), @@ -527,7 +528,7 @@ CAMBEData* CIcomRepeaterProtocolHandler::readBusyAMBE() void CIcomRepeaterProtocolHandler::close() { m_killed = true; - + CLog::logInfo("Stopping Icom Repeater protocol handler thread"); Wait(); } diff --git a/DStarGateway/DStarGatewayThread.cpp b/DStarGateway/DStarGatewayThread.cpp index 693075d..a2d4bc6 100644 --- a/DStarGateway/DStarGatewayThread.cpp +++ b/DStarGateway/DStarGatewayThread.cpp @@ -60,7 +60,7 @@ const std::string LOOPBACK_ADDRESS("127.0.0.1"); const unsigned int REMOTE_DUMMY_PORT = 65016U; CDStarGatewayThread::CDStarGatewayThread(const std::string& logDir, const std::string& dataDir, const std::string& name) : -CThread(), +CThread("Gateway"), m_logDir(logDir), m_dataDir(dataDir), m_name(name), @@ -481,11 +481,18 @@ void* CDStarGatewayThread::Entry() delete m_remote; } + if(m_aprsWriter != nullptr) { + m_aprsWriter->close(); + delete m_aprsWriter; + } + if (headerLogger != NULL) { headerLogger->close(); delete headerLogger; } + CDPlusHandler::finalise(); + return NULL; }