Browse Source

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.

Signed-off-by: Pierre Lamot <pierre@videolabs.io>
pull/119/head
Romain Vimont 6 years ago
committed by Pierre Lamot
parent
commit
dc787ba51b
  1. 3
      modules/gui/qt/medialibrary/medialib.cpp
  2. 4
      modules/gui/qt/medialibrary/medialib.hpp

3
modules/gui/qt/medialibrary/medialib.cpp

@ -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)

4
modules/gui/qt/medialibrary/medialib.hpp

@ -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;
};

Loading…
Cancel
Save