From: RĂ©mi Denis-Courmont Date: Mon, 20 Oct 2008 19:45:16 +0000 (+0300) Subject: vlc_mutex_locker: automatic mutex locking for C++ X-Git-Tag: 1.0.0-pre1~2393 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=14e89cbcefbdd8efd03c6d7484d13682ffe67b4e;p=vlc vlc_mutex_locker: automatic mutex locking for C++ --- 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 */