mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-05 15:35:01 -04:00
BLOCKING_QUEUE: prepare by raising up max queue lenghts
BLOCKING_QUEUE: Replaced ThreadQueue usage by ThreadBlockingQueue usage BLOCKING_QUEUE: instrument all push() with timeouts, showed some call have to be non-blocking... BLOCKING_QUEUE: tuned push()/try_push()
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "FFTDataDistributor.h"
|
||||
#include <algorithm>
|
||||
#include <ThreadBlockingQueue.h>
|
||||
|
||||
FFTDataDistributor::FFTDataDistributor() : outputBuffers("FFTDataDistributorBuffers"), fftSize(DEFAULT_FFT_SIZE), linesPerSecond(DEFAULT_WATERFALL_LPS), lineRateAccum(0.0) {
|
||||
|
||||
@@ -109,7 +110,8 @@ void FFTDataDistributor::process() {
|
||||
outp->sampleRate = inputBuffer.sampleRate;
|
||||
outp->data.assign(inputBuffer.data.begin()+bufferOffset+i,
|
||||
inputBuffer.data.begin()+bufferOffset+i+ fftSize);
|
||||
distribute(outp);
|
||||
//authorize distribute with losses
|
||||
distribute(outp, NON_BLOCKING_TIMEOUT);
|
||||
|
||||
while (lineRateAccum >= 1.0) {
|
||||
lineRateAccum -= 1.0;
|
||||
|
||||
@@ -53,7 +53,6 @@ void FFTVisualDataThread::run() {
|
||||
//this if fed by FFTDataDistributor which has a buffer of FFT_DISTRIBUTOR_BUFFER_IN_SECONDS
|
||||
//so sleep for << FFT_DISTRIBUTOR_BUFFER_IN_SECONDS not to be overflown
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds((int)(FFT_DISTRIBUTOR_BUFFER_IN_SECONDS * 1000.0 / 25.0)));
|
||||
// std::this_thread::yield();
|
||||
|
||||
int fftSize = wproc.getDesiredInputSize();
|
||||
|
||||
@@ -65,7 +64,6 @@ void FFTVisualDataThread::run() {
|
||||
|
||||
if (lpsChanged.load()) {
|
||||
fftDistrib.setLinesPerSecond(linesPerSecond.load());
|
||||
// pipeIQDataIn->set_max_num_items(linesPerSecond.load());
|
||||
lpsChanged.store(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
double fft_floor, fft_ceil;
|
||||
};
|
||||
|
||||
typedef ThreadQueue<ScopeRenderData *> ScopeRenderDataQueue;
|
||||
typedef ThreadBlockingQueue<ScopeRenderData *> ScopeRenderDataQueue;
|
||||
|
||||
class ScopeVisualProcessor : public VisualProcessor<AudioThreadInput, ScopeRenderData> {
|
||||
public:
|
||||
|
||||
@@ -20,7 +20,7 @@ void SpectrumVisualDataThread::run() {
|
||||
while(!stopping) {
|
||||
//this if fed by FFTDataDistributor which has a buffer of FFT_DISTRIBUTOR_BUFFER_IN_SECONDS
|
||||
//so sleep for << FFT_DISTRIBUTOR_BUFFER_IN_SECONDS not to be overflown
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds((int)(FFT_DISTRIBUTOR_BUFFER_IN_SECONDS * 1000.0 / 25.0)));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds((int)(FFT_DISTRIBUTOR_BUFFER_IN_SECONDS * 1000.0 / 25.0)));
|
||||
|
||||
sproc.run();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
int bandwidth;
|
||||
};
|
||||
|
||||
typedef ThreadQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
|
||||
typedef ThreadBlockingQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
|
||||
|
||||
class SpectrumVisualProcessor : public VisualProcessor<DemodulatorThreadIQData, SpectrumVisualData> {
|
||||
public:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "ThreadQueue.h"
|
||||
#include "ThreadBlockingQueue.h"
|
||||
#include "IOThread.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@@ -12,8 +12,8 @@
|
||||
template<typename InputDataType = ReferenceCounter, typename OutputDataType = ReferenceCounter>
|
||||
class VisualProcessor {
|
||||
//
|
||||
typedef ThreadQueue<InputDataType*> VisualInputQueueType;
|
||||
typedef ThreadQueue<OutputDataType*> VisualOutputQueueType;
|
||||
typedef typename ThreadBlockingQueue<InputDataType*> VisualInputQueueType;
|
||||
typedef typename ThreadBlockingQueue<OutputDataType*> VisualOutputQueueType;
|
||||
typedef typename std::vector< VisualOutputQueueType *>::iterator outputs_i;
|
||||
public:
|
||||
virtual ~VisualProcessor() {
|
||||
@@ -94,7 +94,9 @@ protected:
|
||||
//To be used by derived classes implementing
|
||||
//process() : will dispatch 'item' into as many
|
||||
//available outputs, previously set by attachOutput().
|
||||
void distribute(OutputDataType *item) {
|
||||
//* \param[in] timeout The number of microseconds to wait to push an item in each one of the outputs, 0(default) means indefinite wait.
|
||||
//* \param[in] errorMessage an error message written on std::cout in case pf push timeout.
|
||||
void distribute(OutputDataType *item, std::uint64_t timeout = BLOCKING_INFINITE_TIMEOUT, const char* errorMessage = "") {
|
||||
|
||||
std::lock_guard < std::recursive_mutex > busy_lock(busy_update);
|
||||
//We will try to distribute 'output' among all 'outputs',
|
||||
@@ -103,11 +105,11 @@ protected:
|
||||
item->setRefCount((int)outputs.size());
|
||||
for (outputs_i it = outputs.begin(); it != outputs.end(); it++) {
|
||||
//if 'output' failed to be given to an outputs_i, dec its ref count accordingly.
|
||||
if (!(*it)->push(item)) {
|
||||
//blocking push, with a timeout
|
||||
if (!(*it)->push(item, timeout, errorMessage)) {
|
||||
item->decRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
// Now 'item' refcount matches the times 'item' has been successfully distributed,
|
||||
//i.e shared among the outputs.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user