Skip to content

Commit b86a5ce

Browse files
committed
add some mutex locking around modification of the channel lookup table;
1 parent 3da4eb2 commit b86a5ce

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/common/lookups/ChannelLookup.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
* GPLv2 Open Source. Use is subject to license terms.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*
7-
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
7+
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
88
*
99
*/
1010
#include "lookups/ChannelLookup.h"
1111
#include "Log.h"
1212

1313
using namespace lookups;
1414

15+
// ---------------------------------------------------------------------------
16+
// Static Class Members
17+
// ---------------------------------------------------------------------------
18+
19+
std::mutex ChannelLookup::m_mutex;
20+
1521
// ---------------------------------------------------------------------------
1622
// Public Class Members
1723
// ---------------------------------------------------------------------------
@@ -51,6 +57,7 @@ VoiceChData ChannelLookup::getRFChData(uint32_t chNo) const
5157

5258
bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
5359
{
60+
std::lock_guard<std::mutex> lock(m_mutex);
5461
if (chNo == 0U) {
5562
return false;
5663
}
@@ -73,16 +80,16 @@ bool ChannelLookup::addRFCh(uint32_t chNo, bool force)
7380

7481
bool ChannelLookup::removeRFCh(uint32_t chNo)
7582
{
83+
std::lock_guard<std::mutex> lock(m_mutex);
7684
if (chNo == 0U) {
7785
return false;
7886
}
7987

80-
try {
81-
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
88+
auto it = std::find(m_rfChTable.begin(), m_rfChTable.end(), chNo);
89+
if (it != m_rfChTable.end()) {
8290
m_rfChTable.erase(it);
83-
} catch (...) {
84-
return false;
91+
return true;
8592
}
8693

87-
return true;
94+
return false;
8895
}

src/common/lookups/ChannelLookup.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @package DVM / Common Library
88
* @license GPLv2 License (https://opensource.org/licenses/GPL-2.0)
99
*
10-
* Copyright (C) 2024 Bryan Biedenkapp, N2PLL
10+
* Copyright (C) 2024-2025 Bryan Biedenkapp, N2PLL
1111
*
1212
*/
1313
/**
@@ -31,6 +31,7 @@
3131
#include <algorithm>
3232
#include <vector>
3333
#include <functional>
34+
#include <mutex>
3435

3536
namespace lookups
3637
{
@@ -219,6 +220,8 @@ namespace lookups
219220
private:
220221
std::vector<uint32_t> m_rfChTable;
221222
std::unordered_map<uint32_t, VoiceChData> m_rfChDataTable;
223+
224+
static std::mutex m_mutex;
222225
};
223226
} // namespace lookups
224227

0 commit comments

Comments
 (0)