Skip to content
Snippets Groups Projects
Commit 97f2817c authored by Romain Vimont's avatar Romain Vimont
Browse files

qt: medialib: define a medialib thread pool

The database queries, initiated by list models, must be executed
asynchronously (on a thread different from the UI thread).

When a list model is destroyed (from the UI thread), some database
queries might still be executing. It would be incorrect for the list
model to wait for them (it would block the UI thread), so they must be
executed on an external thread pool.

Since the queries themselves require the medialib to be executed, they
must not outlive it (or the asynchronous code might crash). Therefore,
the right scope for executing asynchronous queries is the MediaLib
instance.
parent 9f3a5e55
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,9 @@ MediaLib::MediaLib(intf_thread_t *_intf, QObject *_parent)
{
m_event_cb.reset( vlc_ml_event_register_callback( m_ml, MediaLib::onMediaLibraryEvent,
this ) );
/* https://xkcd.com/221/ */
m_threadPool.setMaxThreadCount(4);
}
void MediaLib::addToPlaylist(const QString& mrl, const QStringList* options)
......
......@@ -28,6 +28,7 @@
#include <QMetaObject>
#include <QMetaMethod>
#include <QQmlEngine>
#include <QThreadPool>
#include <memory>
......@@ -65,6 +66,8 @@ public:
vlc_medialibrary_t* vlcMl();
QThreadPool &threadPool() { return m_threadPool; }
signals:
void reloadStarted();
void reloadCompleted();
......@@ -90,4 +93,5 @@ private:
vlc_medialibrary_t* m_ml;
std::unique_ptr<vlc_ml_event_callback_t, std::function<void(vlc_ml_event_callback_t*)>> m_event_cb;
QThreadPool m_threadPool;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment