Merge pull request #358 from cjcliffe/bugfix_sessions_crashes

Session and Crash fixes
This commit is contained in:
Charles J. Cliffe 2016-06-02 23:50:49 -04:00
commit ad94fe6de3
11 changed files with 171 additions and 188 deletions

View File

@ -1598,15 +1598,22 @@ bool AppFrame::loadSession(std::string fileName) {
wxGetApp().getDemodMgr().terminateAll();
try {
if (!l.rootNode()->hasAnother("header")) {
return false;
}
DataNode *header = l.rootNode()->getNext("header");
if (header->hasAnother("version")) {
std::string version(*header->getNext("version"));
std::cout << "Loading " << version << " session file" << std::endl;
// std::cout << "Loading " << version << " session file" << std::endl;
}
if (header->hasAnother("center_freq")) {
long long center_freq = *header->getNext("center_freq");
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
// std::cout << "\tCenter Frequency: " << center_freq << std::endl;
wxGetApp().setFrequency(center_freq);
}
if (header->hasAnother("sample_rate")) {
int sample_rate = *header->getNext("sample_rate");
@ -1623,6 +1630,7 @@ bool AppFrame::loadSession(std::string fileName) {
}
if (l.rootNode()->hasAnother("demodulators")) {
DataNode *demodulators = l.rootNode()->getNext("demodulators");
int numDemodulators = 0;
@ -1724,20 +1732,20 @@ bool AppFrame::loadSession(std::string fileName) {
}
}
if (!found_device) {
std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output.";
}
// if (!found_device) {
// std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output.";
// }
newDemod->run();
newDemod->setActive(true);
demodsLoaded.push_back(newDemod);
// wxGetApp().bindDemodulator(newDemod);
// wxGetApp().bindDemodulator(newDemod);
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
std::cout << "\t\tOutput Device: " << output_device << std::endl;
std::cout << "\tAdded demodulator at frequency " << newDemod->getFrequency() << " type " << type << std::endl;
// std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
// std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
// std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
// std::cout << "\t\tOutput Device: " << output_device << std::endl;
}
DemodulatorInstance *focusDemod = loadedDemod?loadedDemod:newDemod;
@ -1746,9 +1754,7 @@ bool AppFrame::loadSession(std::string fileName) {
wxGetApp().bindDemodulators(&demodsLoaded);
wxGetApp().getDemodMgr().setActiveDemodulator(focusDemod, false);
}
} catch (DataInvalidChildException &e) {
std::cout << e.what() << std::endl;
return false;
}
} catch (DataTypeMismatchException &e) {
std::cout << e.what() << std::endl;
return false;

View File

@ -368,7 +368,7 @@ void AudioThread::run() {
pthread_setschedparam(tID, SCHED_RR, &prio);
#endif
std::cout << "Audio thread initializing.." << std::endl;
// std::cout << "Audio thread initializing.." << std::endl;
if (dac.getDeviceCount() < 1) {
std::cout << "No audio devices found!" << std::endl;
@ -377,7 +377,7 @@ void AudioThread::run() {
setupDevice((outputDevice.load() == -1) ? (dac.getDefaultOutputDevice()) : outputDevice.load());
std::cout << "Audio thread started." << std::endl;
// std::cout << "Audio thread started." << std::endl;
inputQueue = static_cast<AudioThreadInputQueue *>(getInputQueue("AudioDataInput"));
threadQueueNotify = static_cast<DemodulatorThreadCommandQueue*>(getOutputQueue("NotifyQueue"));
@ -414,7 +414,7 @@ void AudioThread::run() {
tCmd.context = this;
threadQueueNotify->push(tCmd);
}
std::cout << "Audio thread done." << std::endl;
// std::cout << "Audio thread done." << std::endl;
}
void AudioThread::terminate() {

View File

@ -12,16 +12,18 @@ DemodulatorInstance::DemodulatorInstance() :
activeOutput = nullptr;
#endif
terminated.store(true);
audioTerminated.store(true);
demodTerminated.store(true);
audioTerminated.store(true);
preDemodTerminated.store(true);
active.store(false);
squelch.store(false);
muted.store(false);
tracking.store(false);
follow.store(false);
deltaLock.store(false);
deltaLockOfs.store(0);
currentOutputDevice.store(-1);
currentAudioGain.store(1.0);
follow.store(false);
tracking.store(false);
label = new std::string("Unnamed");
pipeIQInputData = new DemodulatorThreadInputQueue;
@ -89,7 +91,7 @@ void DemodulatorInstance::run() {
pthread_create(&t_Demod, &attr, &DemodulatorThread::pthread_helper, demodulatorThread);
pthread_attr_destroy(&attr);
std::cout << "Initialized demodulator stack size of " << size << std::endl;
// std::cout << "Initialized demodulator stack size of " << size << std::endl;
#else
t_PreDemod = new std::thread(&DemodulatorPreThread::threadMain, demodulatorPreThread);
@ -109,11 +111,11 @@ void DemodulatorInstance::updateLabel(long long freq) {
}
void DemodulatorInstance::terminate() {
std::cout << "Terminating demodulator audio thread.." << std::endl;
// std::cout << "Terminating demodulator audio thread.." << std::endl;
audioThread->terminate();
std::cout << "Terminating demodulator thread.." << std::endl;
// std::cout << "Terminating demodulator thread.." << std::endl;
demodulatorThread->terminate();
std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
// std::cout << "Terminating demodulator preprocessor thread.." << std::endl;
demodulatorPreThread->terminate();
}

View File

@ -31,9 +31,7 @@ DemodulatorMgr::~DemodulatorMgr() {
}
DemodulatorInstance *DemodulatorMgr::newThread() {
garbageCollect();
demods_busy.lock();
std::lock_guard < std::mutex > lock(demods_busy);
DemodulatorInstance *newDemod = new DemodulatorInstance;
std::stringstream label;
@ -41,25 +39,22 @@ DemodulatorInstance *DemodulatorMgr::newThread() {
newDemod->setLabel(label.str());
demods.push_back(newDemod);
demods_busy.unlock();
return newDemod;
}
void DemodulatorMgr::terminateAll() {
std::lock_guard < std::mutex > lock(demods_busy);
while (demods.size()) {
demods_busy.lock();
DemodulatorInstance *d = demods.back();
demods.pop_back();
demods_busy.unlock();
wxGetApp().removeDemodulator(d);
deleteThread(d);
}
}
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
demods_busy.lock();
demods_busy.unlock();
std::lock_guard < std::mutex > lock(demods_busy);
return demods;
}
@ -127,8 +122,6 @@ DemodulatorInstance *DemodulatorMgr::getFirstDemodulator() {
}
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
demods_busy.lock();
std::vector<DemodulatorInstance *>::iterator i;
i = std::find(demods.begin(), demods.end(), demod);
@ -149,14 +142,10 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
demod->terminate();
demods_deleted.push_back(demod);
demods_busy.unlock();
garbageCollect();
}
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 *>();
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);
}
}
demods_busy.unlock();
return foundDemods;
}
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++) {
DemodulatorInstance *testDemod = demods[i];
@ -189,12 +177,10 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
long long halfBuffer = bandwidth / 2;
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
demods_busy.unlock();
return true;
}
}
demods_busy.unlock();
return false;
}
@ -213,6 +199,8 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
wxGetApp().getRigThread()->setFrequency(lastActiveDemodulator->getFrequency(),true);
}
#endif
} else {
garbageCollect();
}
if (activeVisualDemodulator) {
@ -230,8 +218,6 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
}
activeDemodulator = demod;
// garbageCollect();
}
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
@ -246,8 +232,8 @@ DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
}
void DemodulatorMgr::garbageCollect() {
std::lock_guard < std::mutex > lock(demods_busy);
if (demods_deleted.size()) {
demods_busy.lock();
std::vector<DemodulatorInstance *>::iterator i;
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
@ -259,11 +245,9 @@ void DemodulatorMgr::garbageCollect() {
delete deleted;
demods_busy.unlock();
return;
}
}
demods_busy.unlock();
}
}

