mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-05-02 06:14:01 -04:00
Threading crash fixes, reusable IQ buffer queue
This commit is contained in:
parent
ef78ffc6f3
commit
b7375ce09f
@ -5,6 +5,7 @@
|
|||||||
#include "liquid/liquid.h"
|
#include "liquid/liquid.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
enum DemodulatorType {
|
enum DemodulatorType {
|
||||||
DEMOD_TYPE_NULL,
|
DEMOD_TYPE_NULL,
|
||||||
@ -60,6 +61,7 @@ public:
|
|||||||
unsigned int frequency;
|
unsigned int frequency;
|
||||||
unsigned int bandwidth;
|
unsigned int bandwidth;
|
||||||
std::vector<signed char> data;
|
std::vector<signed char> data;
|
||||||
|
mutable std::mutex m_mutex;
|
||||||
|
|
||||||
DemodulatorThreadIQData() :
|
DemodulatorThreadIQData() :
|
||||||
frequency(0), bandwidth(0), refCount(0) {
|
frequency(0), bandwidth(0), refCount(0) {
|
||||||
|
|||||||
@ -157,6 +157,7 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||||
std::vector<signed char> *data = &inp->data;
|
std::vector<signed char> *data = &inp->data;
|
||||||
if (data->size()) {
|
if (data->size()) {
|
||||||
int bufSize = data->size() / 2;
|
int bufSize = data->size() / 2;
|
||||||
@ -173,6 +174,8 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
in_buf[i].imag = (float) (*data)[i * 2 + 1] / 127.0f;
|
in_buf[i].imag = (float) (*data)[i * 2 + 1] / 127.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inp->decRefCount();
|
||||||
|
|
||||||
if (shift_freq != 0) {
|
if (shift_freq != 0) {
|
||||||
if (shift_freq < 0) {
|
if (shift_freq < 0) {
|
||||||
nco_crcf_mix_block_up(nco_shift, in_buf, out_buf, bufSize);
|
nco_crcf_mix_block_up(nco_shift, in_buf, out_buf, bufSize);
|
||||||
@ -195,10 +198,8 @@ void DemodulatorPreThread::threadMain() {
|
|||||||
resamp->resampler = resampler;
|
resamp->resampler = resampler;
|
||||||
|
|
||||||
postInputQueue->push(resamp);
|
postInputQueue->push(resamp);
|
||||||
|
} else {
|
||||||
inp->decRefCount();
|
inp->decRefCount();
|
||||||
if (inp->getRefCount()<=0) {
|
|
||||||
delete inp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!workerResults->empty()) {
|
if (!workerResults->empty()) {
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
#include "SDRPostThread.h"
|
#include "SDRPostThread.h"
|
||||||
#include "CubicSDRDefs.h"
|
#include "CubicSDRDefs.h"
|
||||||
#include <vector>
|
|
||||||
#include "CubicSDR.h"
|
#include "CubicSDR.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
SDRPostThread::SDRPostThread() :
|
SDRPostThread::SDRPostThread() :
|
||||||
sample_rate(SRATE), iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL) {
|
sample_rate(SRATE), iqDataOutQueue(NULL), iqDataInQueue(NULL), iqVisualQueue(NULL), terminated(false), dcFilter(NULL) {
|
||||||
}
|
}
|
||||||
@ -49,6 +51,9 @@ void SDRPostThread::threadMain() {
|
|||||||
|
|
||||||
std::cout << "SDR post-processing thread started.." << std::endl;
|
std::cout << "SDR post-processing thread started.." << std::endl;
|
||||||
|
|
||||||
|
std::deque<DemodulatorThreadIQData *> buffers;
|
||||||
|
std::deque<DemodulatorThreadIQData *>::iterator buffers_i;
|
||||||
|
|
||||||
while (!terminated) {
|
while (!terminated) {
|
||||||
SDRThreadIQData *data_in;
|
SDRThreadIQData *data_in;
|
||||||
|
|
||||||
@ -117,7 +122,22 @@ void SDRPostThread::threadMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (demodulators.size()) {
|
if (demodulators.size()) {
|
||||||
DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
|
|
||||||
|
DemodulatorThreadIQData *demodDataOut = NULL;
|
||||||
|
|
||||||
|
for (buffers_i = buffers.begin(); buffers_i != buffers.end(); buffers_i++) {
|
||||||
|
if ((*buffers_i)->getRefCount() <= 0) {
|
||||||
|
demodDataOut = (*buffers_i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (demodDataOut == NULL) {
|
||||||
|
demodDataOut = new DemodulatorThreadIQData;
|
||||||
|
buffers.push_back(demodDataOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard < std::mutex > lock(demodDataOut->m_mutex);
|
||||||
demodDataOut->frequency = data_in->frequency;
|
demodDataOut->frequency = data_in->frequency;
|
||||||
demodDataOut->bandwidth = data_in->bandwidth;
|
demodDataOut->bandwidth = data_in->bandwidth;
|
||||||
demodDataOut->setRefCount(activeDemods);
|
demodDataOut->setRefCount(activeDemods);
|
||||||
@ -150,7 +170,7 @@ void SDRPostThread::threadMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!pushedData) {
|
if (!pushedData) {
|
||||||
delete demodDataOut;
|
demodDataOut->setRefCount(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,6 +180,14 @@ void SDRPostThread::threadMain() {
|
|||||||
delete data_in;
|
delete data_in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!buffers.empty()) {
|
||||||
|
DemodulatorThreadIQData *demodDataDel = buffers.front();
|
||||||
|
buffers.pop_front();
|
||||||
|
std::lock_guard < std::mutex > lock(demodDataDel->m_mutex);
|
||||||
|
delete demodDataDel;
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "SDR post-processing thread done." << std::endl;
|
std::cout << "SDR post-processing thread done." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user