[vlc-devel] commit: vlc_mutex_locker: automatic mutex locking for C++ ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon Oct 20 22:16:07 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Mon Oct 20 22:45:16 2008 +0300| [14e89cbcefbdd8efd03c6d7484d13682ffe67b4e] | committer: Rémi Denis-Courmont 

vlc_mutex_locker: automatic mutex locking for C++

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

 include/vlc_threads.h |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 4ab92c2..7b66e5b 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -448,4 +448,27 @@ static inline void barrier (void)
 #define vlc_thread_join( P_THIS )                                           \
     __vlc_thread_join( VLC_OBJECT(P_THIS) )
 
+#ifdef __cplusplus
+/**
+ * Helper C++ class to lock a mutex.
+ * The mutex is locked when the object is created, and unlocked when the object
+ * is destroyed.
+ */
+class vlc_mutex_locker
+{
+    private:
+        vlc_mutex_t *lock;
+    public:
+        vlc_mutex_locker (vlc_mutex_t *m) : lock (m)
+        {
+            vlc_mutex_lock (lock);
+        }
+
+        ~vlc_mutex_locker (void)
+        {
+            vlc_mutex_unlock (lock);
+        }
+};
+#endif
+
 #endif /* !_VLC_THREADS_H */




More information about the vlc-devel mailing list