View File

@ -52,7 +52,7 @@ void DemodulatorPreThread::run() {
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
std::cout << "Demodulator preprocessor thread started.." << std::endl;
// std::cout << "Demodulator preprocessor thread started.." << std::endl;
ReBuffer<DemodulatorThreadPostIQData> buffers("DemodulatorPreThreadBuffers");
@ -276,7 +276,7 @@ void DemodulatorPreThread::run() {
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_PREPROCESS_TERMINATED);
tCmd.context = this;
threadQueueNotify->push(tCmd);
std::cout << "Demodulator preprocessor thread done." << std::endl;
// std::cout << "Demodulator preprocessor thread done." << std::endl;
}
void DemodulatorPreThread::setDemodType(std::string demodType) {

View File

@ -23,7 +23,6 @@ DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent)
}
DemodulatorThread::~DemodulatorThread() {
}
void DemodulatorThread::onBindOutput(std::string name, ThreadQueueBase *threadQueue) {
@ -65,9 +64,7 @@ void DemodulatorThread::run() {
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
ReBuffer<AudioThreadInput> audioVisBuffers("DemodulatorThreadAudioBuffers");
std::cout << "Demodulator thread started.." << std::endl;
// std::cout << "Demodulator thread started.." << std::endl;
iqInputQueue = static_cast<DemodulatorThreadPostInputQueue*>(getInputQueue("IQDataInput"));
audioOutputQueue = static_cast<AudioThreadInputQueue*>(getOutputQueue("AudioDataOutput"));
@ -188,7 +185,7 @@ void DemodulatorThread::run() {
}
if (ati && localAudioVisOutputQueue != nullptr && localAudioVisOutputQueue->empty()) {
AudioThreadInput *ati_vis = audioVisBuffers.getBuffer();
AudioThreadInput *ati_vis = new AudioThreadInput;
ati_vis->setRefCount(1);
ati_vis->sampleRate = inp->sampleRate;
@ -284,17 +281,16 @@ void DemodulatorThread::run() {
//Guard the cleanup of audioVisOutputQueue properly.
std::lock_guard < std::mutex > lock(m_mutexAudioVisOutputQueue);
if (audioVisOutputQueue != nullptr && !audioVisOutputQueue->empty()) {
AudioThreadInput *dummy_vis;
audioVisOutputQueue->pop(dummy_vis);
}
audioVisBuffers.purge();
// if (audioVisOutputQueue != nullptr && !audioVisOutputQueue->empty()) {
// AudioThreadInput *dummy_vis;
// audioVisOutputQueue->pop(dummy_vis);
// }
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
tCmd.context = this;
threadQueueNotify->push(tCmd);
std::cout << "Demodulator thread done." << std::endl;
// std::cout << "Demodulator thread done." << std::endl;
}
void DemodulatorThread::terminate() {

View File

@ -12,7 +12,7 @@ DemodulatorWorkerThread::~DemodulatorWorkerThread() {
void DemodulatorWorkerThread::run() {
std::cout << "Demodulator worker thread started.." << std::endl;
// std::cout << "Demodulator worker thread started.." << std::endl;
commandQueue = static_cast<DemodulatorThreadWorkerCommandQueue *>(getInputQueue("WorkerCommandQueue"));
resultQueue = static_cast<DemodulatorThreadWorkerResultQueue *>(getOutputQueue("WorkerResultQueue"));
@ -99,7 +99,7 @@ void DemodulatorWorkerThread::run() {
}
std::cout << "Demodulator worker thread done." << std::endl;
// std::cout << "Demodulator worker thread done." << std::endl;
}
void DemodulatorWorkerThread::terminate() {

View File

@ -35,7 +35,7 @@ void FFTVisualDataThread::run() {
wproc.attachOutput(pipeFFTDataOut);
wproc.setup(DEFAULT_FFT_SIZE);
std::cout << "FFT visual data thread started." << std::endl;
// std::cout << "FFT visual data thread started." << std::endl;
while(!terminated) {
@ -63,6 +63,6 @@ void FFTVisualDataThread::run() {
}
}
std::cout << "FFT visual data thread done." << std::endl;
// std::cout << "FFT visual data thread done." << std::endl;
}

View File

@ -99,7 +99,7 @@ void ScopeVisualProcessor::process() {
}
size_t i, iMax = audioInputData->data.size();
if (!iMax) {
audioInputData->decRefCount();
delete audioInputData; //->decRefCount();
return;
}
@ -213,7 +213,7 @@ void ScopeVisualProcessor::process() {
renderData->inputRate = audioInputData->inputRate;
renderData->sampleRate = audioInputData->sampleRate;
audioInputData->decRefCount();
delete audioInputData; //->decRefCount();
float fft_ceil = 0, fft_floor = 1;
@ -280,7 +280,7 @@ void ScopeVisualProcessor::process() {
renderData->spectrum = true;
distribute(renderData);
} else {
audioInputData->decRefCount();
delete audioInputData; //->decRefCount();
}
}
}

View File

@ -13,7 +13,7 @@ SpectrumVisualProcessor *SpectrumVisualDataThread::getProcessor() {
}
void SpectrumVisualDataThread::run() {
std::cout << "Spectrum visual data thread started." << std::endl;
// std::cout << "Spectrum visual data thread started." << std::endl;
while(!terminated) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -21,6 +21,6 @@ void SpectrumVisualDataThread::run() {
sproc.run();
}
std::cout << "Spectrum visual data thread done." << std::endl;
// std::cout << "Spectrum visual data thread done." << std::endl;
}

View File

@ -27,22 +27,20 @@ SDRPostThread::~SDRPostThread() {
}
void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
busy_demod.lock();
std::lock_guard < std::mutex > lock(busy_demod);
demodulators.push_back(demod);
doRefresh.store(true);
busy_demod.unlock();
}
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
if (!demods) {
return;
}
busy_demod.lock();
std::lock_guard < std::mutex > lock(busy_demod);
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
demodulators.push_back(*di);
doRefresh.store(true);
}
busy_demod.unlock();
}
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
@ -50,14 +48,13 @@ void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
return;
}
busy_demod.lock();
std::lock_guard < std::mutex > lock(busy_demod);
std::vector<DemodulatorInstance *>::iterator i = std::find(demodulators.begin(), demodulators.end(), demod);
if (i != demodulators.end()) {
demodulators.erase(i);
doRefresh.store(true);
}
busy_demod.unlock();
}
void SDRPostThread::initPFBChannelizer() {
@ -171,7 +168,7 @@ void SDRPostThread::run() {
pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif
std::cout << "SDR post-processing thread started.." << std::endl;
// std::cout << "SDR post-processing thread started.." << std::endl;
iqDataInQueue = static_cast<SDRThreadIQDataQueue*>(getInputQueue("IQDataInput"));
iqDataOutQueue = static_cast<DemodulatorThreadInputQueue*>(getOutputQueue("IQDataOutput"));
@ -186,7 +183,7 @@ void SDRPostThread::run() {
iqDataInQueue->pop(data_in);
// 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->numChannels > 1) {
@ -211,8 +208,6 @@ void SDRPostThread::run() {
if (doUpdate) {
updateActiveDemodulators();
}
busy_demod.unlock();
}
if (iqVisualQueue && !iqVisualQueue->empty()) {
@ -223,7 +218,7 @@ void SDRPostThread::run() {
// buffers.purge();
// visualDataBuffers.purge();
std::cout << "SDR post-processing thread done." << std::endl;
// std::cout << "SDR post-processing thread done." << std::endl;
}
void SDRPostThread::terminate() {