add some mutex locking around modification of the channel lookup table;

pull/85/head
Bryan Biedenkapp 11 months ago
parent 3da4eb2d40
commit b86a5ce939

@ -4,7 +4,7 @@
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
#include "lookups/ChannelLookup.h"
@ -12,6 +12,12 @@
using namespace lookups;
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std::mutex ChannelLookup::m_mutex;
// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------
@ -51,6 +57,7 @@ VoiceChData ChannelLookup::getRFChData(uint32_t chNo) const
bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (chNo == 0U) {
return false;
}
@ -73,16 +80,16 @@ bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
bool ChannelLookup::removeRFCh(uint32_t chNo)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (chNo == 0U) {
return false;
}
try {
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
if (it != m_rfChTable.end()) {
m_rfChTable.erase(it);
} catch (...) {
return false;
return true;
}
return true;
return false;
}

@ -7,7 +7,7 @@
* @package DVM / Common Library
* @license GPLv2 License (https://opensource.org/licenses/GPL-2.0)
*
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
*
*/
/**
@ -31,6 +31,7 @@
#include <algorithm>
#include <vector>
#include <functional>
#include <mutex>
namespace lookups
{
@ -219,6 +220,8 @@ namespace lookups
private:
std::vector<uint32_t> m_rfChTable;
std::unordered_map<uint32_t, VoiceChData> m_rfChDataTable;
static std::mutex m_mutex;
};
} // namespace lookups

Loading…
Cancel
Save

Powered by TurnKey Linux.