vlc | branch: master | Romain Vimont <ro...@videolabs.io> | Fri Nov 13 14:04:42 2020 +0100| [dc787ba51b2aa450c98d4e873de6817959af4be2] | committer: Pierre Lamot
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 <pie...@videolabs.io> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dc787ba51b2aa450c98d4e873de6817959af4be2 --- modules/gui/qt/medialibrary/medialib.cpp | 3 +++ modules/gui/qt/medialibrary/medialib.hpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/modules/gui/qt/medialibrary/medialib.cpp b/modules/gui/qt/medialibrary/medialib.cpp index c0b06339a9..cdccf4b1b9 100644 --- a/modules/gui/qt/medialibrary/medialib.cpp +++ b/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) diff --git a/modules/gui/qt/medialibrary/medialib.hpp b/modules/gui/qt/medialibrary/medialib.hpp index d7646ea999..2274c359cd 100644 --- a/modules/gui/qt/medialibrary/medialib.hpp +++ b/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; }; _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits