Prevent UI hang during device scan. (#6291)

When unmounting a device, the ConnectedDevice object is destroyed. The
FileSystemDevice destructor waits on its worker thread. If a scan is in
progress, this will block until completion.

There is an existing Stop method in the LibraryWatcher class that is intended to
stop long running operations. To fix, or at least significantly shorten this
hang, we'll call this before waiting for the thread to exit. Also add a
stop_requested check in the cover art scan.

In addition, add a call to Stop in the Library destructor, which has a similar
usage.
This commit is contained in:
Jim Broadus 2019-02-20 00:03:44 -08:00 committed by John Maguire
parent 925773f15c
commit 248f1d8596
3 changed files with 4 additions and 0 deletions

View File

@ -71,6 +71,7 @@ void FilesystemDevice::Init() {
}
FilesystemDevice::~FilesystemDevice() {
watcher_->Stop();
watcher_->deleteLater();
watcher_thread_->exit();
watcher_thread_->wait();

View File

@ -121,6 +121,7 @@ Library::Library(Application* app, QObject* parent)
}
Library::~Library() {
watcher_->Stop();
watcher_->deleteLater();
watcher_thread_->exit();
watcher_thread_->wait(5000 /* five seconds */);

View File

@ -678,6 +678,8 @@ QString LibraryWatcher::PickBestImage(const QStringList& images) {
QString biggest_path;
for (const QString& path : filtered) {
if (stop_requested_) return "";
QImage image(path);
if (image.isNull()) continue;