add some mutex locking for thread safety, ensure addFrame and getFrame cannot happen simultaneously;

pull/69/head
Bryan Biedenkapp 2 years ago
parent 6ddec3c641
commit 14b880b708

@ -98,6 +98,7 @@ Slot::Slot(uint32_t slotNo, uint32_t timeout, uint32_t tgHang, uint32_t queueSiz
m_slotNo(slotNo),
m_txImmQueue(queueSize, "DMR Imm Slot Frame"),
m_txQueue(queueSize, "DMR Slot Frame"),
m_queueLock(),
m_rfState(RS_RF_LISTENING),
m_rfLastDstId(0U),
m_rfLastSrcId(0U),
@ -333,6 +334,8 @@ uint32_t Slot::getFrame(uint8_t* data)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (m_txQueue.isEmpty() && m_txImmQueue.isEmpty())
return 0U;
@ -987,6 +990,8 @@ void Slot::addFrame(const uint8_t *data, bool net, bool imm)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (!net) {
if (m_netState != RS_NET_IDLE)
return;

@ -35,6 +35,7 @@
#include "network/Network.h"
#include <vector>
#include <mutex>
namespace dmr
{
@ -307,6 +308,7 @@ namespace dmr
RingBuffer<uint8_t> m_txImmQueue;
RingBuffer<uint8_t> m_txQueue;
std::mutex m_queueLock;
RPT_RF_STATE m_rfState;
uint32_t m_rfLastDstId;

@ -42,6 +42,11 @@ const uint8_t SCRAMBLER[] = {
0x28U, 0x28U, 0x00U, 0x0AU, 0x02U, 0x82U, 0x20U, 0x28U, 0x82U, 0x2AU, 0xAAU, 0x20U, 0x22U, 0x80U,
0xA8U, 0x8AU, 0x08U, 0xA0U, 0xAAU, 0x02U };
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std::mutex Control::m_queueLock;
// ---------------------------------------------------------------------------
// Public Class Members
@ -482,6 +487,8 @@ uint32_t Control::getFrame(uint8_t* data)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (m_txQueue.isEmpty() && m_txImmQueue.isEmpty())
return 0U;
@ -825,6 +832,8 @@ void Control::addFrame(const uint8_t *data, bool net, bool imm)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (!net) {
if (m_rfTimeout.isRunning() && m_rfTimeout.hasExpired())
return;

@ -43,6 +43,7 @@
#include <cstdio>
#include <string>
#include <mutex>
namespace nxdn
{
@ -289,6 +290,7 @@ namespace nxdn
RingBuffer<uint8_t> m_txImmQueue;
RingBuffer<uint8_t> m_txQueue;
static std::mutex m_queueLock;
RPT_RF_STATE m_rfState;
uint32_t m_rfLastDstId;

@ -37,6 +37,12 @@ const uint8_t MAX_SYNC_BYTES_ERRS = 4U;
const uint32_t TSBK_PCH_CCH_CNT = 6U;
const uint32_t MAX_PREAMBLE_TDU_CNT = 64U;
// ---------------------------------------------------------------------------
// Static Class Members
// ---------------------------------------------------------------------------
std::mutex Control::m_queueLock;
// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------
@ -695,6 +701,8 @@ uint32_t Control::getFrame(uint8_t* data)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (m_txQueue.isEmpty() && m_txImmQueue.isEmpty())
return 0U;
@ -1133,6 +1141,8 @@ void Control::addFrame(const uint8_t* data, uint32_t length, bool net, bool imm)
{
assert(data != nullptr);
std::lock_guard<std::mutex> lock(m_queueLock);
if (!net) {
if (m_rfTimeout.isRunning() && m_rfTimeout.hasExpired())
return;

@ -47,6 +47,7 @@
#include <vector>
#include <unordered_map>
#include <random>
#include <mutex>
namespace p25
{
@ -312,6 +313,7 @@ namespace p25
RingBuffer<uint8_t> m_txImmQueue;
RingBuffer<uint8_t> m_txQueue;
static std::mutex m_queueLock;
RPT_RF_STATE m_rfState;
uint32_t m_rfLastDstId;

Loading…
Cancel
Save

Powered by TurnKey Linux.