[vlc-devel] [PATCH 11/13] qt: medialib: make cache load() asynchronous
Romain Vimont
rom1v at videolabs.io
Tue Nov 24 11:38:09 CET 2020
On Tue, Nov 24, 2020 at 11:16:36AM +0100, Pierre Lamot wrote:
> On 2020-11-23 17:30, Romain Vimont wrote:
> > Make the list cache use async tasks to load the data asynchronously (and
> > notify data changes once available).
> > ---
> > modules/gui/qt/medialibrary/mlbasemodel.hpp | 5 +-
> > modules/gui/qt/util/listcache.hpp | 132 ++++++++++++++++++--
> > 2 files changed, 124 insertions(+), 13 deletions(-)
> >
> > diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp
> > b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> > index fdd98f5626..d108df976e 100644
> > --- a/modules/gui/qt/medialibrary/mlbasemodel.hpp
> > +++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp
> > @@ -216,9 +216,10 @@ public:
> > if (m_cache)
> > return;
> >
> > + auto &threadPool = m_mediaLib->threadPool();
> > auto loader = createLoader();
> > - m_cache.reset(new ListCache<std::unique_ptr<T>>(loader));
> > - connect(&*m_cache, &ListCacheBase::localDataChanged,
> > + m_cache.reset(new ListCache<std::unique_ptr<T>>(threadPool,
> > loader));
> > + connect(&*m_cache, &BaseListCache::localDataChanged,
> > this, &MLBaseModel::onLocalDataChanged);
> >
> > m_cache->initCount();
> > diff --git a/modules/gui/qt/util/listcache.hpp
> > b/modules/gui/qt/util/listcache.hpp
> > index 56016dce77..f8d5c4d729 100644
> > --- a/modules/gui/qt/util/listcache.hpp
> > +++ b/modules/gui/qt/util/listcache.hpp
> > @@ -24,10 +24,16 @@
> > #endif
> >
> > #include "vlc_common.h"
> > +#include <cassert>
> > #include <memory>
> > #include <vector>
> > #include <QtGlobal>
> > +#include <QMutex>
> > +#include <QMutexLocker>
> > #include <QObject>
> > +#include <QRunnable>
> > +#include <QSharedPointer>
> > +#include "util/asynctask.hpp"
> >
> > /**
> > * `ListCache<T>` represents a cache for a (constant) list of items.
> > @@ -37,6 +43,9 @@
> > * - `count()` returns the number of items in the list;
> > * - `load(index, count)` returning the items for the requested
> > interval.
> > *
> > + * These functions are assumed to be long-running, so they executed
> > from a
> > + * separate thread, not to block the UI thread.
> > + *
> > * The precise cache strategy is unspecified (it may change in the
> > future), but
> > * the general principle is to keep locally only a part of the whole
> > data.
> > *
> > @@ -61,23 +70,54 @@ struct ListCacheLoader
> > };
> >
> > /* Non-template class for signals */
> > -class ListCacheBase : public QObject
> > +class BaseListCache : public QObject
>
> nit: this can probably have the final name in the former patch
Oh, good catch. I had rebased to change the name from ListCacheBase to
BaseListCache, but I did it on the wrong commit. Fixed locally.
Thank you.
More information about the vlc-devel
mailing list