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:
vsonnier
2017-02-09 19:12:12 +01:00
parent e173eec3ef
commit c7467a88bc
22 changed files with 354 additions and 107 deletions
+3 -1
View File
@@ -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;
-2
View File
@@ -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);
}
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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();
}
+1 -1
View File
@@ -19,7 +19,7 @@ public:
int bandwidth;
};
typedef ThreadQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
typedef ThreadBlockingQueue<SpectrumVisualData *> SpectrumVisualDataQueue;
class SpectrumVisualProcessor : public VisualProcessor<DemodulatorThreadIQData, SpectrumVisualData> {
public:
+8 -6
View File
@@ -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.
}