[vlc-devel] [PATCH 02/18] gui/qt: add struct vlc_playlist_locker

Filip Roséen filip at videolabs.io
Wed Jul 20 04:36:52 CEST 2016


Given that we currently do not have such entity in
include/vlc_playlist.h, this patch introduces such inside the
gui/Qt-module.

The perks of using this helper are:

    1. it makes locking/unlocking the playlist thread-safe
    2. it makes it "impossible" to forget to unlock the playlist
    3. it often makes it easier to reason about the code
---
 modules/gui/qt/qt.hpp | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
index 0b83f1f..7276bdc 100644
--- a/modules/gui/qt/qt.hpp
+++ b/modules/gui/qt/qt.hpp
@@ -98,6 +98,29 @@ struct intf_sys_t
 
 #define THEPL p_intf->p_sys->p_playlist
 
+/**
+ * This class may be used for scope-bound locking/unlocking
+ * of a playlist_t*. As hinted, the playlist is locked when
+ * the object is created, and unlocked when the object is
+ * destroyed.
+ */
+
+struct vlc_playlist_locker {
+    vlc_playlist_locker( playlist_t* p_playlist )
+        : p_playlist( p_playlist )
+    {
+        playlist_Lock( p_playlist ); 
+    }
+
+    ~vlc_playlist_locker()
+    {
+        playlist_Unlock( p_playlist );
+    }
+
+    private:
+        playlist_t* p_playlist;
+};
+
 #define THEDP DialogsProvider::getInstance()
 #define THEMIM MainInputManager::getInstance( p_intf )
 #define THEAM ActionsManager::getInstance( p_intf )
-- 
2.9.0



More information about the vlc-devel mailing list