got rid of const_cast in CGateKeeper with a mutable mutex

pull/1/head
Tom Early 3 years ago
parent 864d834ddb
commit 4890472c50

@ -176,7 +176,7 @@ CBuffer::operator const char *() const
void CBuffer::DebugDump(std::ofstream &debugout) 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++ ) for ( unsigned int i = 0; i < m_data.size(); i++ )
{ {
char sz[16]; char sz[16];

@ -33,8 +33,8 @@ public:
CCallsignList(); CCallsignList();
// locks // locks
void Lock(void) { m_Mutex.lock(); } void Lock(void) const { m_Mutex.lock(); }
void Unlock(void) { m_Mutex.unlock(); } void Unlock(void) const { m_Mutex.unlock(); }
// file io // file io
virtual bool LoadFromFile(const std::string &str); virtual bool LoadFromFile(const std::string &str);
@ -60,7 +60,7 @@ protected:
char *TrimWhiteSpaces(char *); char *TrimWhiteSpaces(char *);
// data // data
std::mutex m_Mutex; mutable std::mutex m_Mutex;
std::string m_Filename; std::string m_Filename;
time_t m_LastModTime; time_t m_LastModTime;
std::list<CCallsignListItem> m_Callsigns; std::list<CCallsignListItem> m_Callsigns;

@ -133,10 +133,6 @@ void CCodecStream::Task(void)
} }
m_RTSum += rt; m_RTSum += rt;
m_RTCount++; m_RTCount++;
#ifdef DEBUG
if (0 == m_RTCount % 50)
ReportStats();
#endif
if ( m_LocalQueue.IsEmpty() ) if ( m_LocalQueue.IsEmpty() )
{ {

@ -204,17 +204,20 @@ bool CGateKeeper::IsNodeListedOk(const CCallsign &callsign, const CIp &ip, char
{ {
// first check if callsign is in white list // first check if callsign is in white list
// note if white list is empty, everybody is authorized // note if white list is empty, everybody is authorized
const_cast<CCallsignList &>(m_NodeWhiteList).Lock(); m_NodeWhiteList.Lock();
if ( !m_NodeWhiteList.empty() ) if ( !m_NodeWhiteList.empty() )
{ {
ok = m_NodeWhiteList.IsCallsignListedWithWildcard(callsign, module); ok = m_NodeWhiteList.IsCallsignListedWithWildcard(callsign, module);
} }
const_cast<CCallsignList &>(m_NodeWhiteList).Unlock(); m_NodeWhiteList.Unlock();
// then check if not blacklisted // then check if not blacklisted
const_cast<CCallsignList &>(m_NodeBlackList).Lock(); if (ok)
ok &= !m_NodeBlackList.IsCallsignListedWithWildcard(callsign); {
const_cast<CCallsignList &>(m_NodeBlackList).Unlock(); m_NodeBlackList.Lock();
ok = !m_NodeBlackList.IsCallsignListedWithWildcard(callsign);
m_NodeBlackList.Unlock();
}
} }
// done // done
@ -232,12 +235,12 @@ bool CGateKeeper::IsPeerListedOk(const CCallsign &callsign, const CIp &ip, char
if ( ok ) if ( ok )
{ {
// look for an exact match in the list // look for an exact match in the list
const_cast<CPeerCallsignList &>(m_PeerList).Lock(); m_PeerList.Lock();
if ( !m_PeerList.empty() ) if ( !m_PeerList.empty() )
{ {
ok = m_PeerList.IsCallsignListed(callsign, module); ok = m_PeerList.IsCallsignListed(callsign, module);
} }
const_cast<CPeerCallsignList &>(m_PeerList).Unlock(); m_PeerList.Unlock();
} }
// done // done
@ -254,12 +257,12 @@ bool CGateKeeper::IsPeerListedOk(const CCallsign &callsign, const CIp &ip, char
if ( ok ) if ( ok )
{ {
// look for an exact match in the list // look for an exact match in the list
const_cast<CPeerCallsignList &>(m_PeerList).Lock(); m_PeerList.Lock();
if ( !m_PeerList.empty() ) if ( !m_PeerList.empty() )
{ {
ok = m_PeerList.IsCallsignListed(callsign, modules); ok = m_PeerList.IsCallsignListed(callsign, modules);
} }
const_cast<CPeerCallsignList &>(m_PeerList).Unlock(); m_PeerList.Unlock();
} }
// done // done

Loading…
Cancel
Save

Powered by TurnKey Linux.