TH_CLEAN_3: Use of non-blocking try_pop() when possible,

AudioThread concurrent access hardening and simplified,
and misc.
This commit is contained in:
vsonnier
2016-07-05 21:43:45 +02:00
parent 3bf17d0f40
commit b495b388c9
16 changed files with 223 additions and 149 deletions
+10 -12
View File
@@ -210,12 +210,11 @@ void DemodulatorPreThread::run() {
inp->decRefCount();
if (!stopping && !workerResults->empty()) {
while (!workerResults->empty()) {
DemodulatorWorkerThreadResult result;
workerResults->pop(result);
switch (result.cmd) {
DemodulatorWorkerThreadResult result;
//process all worker results until
while (!stopping && workerResults->try_pop(result)) {
switch (result.cmd) {
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
if (result.iqResampler) {
if (iqResampler) {
@@ -258,20 +257,19 @@ void DemodulatorPreThread::run() {
break;
default:
break;
}
}
}
} //end while
if ((cModem != nullptr) && modemSettingsChanged.load()) {
cModem->writeSettings(modemSettingsBuffered);
modemSettingsBuffered.clear();
modemSettingsChanged.store(false);
}
}
} //end while stopping
while (!iqOutputQueue->empty()) {
DemodulatorThreadPostIQData *tmp;
iqOutputQueue->pop(tmp);
DemodulatorThreadPostIQData *tmp;
while (iqOutputQueue->try_pop(tmp)) {
tmp->decRefCount();
}
buffers.purge();
+26 -24
View File
@@ -250,43 +250,45 @@ void DemodulatorThread::run() {
}
}
if (!threadQueueControl->empty()) {
while (!threadQueueControl->empty()) {
DemodulatorThreadControlCommand command;
threadQueueControl->pop(command);
switch (command.cmd) {
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_ON:
squelchEnabled = true;
break;
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF:
squelchEnabled = false;
break;
default:
break;
}
DemodulatorThreadControlCommand command;
//empty command queue, execute commands
while (threadQueueControl->try_pop(command)) {
switch (command.cmd) {
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_ON:
squelchEnabled = true;
break;
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF:
squelchEnabled = false;
break;
default:
break;
}
}
inp->decRefCount();
}
// end while !stopping
// Purge any unused inputs
while (!iqInputQueue->empty()) {
DemodulatorThreadPostIQData *ref;
iqInputQueue->pop(ref);
// Purge any unused inputs, with a non-blocking pop
DemodulatorThreadPostIQData *ref;
while (iqInputQueue->try_pop(ref)) {
if (ref) { // May have other consumers; just decrement
ref->decRefCount();
}
}
while (!audioOutputQueue->empty()) {
AudioThreadInput *ref;
audioOutputQueue->pop(ref);
if (ref) { // Originated here; set RefCount to 0
ref->setRefCount(0);
AudioThreadInput *ref_audio;
while (audioOutputQueue->try_pop(ref_audio)) {
if (ref_audio) { // Originated here; set RefCount to 0
ref_audio->setRefCount(0);
}
}
outputBuffers.purge();
// std::cout << "Demodulator thread done." << std::endl;
+4
View File
@@ -24,8 +24,12 @@ void DemodulatorWorkerThread::run() {
DemodulatorWorkerThreadCommand command;
bool done = false;
//Beware of the subtility here,
//we are waiting for the first command to show up (blocking!)
//then consuming the commands until done.
while (!done) {
commandQueue->pop(command);
switch (command.cmd) {
case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS:
filterChanged = true;