From b07277a5e2b27f2a2ff8ee650f16d8fffac41fb8 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 28 Aug 2018 14:04:30 +0200 Subject: [PATCH] SDRdaemon: manage data read queue full --- sdrdaemon/channel/sdrdaemondatareadqueue.cpp | 16 ++++++++++++---- sdrdaemon/channel/sdrdaemondatareadqueue.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sdrdaemon/channel/sdrdaemondatareadqueue.cpp b/sdrdaemon/channel/sdrdaemondatareadqueue.cpp index 7cc76b227..7081ee569 100644 --- a/sdrdaemon/channel/sdrdaemondatareadqueue.cpp +++ b/sdrdaemon/channel/sdrdaemondatareadqueue.cpp @@ -28,7 +28,8 @@ const uint32_t SDRDaemonDataReadQueue::MaxSize = 20; SDRDaemonDataReadQueue::SDRDaemonDataReadQueue() : m_dataBlock(0), m_blockIndex(1), - m_sampleIndex(0) + m_sampleIndex(0), + m_full(false) {} SDRDaemonDataReadQueue::~SDRDaemonDataReadQueue() @@ -44,14 +45,21 @@ SDRDaemonDataReadQueue::~SDRDaemonDataReadQueue() void SDRDaemonDataReadQueue::push(SDRDaemonDataBlock* dataBlock) { - if (size() > MaxSize) + if (size() >= MaxSize) { qWarning("SDRDaemonDataReadQueue::push: queue is full"); + m_full = true; // stop filling the queue SDRDaemonDataBlock *data = m_dataReadQueue.takeLast(); delete data; } - m_dataReadQueue.append(dataBlock); + if (m_full) { + m_full = (size() > MaxSize/2); // do not fill queue again before queue is half size + } + + if (!m_full) { + m_dataReadQueue.append(dataBlock); + } } SDRDaemonDataBlock* SDRDaemonDataReadQueue::pop() @@ -76,7 +84,7 @@ uint32_t SDRDaemonDataReadQueue::size() void SDRDaemonDataReadQueue::readSample(Sample& s) { - // initial state + // depletion/repletion state if (m_dataBlock == 0) { if (size() >= MaxSize/2) diff --git a/sdrdaemon/channel/sdrdaemondatareadqueue.h b/sdrdaemon/channel/sdrdaemondatareadqueue.h index 19c0687b1..7caa3e5e6 100644 --- a/sdrdaemon/channel/sdrdaemondatareadqueue.h +++ b/sdrdaemon/channel/sdrdaemondatareadqueue.h @@ -46,6 +46,7 @@ private: SDRDaemonDataBlock *m_dataBlock; uint32_t m_blockIndex; uint32_t m_sampleIndex; + bool m_full; //!< full condition was hit };