TH_CLEAN_3.5: push() cleanup side of things, assure SDRThread::readStream() to actually check for full + make ThreadQueue notify even in case on not-successfull push(), make it spam notify_all() everytime

This commit is contained in:
vsonnier
2016-07-06 21:23:59 +02:00
parent b495b388c9
commit 21c8a81c32
13 changed files with 197 additions and 99 deletions
+3 -6
View File
@@ -152,7 +152,6 @@ bool DemodulatorInstance::isTerminated() {
bool demodTerminated = demodulatorThread->isTerminated();
bool preDemodTerminated = demodulatorPreThread->isTerminated();
//Cleanup the worker threads, if the threads are indeed terminated
if (audioTerminated) {
@@ -168,7 +167,6 @@ bool DemodulatorInstance::isTerminated() {
if (demodTerminated) {
if (t_Demod) {
#ifdef __APPLE__
pthread_join(t_Demod, nullptr);
#else
@@ -185,8 +183,8 @@ bool DemodulatorInstance::isTerminated() {
}
if (preDemodTerminated) {
if (t_PreDemod) {
if (t_PreDemod) {
#ifdef __APPLE__
pthread_join(t_PreDemod, NULL);
@@ -195,10 +193,9 @@ bool DemodulatorInstance::isTerminated() {
delete t_PreDemod;
#endif
t_PreDemod = nullptr;
}
}
}
bool terminated = audioTerminated && demodTerminated && preDemodTerminated;
return terminated;
+29 -28
View File
@@ -136,13 +136,13 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
i = std::find(demods.begin(), demods.end(), demod);
if (activeDemodulator == demod) {
activeDemodulator = NULL;
activeDemodulator = nullptr;
}
if (lastActiveDemodulator == demod) {
lastActiveDemodulator = NULL;
lastActiveDemodulator = nullptr;
}
if (activeVisualDemodulator == demod) {
activeVisualDemodulator = NULL;
activeVisualDemodulator = nullptr;
}
if (i != demods.end()) {
@@ -150,6 +150,7 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
}
//Ask for termination
demod->setActive(false);
demod->terminate();
//Do not cleanup immediatly
@@ -200,27 +201,28 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool temporary) {
std::lock_guard < std::recursive_mutex > lock(demods_busy);
if (!temporary) {
if (activeDemodulator != NULL) {
lastActiveDemodulator = activeDemodulator;
if (activeDemodulator.load() != nullptr) {
lastActiveDemodulator = activeDemodulator.load();
updateLastState();
} else {
lastActiveDemodulator = demod;
}
updateLastState();
#if USE_HAMLIB
if (wxGetApp().rigIsActive() && wxGetApp().getRigThread()->getFollowModem() && lastActiveDemodulator) {
wxGetApp().getRigThread()->setFrequency(lastActiveDemodulator->getFrequency(),true);
if (wxGetApp().rigIsActive() && wxGetApp().getRigThread()->getFollowModem() && lastActiveDemodulator.load()) {
wxGetApp().getRigThread()->setFrequency(lastActiveDemodulator.load()->getFrequency(),true);
}
#endif
} else {
std::lock_guard < std::recursive_mutex > lock(demods_busy);
garbageCollect();
ReBufferGC::garbageCollect();
}
if (activeVisualDemodulator) {
activeVisualDemodulator->setVisualOutputQueue(NULL);
if (activeVisualDemodulator.load()) {
activeVisualDemodulator.load()->setVisualOutputQueue(nullptr);
}
if (demod) {
demod->setVisualOutputQueue(wxGetApp().getAudioVisualQueue());
@@ -238,7 +240,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
}
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
if (activeDemodulator && !activeDemodulator->isActive()) {
if (activeDemodulator.load() && !activeDemodulator.load()->isActive()) {
activeDemodulator = getLastActiveDemodulator();
}
return activeDemodulator;
@@ -262,8 +264,6 @@ void DemodulatorMgr::garbageCollect() {
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
delete deleted;
return;
}
}
@@ -273,27 +273,28 @@ void DemodulatorMgr::garbageCollect() {
void DemodulatorMgr::updateLastState() {
std::lock_guard < std::recursive_mutex > lock(demods_busy);
if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) {
if (activeDemodulator && activeDemodulator->isActive()) {
lastActiveDemodulator = activeDemodulator;
} else if (activeDemodulator && !activeDemodulator->isActive()){
activeDemodulator = NULL;
lastActiveDemodulator = NULL;
if (activeDemodulator.load() && activeDemodulator.load()->isActive()) {
lastActiveDemodulator = activeDemodulator.load();
} else if (activeDemodulator.load() && !activeDemodulator.load()->isActive()){
activeDemodulator = nullptr;
lastActiveDemodulator = nullptr;
}
}
if (lastActiveDemodulator && !lastActiveDemodulator->isActive()) {
lastActiveDemodulator = NULL;
if (lastActiveDemodulator.load() && !lastActiveDemodulator.load()->isActive()) {
lastActiveDemodulator = nullptr;
}
if (lastActiveDemodulator) {
lastBandwidth = lastActiveDemodulator->getBandwidth();
lastDemodType = lastActiveDemodulator->getDemodulatorType();
lastDemodLock = lastActiveDemodulator->getDemodulatorLock()?true:false;
lastSquelchEnabled = lastActiveDemodulator->isSquelchEnabled();
lastSquelch = lastActiveDemodulator->getSquelchLevel();
lastGain = lastActiveDemodulator->getGain();
lastModemSettings[lastDemodType] = lastActiveDemodulator->readModemSettings();
if (lastActiveDemodulator.load()) {
lastBandwidth = lastActiveDemodulator.load()->getBandwidth();
lastDemodType = lastActiveDemodulator.load()->getDemodulatorType();
lastDemodLock = lastActiveDemodulator.load()->getDemodulatorLock()?true:false;
lastSquelchEnabled = lastActiveDemodulator.load()->isSquelchEnabled();
lastSquelch = lastActiveDemodulator.load()->getSquelchLevel();
lastGain = lastActiveDemodulator.load()->getGain();
lastModemSettings[lastDemodType] = lastActiveDemodulator.load()->readModemSettings();
}
}
+6 -4
View File
@@ -53,15 +53,17 @@ public:
void setLastModemSettings(std::string, ModemSettings);
void updateLastState();
private:
void garbageCollect();
std::vector<DemodulatorInstance *> demods;
std::vector<DemodulatorInstance *> demods_deleted;
DemodulatorInstance *activeDemodulator;
DemodulatorInstance *lastActiveDemodulator;
DemodulatorInstance *activeVisualDemodulator;
std::atomic<DemodulatorInstance *> activeDemodulator;
std::atomic<DemodulatorInstance *> lastActiveDemodulator;
std::atomic<DemodulatorInstance *> activeVisualDemodulator;
int lastBandwidth;
std::string lastDemodType;
+10 -2
View File
@@ -66,6 +66,7 @@ void DemodulatorPreThread::run() {
while (!stopping) {
DemodulatorThreadIQData *inp;
iqInputQueue->pop(inp);
if (frequencyChanged.load()) {
@@ -205,7 +206,11 @@ void DemodulatorPreThread::run() {
resamp->modemKit = cModemKit;
resamp->sampleRate = currentBandwidth;
iqOutputQueue->push(resamp);
if (!iqOutputQueue->push(resamp)) {
resamp->setRefCount(0);
std::cout << "DemodulatorPreThread::run() cannot push resamp into iqOutputQueue, is full !" << std::endl;
std::this_thread::yield();
}
}
inp->decRefCount();
@@ -335,7 +340,10 @@ int DemodulatorPreThread::getAudioSampleRate() {
void DemodulatorPreThread::terminate() {
IOThread::terminate();
DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
iqInputQueue->push(inp);
if (!iqInputQueue->push(inp)) {
delete inp;
}
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_NULL);
workerQueue->push(command);
+16 -3
View File
@@ -74,6 +74,7 @@ void DemodulatorThread::run() {
while (!stopping) {
DemodulatorThreadPostIQData *inp;
iqInputQueue->pop(inp);
// std::lock_guard < std::mutex > lock(inp->m_mutex);
@@ -238,13 +239,23 @@ void DemodulatorThread::run() {
ati_vis->type = 0;
}
localAudioVisOutputQueue->push(ati_vis);
if (!localAudioVisOutputQueue->push(ati_vis)) {
ati_vis->setRefCount(0);
std::cout << "DemodulatorThread::run() cannot push ati_vis into localAudioVisOutputQueue, is full !" << std::endl;
std::this_thread::yield();
}
}
if (ati != nullptr) {
if (!muted.load() && (!wxGetApp().getSoloMode() || (demodInstance == wxGetApp().getDemodMgr().getLastActiveDemodulator()))) {
audioOutputQueue->push(ati);
if (!audioOutputQueue->push(ati)) {
ati->decRefCount();
std::cout << "DemodulatorThread::run() cannot push ati into audioOutputQueue, is full !" << std::endl;
std::this_thread::yield();
}
} else {
ati->setRefCount(0);
}
@@ -297,7 +308,9 @@ void DemodulatorThread::run() {
void DemodulatorThread::terminate() {
IOThread::terminate();
DemodulatorThreadPostIQData *inp = new DemodulatorThreadPostIQData; // push dummy to nudge queue
iqInputQueue->push(inp);
if (!iqInputQueue->push(inp)) {
delete inp;
}
}
bool DemodulatorThread::isMuted() {