diff --git a/src/common/lookups/ChannelLookup.cpp b/src/common/lookups/ChannelLookup.cpp index f803702a..2845c1d0 100644 --- a/src/common/lookups/ChannelLookup.cpp +++ b/src/common/lookups/ChannelLookup.cpp @@ -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 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 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; } diff --git a/src/common/lookups/ChannelLookup.h b/src/common/lookups/ChannelLookup.h index 06fe8a78..b9207061 100644 --- a/src/common/lookups/ChannelLookup.h +++ b/src/common/lookups/ChannelLookup.h @@ -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 #include #include +#include namespace lookups { @@ -219,6 +220,8 @@ namespace lookups private: std::vector m_rfChTable; std::unordered_map m_rfChDataTable; + + static std::mutex m_mutex; }; } // namespace lookups