Fix timer managmement during shutdown

This commit is contained in:
Brad Davis 2018-09-24 14:52:13 -07:00
parent d520152a95
commit 72fc686ec1
4 changed files with 36 additions and 5 deletions

View file

@ -1759,10 +1759,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// Make sure we don't time out during slow operations at startup
updateHeartbeat();
QTimer* settingsTimer = new QTimer();
moveToNewNamedThread(settingsTimer, "Settings Thread", [this, settingsTimer]{
connect(qApp, &Application::beforeAboutToQuit, [this, settingsTimer]{
// This needs to run on the settings thread, so we need to pass the `settingsTimer` as the
// receiver object, otherwise it will run on the application thread and trigger a warning
// about trying to kill the timer on the main thread.
connect(qApp, &Application::beforeAboutToQuit, settingsTimer, [this, settingsTimer]{
// Disconnect the signal from the save settings
QObject::disconnect(settingsTimer, &QTimer::timeout, this, &Application::saveSettings);
// Stop the settings timer

View file

@ -101,6 +101,13 @@ QList<QAudioDeviceInfo> getAvailableDevices(QAudio::Mode mode) {
// now called from a background thread, to keep blocking operations off the audio thread
void AudioClient::checkDevices() {
// Make sure we're not shutting down
Lock timerMutex(_checkDevicesMutex);
// If we HAVE shut down after we were queued, but prior to execution, early exit
if (nullptr == _checkDevicesTimer) {
return;
}
auto inputDevices = getAvailableDevices(QAudio::AudioInput);
auto outputDevices = getAvailableDevices(QAudio::AudioOutput);
@ -278,8 +285,8 @@ void AudioClient::customDeleter() {
_shouldRestartInputSetup = false;
#endif
stop();
_checkDevicesTimer->stop();
_checkPeakValuesTimer->stop();
//_checkDevicesTimer->stop();
//_checkPeakValuesTimer->stop();
deleteLater();
}
@ -648,12 +655,26 @@ void AudioClient::start() {
}
void AudioClient::stop() {
qCDebug(audioclient) << "AudioClient::stop(), requesting switchInputToAudioDevice() to shut down";
switchInputToAudioDevice(QAudioDeviceInfo(), true);
qCDebug(audioclient) << "AudioClient::stop(), requesting switchOutputToAudioDevice() to shut down";
switchOutputToAudioDevice(QAudioDeviceInfo(), true);
// Stop triggering the checks
QObject::disconnect(_checkPeakValuesTimer, &QTimer::timeout, nullptr, nullptr);
QObject::disconnect(_checkDevicesTimer, &QTimer::timeout, nullptr, nullptr);
// Destruction of the pointers will occur when the parent object (this) is destroyed)
{
Lock lock(_checkDevicesMutex);
_checkDevicesTimer = nullptr;
}
{
Lock lock(_checkPeakValuesMutex);
_checkPeakValuesTimer = nullptr;
}
#if defined(Q_OS_ANDROID)
_checkInputTimer.stop();
disconnect(&_checkInputTimer, &QTimer::timeout, 0, 0);

View file

@ -432,7 +432,9 @@ private:
bool _shouldRestartInputSetup { true }; // Should we restart the input device because of an unintended stop?
#endif
Mutex _checkDevicesMutex;
QTimer* _checkDevicesTimer { nullptr };
Mutex _checkPeakValuesMutex;
QTimer* _checkPeakValuesTimer { nullptr };
bool _isRecording { false };

View file

@ -40,6 +40,12 @@ void release(IAudioClient* audioClient) {
}
void AudioClient::checkPeakValues() {
// Guard against running during shutdown
Lock timerMutex(_checkPeakValuesMutex);
if (nullptr == _checkPeakValuesTimer) {
return;
}
// prepare the windows environment
CoInitialize(NULL);