mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-11 01:14:24 +01:00
Prevent deletion of LibraryModel object while async query is running.
Create a thread pool for each LibraryModel object and block destruction until all threads that are operating on this object are complete. Note that this is not a complete solution. The async query also uses the library backend which may still be deleted before the thread exits. This will be addressed in a future change.
This commit is contained in:
parent
9a9cf08a63
commit
f817e0de48
@ -88,6 +88,7 @@ LibraryModel::LibraryModel(LibraryBackend* backend, Application* app,
|
||||
playlists_dir_icon_(IconLoader::Load("folder-sound", IconLoader::Base)),
|
||||
playlist_icon_(IconLoader::Load("x-clementine-albums", IconLoader::Base)),
|
||||
icon_cache_(new QNetworkDiskCache(this)),
|
||||
thread_pool_(this),
|
||||
init_task_id_(-1),
|
||||
use_pretty_covers_(false),
|
||||
show_dividers_(true) {
|
||||
@ -129,7 +130,10 @@ LibraryModel::LibraryModel(LibraryBackend* backend, Application* app,
|
||||
backend_->UpdateTotalSongCountAsync();
|
||||
}
|
||||
|
||||
LibraryModel::~LibraryModel() { delete root_; }
|
||||
LibraryModel::~LibraryModel() {
|
||||
thread_pool_.waitForDone();
|
||||
delete root_;
|
||||
}
|
||||
|
||||
void LibraryModel::set_pretty_covers(bool use_pretty_covers) {
|
||||
if (use_pretty_covers != use_pretty_covers_) {
|
||||
@ -769,7 +773,7 @@ void LibraryModel::LazyPopulate(LibraryItem* parent, bool signal) {
|
||||
|
||||
void LibraryModel::ResetAsync() {
|
||||
QFuture<LibraryModel::QueryResult> future =
|
||||
QtConcurrent::run(this, &LibraryModel::RunQuery, root_);
|
||||
QtConcurrent::run(&thread_pool_, this, &LibraryModel::RunQuery, root_);
|
||||
NewClosure(future, this,
|
||||
SLOT(ResetAsyncQueryFinished(QFuture<LibraryModel::QueryResult>)),
|
||||
future);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QAbstractItemModel>
|
||||
#include <QIcon>
|
||||
#include <QNetworkDiskCache>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "libraryitem.h"
|
||||
#include "libraryquery.h"
|
||||
@ -292,6 +293,8 @@ signals:
|
||||
|
||||
QNetworkDiskCache* icon_cache_;
|
||||
|
||||
QThreadPool thread_pool_;
|
||||
|
||||
int init_task_id_;
|
||||
|
||||
bool use_pretty_covers_;
|
||||
|
Loading…
Reference in New Issue
Block a user