From 4890472c50a0d8bd0e0e198293278e099a980c75 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Fri, 24 Feb 2023 06:00:26 -0700 Subject: [PATCH] got rid of const_cast in CGateKeeper with a mutable mutex --- reflector/Buffer.cpp | 2 +- reflector/CallsignList.h | 10 +++++----- reflector/CodecStream.cpp | 4 ---- reflector/GateKeeper.cpp | 21 ++++++++++++--------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/reflector/Buffer.cpp b/reflector/Buffer.cpp index 8aa57a5..c99d290 100644 --- a/reflector/Buffer.cpp +++ b/reflector/Buffer.cpp @@ -176,7 +176,7 @@ CBuffer::operator const char *() const void CBuffer::DebugDump(std::ofstream &debugout) const { - // dump an hex line + // dump a hex line for ( unsigned int i = 0; i < m_data.size(); i++ ) { char sz[16]; diff --git a/reflector/CallsignList.h b/reflector/CallsignList.h index df1d153..3a221a1 100644 --- a/reflector/CallsignList.h +++ b/reflector/CallsignList.h @@ -33,8 +33,8 @@ public: CCallsignList(); // locks - void Lock(void) { m_Mutex.lock(); } - void Unlock(void) { m_Mutex.unlock(); } + void Lock(void) const { m_Mutex.lock(); } + void Unlock(void) const { m_Mutex.unlock(); } // file io virtual bool LoadFromFile(const std::string &str); @@ -60,8 +60,8 @@ protected: char *TrimWhiteSpaces(char *); // data - std::mutex m_Mutex; - std::string m_Filename; - time_t m_LastModTime; + mutable std::mutex m_Mutex; + std::string m_Filename; + time_t m_LastModTime; std::list m_Callsigns; }; diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index 70e6b39..6109fc0 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -133,10 +133,6 @@ void CCodecStream::Task(void) } m_RTSum += rt; m_RTCount++; -#ifdef DEBUG - if (0 == m_RTCount % 50) - ReportStats(); -#endif if ( m_LocalQueue.IsEmpty() ) { diff --git a/reflector/GateKeeper.cpp b/reflector/GateKeeper.cpp index 28065fc..f91db6e 100644 --- a/reflector/GateKeeper.cpp +++ b/reflector/GateKeeper.cpp @@ -204,17 +204,20 @@ bool CGateKeeper::IsNodeListedOk(const CCallsign &callsign, const CIp &ip, char { // first check if callsign is in white list // note if white list is empty, everybody is authorized - const_cast(m_NodeWhiteList).Lock(); + m_NodeWhiteList.Lock(); if ( !m_NodeWhiteList.empty() ) { ok = m_NodeWhiteList.IsCallsignListedWithWildcard(callsign, module); } - const_cast(m_NodeWhiteList).Unlock(); + m_NodeWhiteList.Unlock(); // then check if not blacklisted - const_cast(m_NodeBlackList).Lock(); - ok &= !m_NodeBlackList.IsCallsignListedWithWildcard(callsign); - const_cast(m_NodeBlackList).Unlock(); + if (ok) + { + m_NodeBlackList.Lock(); + ok = !m_NodeBlackList.IsCallsignListedWithWildcard(callsign); + m_NodeBlackList.Unlock(); + } } // done @@ -232,12 +235,12 @@ bool CGateKeeper::IsPeerListedOk(const CCallsign &callsign, const CIp &ip, char if ( ok ) { // look for an exact match in the list - const_cast(m_PeerList).Lock(); + m_PeerList.Lock(); if ( !m_PeerList.empty() ) { ok = m_PeerList.IsCallsignListed(callsign, module); } - const_cast(m_PeerList).Unlock(); + m_PeerList.Unlock(); } // done @@ -254,12 +257,12 @@ bool CGateKeeper::IsPeerListedOk(const CCallsign &callsign, const CIp &ip, char if ( ok ) { // look for an exact match in the list - const_cast(m_PeerList).Lock(); + m_PeerList.Lock(); if ( !m_PeerList.empty() ) { ok = m_PeerList.IsCallsignListed(callsign, modules); } - const_cast(m_PeerList).Unlock(); + m_PeerList.Unlock(); } // done