mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-29 23:28:39 -05:00
No Spin-lock for xxxProcessor, unclear what the gain was
This commit is contained in:
parent
8dfc7503f2
commit
8dbd5de53d
@ -49,21 +49,21 @@ SpectrumVisualProcessor::~SpectrumVisualProcessor() {
|
|||||||
|
|
||||||
bool SpectrumVisualProcessor::isView() {
|
bool SpectrumVisualProcessor::isView() {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return is_view;
|
return is_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setView(bool bView) {
|
void SpectrumVisualProcessor::setView(bool bView) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
is_view = bView;
|
is_view = bView;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setView(bool bView, long long centerFreq_in, long bandwidth_in) {
|
void SpectrumVisualProcessor::setView(bool bView, long long centerFreq_in, long bandwidth_in) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
is_view = bView;
|
is_view = bView;
|
||||||
bandwidth = bandwidth_in;
|
bandwidth = bandwidth_in;
|
||||||
centerFreq = centerFreq_in;
|
centerFreq = centerFreq_in;
|
||||||
@ -72,49 +72,49 @@ void SpectrumVisualProcessor::setView(bool bView, long long centerFreq_in, long
|
|||||||
|
|
||||||
void SpectrumVisualProcessor::setFFTAverageRate(float fftAverageRate) {
|
void SpectrumVisualProcessor::setFFTAverageRate(float fftAverageRate) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
this->fft_average_rate = fftAverageRate;
|
this->fft_average_rate = fftAverageRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
float SpectrumVisualProcessor::getFFTAverageRate() {
|
float SpectrumVisualProcessor::getFFTAverageRate() {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return this->fft_average_rate;
|
return this->fft_average_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) {
|
void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
centerFreq = centerFreq_in;
|
centerFreq = centerFreq_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long SpectrumVisualProcessor::getCenterFrequency() {
|
long long SpectrumVisualProcessor::getCenterFrequency() {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return centerFreq;
|
return centerFreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setBandwidth(long bandwidth_in) {
|
void SpectrumVisualProcessor::setBandwidth(long bandwidth_in) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
bandwidth = bandwidth_in;
|
bandwidth = bandwidth_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
long SpectrumVisualProcessor::getBandwidth() {
|
long SpectrumVisualProcessor::getBandwidth() {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return bandwidth;
|
return bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setPeakHold(bool peakHold_in) {
|
void SpectrumVisualProcessor::setPeakHold(bool peakHold_in) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
if (peakHold && peakHold_in) {
|
if (peakHold && peakHold_in) {
|
||||||
peakReset = PEAK_RESET_COUNT;
|
peakReset = PEAK_RESET_COUNT;
|
||||||
@ -126,20 +126,20 @@ void SpectrumVisualProcessor::setPeakHold(bool peakHold_in) {
|
|||||||
|
|
||||||
bool SpectrumVisualProcessor::getPeakHold() {
|
bool SpectrumVisualProcessor::getPeakHold() {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return peakHold;
|
return peakHold;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpectrumVisualProcessor::getDesiredInputSize() {
|
int SpectrumVisualProcessor::getDesiredInputSize() {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
return desiredInputSize;
|
return desiredInputSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setup(unsigned int fftSize_in) {
|
void SpectrumVisualProcessor::setup(unsigned int fftSize_in) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
fftSize = fftSize_in;
|
fftSize = fftSize_in;
|
||||||
fftSizeInternal = fftSize_in * SPECTRUM_VZM;
|
fftSizeInternal = fftSize_in * SPECTRUM_VZM;
|
||||||
@ -180,7 +180,7 @@ void SpectrumVisualProcessor::setup(unsigned int fftSize_in) {
|
|||||||
void SpectrumVisualProcessor::setFFTSize(unsigned int fftSize_in) {
|
void SpectrumVisualProcessor::setFFTSize(unsigned int fftSize_in) {
|
||||||
|
|
||||||
//then get the busy_lock
|
//then get the busy_lock
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
if (fftSize_in == fftSize) {
|
if (fftSize_in == fftSize) {
|
||||||
return;
|
return;
|
||||||
@ -192,7 +192,7 @@ void SpectrumVisualProcessor::setFFTSize(unsigned int fftSize_in) {
|
|||||||
unsigned int SpectrumVisualProcessor::getFFTSize() {
|
unsigned int SpectrumVisualProcessor::getFFTSize() {
|
||||||
|
|
||||||
//then get the busy_lock
|
//then get the busy_lock
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
if (fftSizeChanged) {
|
if (fftSizeChanged) {
|
||||||
return newFFTSize;
|
return newFFTSize;
|
||||||
@ -203,7 +203,7 @@ unsigned int SpectrumVisualProcessor::getFFTSize() {
|
|||||||
|
|
||||||
void SpectrumVisualProcessor::setHideDC(bool hideDC) {
|
void SpectrumVisualProcessor::setHideDC(bool hideDC) {
|
||||||
|
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
this->hideDC = hideDC;
|
this->hideDC = hideDC;
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ void SpectrumVisualProcessor::process() {
|
|||||||
bool executeSetup = false;
|
bool executeSetup = false;
|
||||||
|
|
||||||
{ // scoped lock here
|
{ // scoped lock here
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
if (fftSizeChanged) {
|
if (fftSizeChanged) {
|
||||||
executeSetup = true;
|
executeSetup = true;
|
||||||
fftSizeChanged = false;
|
fftSizeChanged = false;
|
||||||
@ -242,7 +242,7 @@ void SpectrumVisualProcessor::process() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//then get the busy_lock for the rest of the processing.
|
//then get the busy_lock for the rest of the processing.
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
bool doPeak = peakHold && (peakReset == 0);
|
bool doPeak = peakHold && (peakReset == 0);
|
||||||
|
|
||||||
@ -638,14 +638,14 @@ void SpectrumVisualProcessor::process() {
|
|||||||
|
|
||||||
|
|
||||||
void SpectrumVisualProcessor::setScaleFactor(float sf) {
|
void SpectrumVisualProcessor::setScaleFactor(float sf) {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
|
|
||||||
scaleFactor = sf;
|
scaleFactor = sf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float SpectrumVisualProcessor::getScaleFactor() {
|
float SpectrumVisualProcessor::getScaleFactor() {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_run);
|
std::lock_guard < std::mutex > busy_lock(busy_run);
|
||||||
return scaleFactor;
|
return scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "DemodDefs.h"
|
#include "DemodDefs.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "SpinMutex.h"
|
|
||||||
|
|
||||||
#define SPECTRUM_VZM 2
|
#define SPECTRUM_VZM 2
|
||||||
#define PEAK_RESET_COUNT 30
|
#define PEAK_RESET_COUNT 30
|
||||||
@ -66,7 +65,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//protects all access to fields below
|
//protects all access to fields below
|
||||||
SpinMutex busy_run;
|
std::mutex busy_run;
|
||||||
|
|
||||||
bool is_view;
|
bool is_view;
|
||||||
size_t fftSize, newFFTSize;
|
size_t fftSize, newFFTSize;
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include "SpinMutex.h"
|
|
||||||
|
|
||||||
template<typename InputDataType, typename OutputDataType>
|
template<typename InputDataType, typename OutputDataType>
|
||||||
class VisualProcessor {
|
class VisualProcessor {
|
||||||
@ -29,7 +28,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isInputEmpty() {
|
bool isInputEmpty() {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
return input->empty();
|
return input->empty();
|
||||||
@ -39,7 +38,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isOutputEmpty() {
|
bool isOutputEmpty() {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
|
|
||||||
for (VisualOutputQueueTypePtr single_output : outputs) {
|
for (VisualOutputQueueTypePtr single_output : outputs) {
|
||||||
if (single_output->full()) {
|
if (single_output->full()) {
|
||||||
@ -50,7 +49,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isAnyOutputEmpty() {
|
bool isAnyOutputEmpty() {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
|
|
||||||
for (VisualOutputQueueTypePtr single_output : outputs) {
|
for (VisualOutputQueueTypePtr single_output : outputs) {
|
||||||
if (!(single_output)->full()) {
|
if (!(single_output)->full()) {
|
||||||
@ -62,7 +61,7 @@ public:
|
|||||||
|
|
||||||
//Set a (new) 'input' queue for incoming data.
|
//Set a (new) 'input' queue for incoming data.
|
||||||
void setInput(VisualInputQueueTypePtr vis_in) {
|
void setInput(VisualInputQueueTypePtr vis_in) {
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
input = vis_in;
|
input = vis_in;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -71,14 +70,14 @@ public:
|
|||||||
//dispatched by distribute().
|
//dispatched by distribute().
|
||||||
void attachOutput(VisualOutputQueueTypePtr vis_out) {
|
void attachOutput(VisualOutputQueueTypePtr vis_out) {
|
||||||
// attach an output queue
|
// attach an output queue
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
outputs.push_back(vis_out);
|
outputs.push_back(vis_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
//reverse of attachOutput(), removed an existing attached vis_out.
|
//reverse of attachOutput(), removed an existing attached vis_out.
|
||||||
void removeOutput(VisualOutputQueueTypePtr vis_out) {
|
void removeOutput(VisualOutputQueueTypePtr vis_out) {
|
||||||
// remove an output queue
|
// remove an output queue
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
|
|
||||||
auto it = std::find(outputs.begin(), outputs.end(), vis_out);
|
auto it = std::find(outputs.begin(), outputs.end(), vis_out);
|
||||||
if (it != outputs.end()) {
|
if (it != outputs.end()) {
|
||||||
@ -99,7 +98,7 @@ public:
|
|||||||
//scoped-lock: create a local copy of outputs, and work with it.
|
//scoped-lock: create a local copy of outputs, and work with it.
|
||||||
std::vector<VisualOutputQueueTypePtr> local_outputs;
|
std::vector<VisualOutputQueueTypePtr> local_outputs;
|
||||||
{
|
{
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
local_outputs = outputs;
|
local_outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,17 +132,11 @@ protected:
|
|||||||
//* \param[in] errorMessage an error message written on std::cout in case pf push timeout.
|
//* \param[in] errorMessage an error message written on std::cout in case pf push timeout.
|
||||||
void distribute(OutputDataTypePtr item, std::uint64_t timeout = BLOCKING_INFINITE_TIMEOUT, const char* errorMessage = nullptr) {
|
void distribute(OutputDataTypePtr item, std::uint64_t timeout = BLOCKING_INFINITE_TIMEOUT, const char* errorMessage = nullptr) {
|
||||||
|
|
||||||
//scoped-lock: create a local copy of outputs, and work with it.
|
std::lock_guard < std::mutex > busy_lock(busy_update);
|
||||||
std::vector<VisualOutputQueueTypePtr> local_outputs;
|
//We will try to distribute 'output' among all 'outputs',
|
||||||
{
|
//so 'output' will a-priori be shared among all 'outputs'.
|
||||||
std::lock_guard < SpinMutex > busy_lock(busy_update);
|
|
||||||
local_outputs = outputs;
|
|
||||||
}
|
|
||||||
|
|
||||||
//We will try to distribute 'output' among all 'local_outputs',
|
for (VisualOutputQueueTypePtr single_output : outputs) {
|
||||||
//so 'output' will a-priori be shared among all 'local_outputs'.
|
|
||||||
|
|
||||||
for (VisualOutputQueueTypePtr single_output : local_outputs) {
|
|
||||||
//'output' can fail to be given to an single_output,
|
//'output' can fail to be given to an single_output,
|
||||||
//using a blocking push, with a timeout
|
//using a blocking push, with a timeout
|
||||||
if (!(single_output)->push(item, timeout, errorMessage)) {
|
if (!(single_output)->push(item, timeout, errorMessage)) {
|
||||||
@ -159,7 +152,7 @@ protected:
|
|||||||
std::vector<VisualOutputQueueTypePtr> outputs;
|
std::vector<VisualOutputQueueTypePtr> outputs;
|
||||||
|
|
||||||
//protects input and outputs
|
//protects input and outputs
|
||||||
SpinMutex busy_update;
|
std::mutex busy_update;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Specialization much like VisualDataReDistributor, except
|
//Specialization much like VisualDataReDistributor, except
|
||||||
|
Loading…
Reference in New Issue
Block a user