add some mutex locking for affiliation lookups;

pull/75/head
Bryan Biedenkapp 1 year ago
parent 482a480edf
commit 2979110421

@ -20,6 +20,12 @@ using namespace lookups;
const uint32_t UNIT_REG_TIMEOUT = 43200U; // 12 hours const uint32_t UNIT_REG_TIMEOUT = 43200U; // 12 hours
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std::mutex AffiliationLookup::m_mutex;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Public Class Members // Public Class Members
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -297,6 +303,7 @@ bool AffiliationLookup::grantCh(uint32_t dstId, uint32_t srcId, uint32_t grantTi
return false; return false;
} }
std::lock_guard<std::mutex> lock(m_mutex);
uint32_t chNo = m_chLookup->getFirstRFChannel(); uint32_t chNo = m_chLookup->getFirstRFChannel();
m_chLookup->removeRFCh(chNo); m_chLookup->removeRFCh(chNo);
@ -326,6 +333,7 @@ void AffiliationLookup::touchGrant(uint32_t dstId)
return; return;
} }
std::lock_guard<std::mutex> lock(m_mutex);
if (isGranted(dstId)) { if (isGranted(dstId)) {
m_grantTimers[dstId].start(); m_grantTimers[dstId].start();
} }
@ -333,12 +341,15 @@ void AffiliationLookup::touchGrant(uint32_t dstId)
/* Helper to release the channel grant for the destination ID. */ /* Helper to release the channel grant for the destination ID. */
bool AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll) bool AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll, bool noLock)
{ {
if (dstId == 0U && !releaseAll) { if (dstId == 0U && !releaseAll) {
return false; return false;
} }
if (!noLock)
m_mutex.lock();
// are we trying to release all grants? // are we trying to release all grants?
if (dstId == 0U && releaseAll) { if (dstId == 0U && releaseAll) {
LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name.c_str()); LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name.c_str());
@ -354,6 +365,8 @@ bool AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll)
releaseGrant(dstId, false); releaseGrant(dstId, false);
} }
if (!noLock)
m_mutex.unlock();
return true; return true;
} }
@ -383,9 +396,14 @@ bool AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll)
} }
m_grantTimers[dstId].stop(); m_grantTimers[dstId].stop();
if (!noLock)
m_mutex.unlock();
return true; return true;
} }
if (!noLock)
m_mutex.unlock();
return false; return false;
} }
@ -527,6 +545,8 @@ uint32_t AffiliationLookup::getGrantedSrcId(uint32_t dstId)
void AffiliationLookup::clock(uint32_t ms) void AffiliationLookup::clock(uint32_t ms)
{ {
std::lock_guard<std::mutex> lock(m_mutex);
// clock all the grant timers // clock all the grant timers
std::vector<uint32_t> gntsToRel = std::vector<uint32_t>(); std::vector<uint32_t> gntsToRel = std::vector<uint32_t>();
for (auto entry : m_grantChTable) { for (auto entry : m_grantChTable) {
@ -540,7 +560,7 @@ void AffiliationLookup::clock(uint32_t ms)
// release grants that have timed out // release grants that have timed out
for (uint32_t dstId : gntsToRel) { for (uint32_t dstId : gntsToRel) {
releaseGrant(dstId, false); releaseGrant(dstId, false, true);
} }
if (!m_disableUnitRegTimeout) { if (!m_disableUnitRegTimeout) {

@ -29,6 +29,7 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <mutex>
namespace lookups namespace lookups
{ {
@ -182,9 +183,10 @@ namespace lookups
* @brief Helper to release the channel grant for the destination ID. * @brief Helper to release the channel grant for the destination ID.
* @param dstId Destination Address. * @param dstId Destination Address.
* @param releaseAll Flag indicating all channel grants should be released. * @param releaseAll Flag indicating all channel grants should be released.
* @param noLock Flag indicating no mutex lock operation should be performed while releasing.
* @returns bool True, if channel grant was released, otherwise false. * @returns bool True, if channel grant was released, otherwise false.
*/ */
virtual bool releaseGrant(uint32_t dstId, bool releaseAll); virtual bool releaseGrant(uint32_t dstId, bool releaseAll, bool noLock = false);
/** /**
* @brief Helper to determine if the channel number is busy. * @brief Helper to determine if the channel number is busy.
* @param chNo Channel Number. * @param chNo Channel Number.
@ -298,6 +300,8 @@ namespace lookups
bool m_disableUnitRegTimeout; bool m_disableUnitRegTimeout;
bool m_verbose; bool m_verbose;
static std::mutex m_mutex;
}; };
} // namespace lookups } // namespace lookups

@ -86,12 +86,15 @@ bool DMRAffiliationLookup::grantChSlot(uint32_t dstId, uint32_t srcId, uint8_t s
/* Helper to release the channel grant for the destination ID. */ /* Helper to release the channel grant for the destination ID. */
bool DMRAffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll) bool DMRAffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll, bool noLock)
{ {
if (dstId == 0U && !releaseAll) { if (dstId == 0U && !releaseAll) {
return false; return false;
} }
if (!noLock)
m_mutex.lock();
// are we trying to release all grants? // are we trying to release all grants?
if (dstId == 0U && releaseAll) { if (dstId == 0U && releaseAll) {
LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name.c_str()); LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name.c_str());
@ -107,6 +110,8 @@ bool DMRAffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll)
releaseGrant(dstId, false); releaseGrant(dstId, false);
} }
if (!noLock)
m_mutex.unlock();
return true; return true;
} }
@ -139,9 +144,14 @@ bool DMRAffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll)
} }
m_grantTimers[dstId].stop(); m_grantTimers[dstId].stop();
if (!noLock)
m_mutex.unlock();
return true; return true;
} }
if (!noLock)
m_mutex.unlock();
return false; return false;
} }

