mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2026-06-08 00:44:56 -04:00
Unsafe vector demod queues replaced /w mutex lock
This commit is contained in:
+14
-21
@@ -27,7 +27,9 @@ SDRPostThread::~SDRPostThread() {
|
||||
}
|
||||
|
||||
void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
|
||||
demodulators_add.push_back(demod);
|
||||
busy_demod.lock();
|
||||
demodulators.push_back(demod);
|
||||
busy_demod.unlock();
|
||||
}
|
||||
|
||||
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||
@@ -35,7 +37,13 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||
return;
|
||||
}
|
||||
|
||||
demodulators_remove.push_back(demod);
|
||||
busy_demod.lock();
|
||||
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
|
||||
|
||||
if (i != demodulators.end()) {
|
||||
demodulators.erase(i);
|
||||
}
|
||||
busy_demod.unlock();
|
||||
}
|
||||
|
||||
void SDRPostThread::setIQDataInQueue(SDRThreadIQDataQueue* iqDataQueue) {
|
||||
@@ -129,25 +137,8 @@ void SDRPostThread::threadMain() {
|
||||
|
||||
iqVisualQueue.load()->push(visualDataOut);
|
||||
}
|
||||
|
||||
if (demodulators_add.size()) {
|
||||
while (!demodulators_add.empty()) {
|
||||
demodulators.push_back(demodulators_add.back());
|
||||
demodulators_add.pop_back();
|
||||
}
|
||||
}
|
||||
if (demodulators_remove.size()) {
|
||||
while (!demodulators_remove.empty()) {
|
||||
DemodulatorInstance *demod = demodulators_remove.back();
|
||||
demodulators_remove.pop_back();
|
||||
|
||||
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
|
||||
|
||||
if (i != demodulators.end()) {
|
||||
demodulators.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
busy_demod.lock();
|
||||
|
||||
int activeDemods = 0;
|
||||
bool pushedData = false;
|
||||
@@ -226,6 +217,8 @@ void SDRPostThread::threadMain() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
busy_demod.unlock();
|
||||
}
|
||||
data_in->decRefCount();
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ protected:
|
||||
std::atomic<SDRThreadIQDataQueue *> iqDataInQueue;
|
||||
std::atomic<DemodulatorThreadInputQueue *> iqDataOutQueue;
|
||||
std::atomic<DemodulatorThreadInputQueue *> iqVisualQueue;
|
||||
|
||||
|
||||
std::mutex busy_demod;
|
||||
std::vector<DemodulatorInstance *> demodulators;
|
||||
std::vector<DemodulatorInstance *> demodulators_add;
|
||||
std::vector<DemodulatorInstance *> demodulators_remove;
|
||||
std::atomic<bool> terminated;
|
||||
iirfilt_crcf dcFilter;
|
||||
int num_vis_samples;
|
||||
|
||||
Reference in New Issue
Block a user