From 14e89cbcefbdd8efd03c6d7484d13682ffe67b4e Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Mon, 20 Oct 2008 22:45:16 +0300 Subject: [PATCH 1/1] vlc_mutex_locker: automatic mutex locking for C++ --- include/vlc_threads.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/vlc_threads.h b/include/vlc_threads.h index 4ab92c2d03..7b66e5b07c 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 */ -- 2.39.2