[vlc-commits] medialib: improve starting

Romain Vimont git at videolan.org
Mon Jan 25 17:47:00 UTC 2021


vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Wed Jan  6 13:45:59 2021 +0100| [4e7a6b4fa982f9737d27b07701758809083682d6] | committer: Hugo Beauzée-Luyssen

medialib: improve starting

Some controls request to "start" the medialibrary (start to discover
some folders) if not already started. The actual starting should be done
at most once.

The fact that it was already started relied on the number of entry
points, which can only be known by executing SQL queries. For
asynchronous controls, this caused the execution of SQL queries on the
UI thread for every control requesting the medialibrary to be "started".

To avoid this unnecessary performance issue, add a simple atomic flag.

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4e7a6b4fa982f9737d27b07701758809083682d6
---

 modules/misc/medialibrary/medialibrary.cpp | 4 ++++
 modules/misc/medialibrary/medialibrary.h   | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/modules/misc/medialibrary/medialibrary.cpp b/modules/misc/medialibrary/medialibrary.cpp
index ff675cf865..1d7a12547c 100644
--- a/modules/misc/medialibrary/medialibrary.cpp
+++ b/modules/misc/medialibrary/medialibrary.cpp
@@ -462,6 +462,10 @@ bool MediaLibrary::Start()
     if ( Init() == false )
         return false;
 
+    if ( m_started.test_and_set() )
+        /* The code below should be executed at most once */
+        return true;
+
     /*
      * If we already provided the medialib with some entry points, then we have
      * nothing left to do
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 09c773bf59..8ba8d5c108 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -170,6 +170,8 @@ private:
     vlc::threads::mutex m_mutex;
     bool m_initialized = false; /* protected by m_mutex */
 
+    std::atomic_flag m_started = ATOMIC_FLAG_INIT;
+
     // IMediaLibraryCb interface
 public:
     virtual void onMediaAdded(std::vector<medialibrary::MediaPtr> media) override;



More information about the vlc-commits mailing list