@ -76,9 +76,10 @@ namespace dmr
* @brief Helper to release the channel grant for the destination ID. * @brief Helper to release the channel grant for the destination ID.
* @param dstId Destination Address. * @param dstId Destination Address.
* @param releaseAll Flag indicating all channel grants should be released. * @param releaseAll Flag indicating all channel grants should be released.
* @param noLock Flag indicating no mutex lock operation should be performed while releasing.
* @returns bool True, if channel grant was released, otherwise false. * @returns bool True, if channel grant was released, otherwise false.
*/ */
bool releaseGrant(uint32_t dstId, bool releaseAll) override; bool releaseGrant(uint32_t dstId, bool releaseAll, bool noLock = false) override;
/** /**
* @brief Helper to determine if the channel number is busy. * @brief Helper to determine if the channel number is busy.
* @param chNo Channel Number. * @param chNo Channel Number.

@ -46,9 +46,9 @@ std::vector<uint32_t> P25AffiliationLookup::clearGroupAff(uint32_t dstId, bool r
/* Helper to release the channel grant for the destination ID. */ /* Helper to release the channel grant for the destination ID. */
bool P25AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll) bool P25AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll, bool noLock)
{ {
bool ret = ::lookups::AffiliationLookup::releaseGrant(dstId, releaseAll); bool ret = ::lookups::AffiliationLookup::releaseGrant(dstId, releaseAll, noLock);
if (ret) { if (ret) {
if (m_rfGrantChCnt > 0U) { if (m_rfGrantChCnt > 0U) {
m_p25->m_siteData.setChCnt(m_chLookup->rfChSize() + m_rfGrantChCnt); m_p25->m_siteData.setChCnt(m_chLookup->rfChSize() + m_rfGrantChCnt);

@ -72,9 +72,10 @@ namespace p25
* @brief Helper to release the channel grant for the destination ID. * @brief Helper to release the channel grant for the destination ID.
* @param dstId Destination Address. * @param dstId Destination Address.
* @param releaseAll Flag indicating all channel grants should be released. * @param releaseAll Flag indicating all channel grants should be released.
* @param noLock Flag indicating no mutex lock operation should be performed while releasing.
* @returns bool True, if channel grant was released, otherwise false. * @returns bool True, if channel grant was released, otherwise false.
*/ */
bool releaseGrant(uint32_t dstId, bool releaseAll) override; bool releaseGrant(uint32_t dstId, bool releaseAll, bool noLock = false) override;
/** @} */ /** @} */
protected: protected:

Loading…
Cancel
Save

Powered by TurnKey Linux.