From fc1c1c3b4d6df7c2c6b518f7066e0ef580c319b1 Mon Sep 17 00:00:00 2001 From: vsonnier Date: Mon, 22 Jan 2018 06:49:42 +0100 Subject: [PATCH] AudioThread: rollback deviceCleanup() to only doing terminate + TEST: apply to all platforms --- src/CubicSDR.cpp | 3 +-- src/audio/AudioThread.cpp | 24 ++++-------------------- src/audio/AudioThread.h | 1 - 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index e6b63b1..6823a7e 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -486,9 +486,8 @@ int CubicSDR::OnExit() { std::cout << "Application termination complete." << std::endl << std::flush; -#ifdef __APPLE__ + //TODO ? AudioThread::deviceCleanup(); -#endif return wxApp::OnExit(); } diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index a8df680..97b44ee 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -81,24 +81,10 @@ void AudioThread::removeThread(AudioThread *other) { void AudioThread::deviceCleanup() { std::lock_guard lock(m_device_mutex); - - auto it = deviceController.begin(); - - std::cout << "Final audio management cleanup, terminating " << deviceController.size() << " device controllers..." << std::endl << std::flush; - - while (it != deviceController.end()) { - - //notify termination... - it->second->terminate(); - - //deletion of it->second will take care of the controllerThread: - delete it->second; - - //next device - it++; - } - - std::cout << "Final audio management cleanup complete..." << std::endl << std::flush; + // only notify, let the thread die by itself. + for (auto i = deviceController.begin(); i != deviceController.end(); i++) { + i->second->terminate(); + } } static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned int nBufferFrames, double /* streamTime */, RtAudioStreamStatus status, @@ -428,9 +414,7 @@ void AudioThread::setupDevice(int deviceId) { deviceController[parameters.deviceId] = new AudioThread(); deviceController[parameters.deviceId]->setInitOutputDevice(parameters.deviceId, sampleRate); - // BEWARE: the controller add itself to the list of boundThreads ! deviceController[parameters.deviceId]->bindThread(this); - deviceController[parameters.deviceId]->attachControllerThread(new std::thread(&AudioThread::threadMain, deviceController[parameters.deviceId])); } else if (deviceController[parameters.deviceId] == this) { diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index 0149193..ec13edc 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "ThreadBlockingQueue.h" #include "RtAudio.h"