mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-07 23:57:50 -04:00
mutex locking cleanup for demod add / remove chain
This commit is contained in:
parent
6d63d570aa
commit
423c83f500
@ -31,9 +31,7 @@ DemodulatorMgr::~DemodulatorMgr() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::newThread() {
|
DemodulatorInstance *DemodulatorMgr::newThread() {
|
||||||
garbageCollect();
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
|
|
||||||
demods_busy.lock();
|
|
||||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||||
|
|
||||||
std::stringstream label;
|
std::stringstream label;
|
||||||
@ -41,25 +39,22 @@ DemodulatorInstance *DemodulatorMgr::newThread() {
|
|||||||
newDemod->setLabel(label.str());
|
newDemod->setLabel(label.str());
|
||||||
|
|
||||||
demods.push_back(newDemod);
|
demods.push_back(newDemod);
|
||||||
demods_busy.unlock();
|
|
||||||
|
|
||||||
return newDemod;
|
return newDemod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::terminateAll() {
|
void DemodulatorMgr::terminateAll() {
|
||||||
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
while (demods.size()) {
|
while (demods.size()) {
|
||||||
demods_busy.lock();
|
|
||||||
DemodulatorInstance *d = demods.back();
|
DemodulatorInstance *d = demods.back();
|
||||||
demods.pop_back();
|
demods.pop_back();
|
||||||
demods_busy.unlock();
|
|
||||||
wxGetApp().removeDemodulator(d);
|
wxGetApp().removeDemodulator(d);
|
||||||
deleteThread(d);
|
deleteThread(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||||
demods_busy.lock();
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
demods_busy.unlock();
|
|
||||||
return demods;
|
return demods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +122,6 @@ DemodulatorInstance *DemodulatorMgr::getFirstDemodulator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
||||||
demods_busy.lock();
|
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
i = std::find(demods.begin(), demods.end(), demod);
|
i = std::find(demods.begin(), demods.end(), demod);
|
||||||
@ -149,14 +142,10 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
|||||||
demod->terminate();
|
demod->terminate();
|
||||||
|
|
||||||
demods_deleted.push_back(demod);
|
demods_deleted.push_back(demod);
|
||||||
|
|
||||||
demods_busy.unlock();
|
|
||||||
|
|
||||||
garbageCollect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
|
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
|
||||||
demods_busy.lock();
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||||
|
|
||||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
@ -172,13 +161,12 @@ std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long
|
|||||||
foundDemods->push_back(testDemod);
|
foundDemods->push_back(testDemod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
demods_busy.unlock();
|
|
||||||
|
|
||||||
return foundDemods;
|
return foundDemods;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
||||||
demods_busy.lock();
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
DemodulatorInstance *testDemod = demods[i];
|
DemodulatorInstance *testDemod = demods[i];
|
||||||
|
|
||||||
@ -189,12 +177,10 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
|||||||
long long halfBuffer = bandwidth / 2;
|
long long halfBuffer = bandwidth / 2;
|
||||||
|
|
||||||
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
|
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
|
||||||
demods_busy.unlock();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
demods_busy.unlock();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +199,8 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
|
|||||||
wxGetApp().getRigThread()->setFrequency(lastActiveDemodulator->getFrequency(),true);
|
wxGetApp().getRigThread()->setFrequency(lastActiveDemodulator->getFrequency(),true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeVisualDemodulator) {
|
if (activeVisualDemodulator) {
|
||||||
@ -230,8 +218,6 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
|
|||||||
}
|
}
|
||||||
|
|
||||||
activeDemodulator = demod;
|
activeDemodulator = demod;
|
||||||
|
|
||||||
// garbageCollect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
||||||
@ -246,8 +232,8 @@ DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::garbageCollect() {
|
void DemodulatorMgr::garbageCollect() {
|
||||||
|
std::lock_guard < std::mutex > lock(demods_busy);
|
||||||
if (demods_deleted.size()) {
|
if (demods_deleted.size()) {
|
||||||
demods_busy.lock();
|
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||||
@ -259,11 +245,9 @@ void DemodulatorMgr::garbageCollect() {
|
|||||||
|
|
||||||
delete deleted;
|
delete deleted;
|
||||||
|
|
||||||
demods_busy.unlock();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
demods_busy.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,22 +27,20 @@ SDRPostThread::~SDRPostThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
|
void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
|
||||||
busy_demod.lock();
|
std::lock_guard < std::mutex > lock(busy_demod);
|
||||||
demodulators.push_back(demod);
|
demodulators.push_back(demod);
|
||||||
doRefresh.store(true);
|
doRefresh.store(true);
|
||||||
busy_demod.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
|
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
|
||||||
if (!demods) {
|
if (!demods) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
busy_demod.lock();
|
std::lock_guard < std::mutex > lock(busy_demod);
|
||||||
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
|
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
|
||||||
demodulators.push_back(*di);
|
demodulators.push_back(*di);
|
||||||
doRefresh.store(true);
|
doRefresh.store(true);
|
||||||
}
|
}
|
||||||
busy_demod.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||||
@ -50,14 +48,13 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
busy_demod.lock();
|
std::lock_guard < std::mutex > lock(busy_demod);
|
||||||
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
|
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
|
||||||
|
|
||||||
if (i != demodulators.end()) {
|
if (i != demodulators.end()) {
|
||||||
demodulators.erase(i);
|
demodulators.erase(i);
|
||||||
doRefresh.store(true);
|
doRefresh.store(true);
|
||||||
}
|
}
|
||||||
busy_demod.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDRPostThread::initPFBChannelizer() {
|
void SDRPostThread::initPFBChannelizer() {
|
||||||
@ -186,7 +183,7 @@ void SDRPostThread::run() {
|
|||||||
iqDataInQueue->pop(data_in);
|
iqDataInQueue->pop(data_in);
|
||||||
// std::lock_guard < std::mutex > lock(data_in->m_mutex);
|
// std::lock_guard < std::mutex > lock(data_in->m_mutex);
|
||||||
|
|
||||||
busy_demod.lock();
|
std::lock_guard < std::mutex > lock(busy_demod);
|
||||||
|
|
||||||
if (data_in && data_in->data.size()) {
|
if (data_in && data_in->data.size()) {
|
||||||
if(data_in->numChannels > 1) {
|
if(data_in->numChannels > 1) {
|
||||||
@ -211,8 +208,6 @@ void SDRPostThread::run() {
|
|||||||
if (doUpdate) {
|
if (doUpdate) {
|
||||||
updateActiveDemodulators();
|
updateActiveDemodulators();
|
||||||
}
|
}
|
||||||
|
|
||||||
busy_demod.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iqVisualQueue && !iqVisualQueue->empty()) {
|
if (iqVisualQueue && !iqVisualQueue->empty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user