From d2240ec0ae7770e0917c18ff5f29e580e630a34a Mon Sep 17 00:00:00 2001 From: Lukas Prediger Date: Thu, 3 Jun 2021 21:28:46 +0300 Subject: [PATCH] Device change watchdog timer no longer freezes main thread while CddaSongLoader is active. --- src/devices/cddadevice.cpp | 4 ++++ src/devices/cddasongloader.cpp | 4 +++- src/devices/cddasongloader.h | 1 + src/ripper/ripcddialog.h | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/devices/cddadevice.cpp b/src/devices/cddadevice.cpp index f270e22b1..ba250f879 100644 --- a/src/devices/cddadevice.cpp +++ b/src/devices/cddadevice.cpp @@ -77,6 +77,10 @@ void CddaDevice::SongsLoaded(const SongList& songs) { } void CddaDevice::CheckDiscChanged() { + // do nothing if loader is currently reading; + // we'd just block until it's finished + if (cdda_song_loader_.IsActive()) return; + Q_ASSERT(cdio_); if (cdio_get_media_changed(cdio_) == 1) { emit DiscChanged(); diff --git a/src/devices/cddasongloader.cpp b/src/devices/cddasongloader.cpp index 37908ac84..b26dfb564 100644 --- a/src/devices/cddasongloader.cpp +++ b/src/devices/cddasongloader.cpp @@ -50,9 +50,11 @@ QUrl CddaSongLoader::GetUrlFromTrack(int track_number) const { return CddaDevice::TrackStrToUrl(track); } +bool CddaSongLoader::IsActive() const { return loading_future_.isRunning(); } + void CddaSongLoader::LoadSongs() { // only dispatch a new thread for loading tracks if not already running. - if (!loading_future_.isRunning()) { + if (!IsActive()) { loading_future_ = QtConcurrent::run(this, &CddaSongLoader::LoadSongsFromCdda); } diff --git a/src/devices/cddasongloader.h b/src/devices/cddasongloader.h index 3111a1fe8..b2e5d3919 100644 --- a/src/devices/cddasongloader.h +++ b/src/devices/cddasongloader.h @@ -45,6 +45,7 @@ class CddaSongLoader : public QObject { // Signals declared below will be emitted anytime new information will be // available. void LoadSongs(); + bool IsActive() const; signals: void SongsLoaded(const SongList& songs); diff --git a/src/ripper/ripcddialog.h b/src/ripper/ripcddialog.h index b5577c70a..08c38ae7d 100644 --- a/src/ripper/ripcddialog.h +++ b/src/ripper/ripcddialog.h @@ -47,8 +47,8 @@ class RipCDDialog : public QDialog { ~RipCDDialog(); protected: - void closeEvent(QCloseEvent* event); - void showEvent(QShowEvent* event); + void closeEvent(QCloseEvent* event) override; + void showEvent(QShowEvent* event) override; private slots: void ClickedRipButton();