mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-02-03 09:44:26 -05:00
Unsafe vector demod queues replaced /w mutex lock
This commit is contained in:
parent
0237c563a0
commit
3efb036099
@ -109,6 +109,8 @@ bool CubicSDR::OnInit() {
|
||||
}
|
||||
|
||||
int CubicSDR::OnExit() {
|
||||
demodMgr.terminateAll();
|
||||
|
||||
std::cout << "Terminating SDR thread.." << std::endl;
|
||||
sdrThread->terminate();
|
||||
t_SDR->join();
|
||||
@ -123,8 +125,6 @@ int CubicSDR::OnExit() {
|
||||
delete sdrPostThread;
|
||||
delete t_PostSDR;
|
||||
|
||||
demodMgr.terminateAll();
|
||||
|
||||
delete threadCmdQueueSDR;
|
||||
|
||||
delete iqVisualQueue;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user