vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Sat Oct 20 22:01:23 2018 +0300| [bb4dc88183adb8bc213ec1733b02ad1ce1579844] | committer: Rémi Denis-Courmont
posix: use the new mutex checks > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bb4dc88183adb8bc213ec1733b02ad1ce1579844 --- src/libvlc.h | 7 ++++++- src/posix/thread.c | 43 ++++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/libvlc.h b/src/libvlc.h index 18243ce4c0..dff18d6285 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -78,9 +78,14 @@ bool vlc_mutex_marked(const vlc_mutex_t *); # define vlc_mutex_unmark(m) ((void)(m)) #endif +/** + * Asserts that a mutex is locked by the calling thread. + */ #define vlc_mutex_assert(m) assert(vlc_mutex_marked(m)) -#if (defined (LIBVLC_USE_PTHREAD) || defined(__ANDROID__) || defined (__APPLE__)) && !defined (NDEBUG) +#if (defined (LIBVLC_USE_PTHREAD)) +#define vlc_assert_locked(m) vlc_mutex_assert(m) +#elif (defined(__ANDROID__) || defined (__APPLE__)) && !defined (NDEBUG) void vlc_assert_locked (vlc_mutex_t *); #else # define vlc_assert_locked( m ) (void)m diff --git a/src/posix/thread.c b/src/posix/thread.c index fc92102df6..74f4b2763d 100644 --- a/src/posix/thread.c +++ b/src/posix/thread.c @@ -136,43 +136,32 @@ void vlc_mutex_destroy (vlc_mutex_t *p_mutex) VLC_THREAD_ASSERT ("destroying mutex"); } -#ifndef NDEBUG -# ifdef HAVE_VALGRIND_VALGRIND_H -# include <valgrind/valgrind.h> -# else -# define RUNNING_ON_VALGRIND (0) -# endif - -/** - * Asserts that a mutex is locked by the calling thread. - */ -void vlc_assert_locked (vlc_mutex_t *p_mutex) +void vlc_mutex_lock(vlc_mutex_t *mutex) { - if (RUNNING_ON_VALGRIND > 0) - return; - assert (pthread_mutex_lock (p_mutex) == EDEADLK); -} -#endif + int val = pthread_mutex_lock(mutex); -void vlc_mutex_lock (vlc_mutex_t *p_mutex) -{ - int val = pthread_mutex_lock( p_mutex ); - VLC_THREAD_ASSERT ("locking mutex"); + VLC_THREAD_ASSERT("locking mutex"); + vlc_mutex_mark(mutex); } -int vlc_mutex_trylock (vlc_mutex_t *p_mutex) +int vlc_mutex_trylock(vlc_mutex_t *mutex) { - int val = pthread_mutex_trylock( p_mutex ); + int val = pthread_mutex_trylock(mutex); + + if (val != EBUSY) { + VLC_THREAD_ASSERT("locking mutex"); + vlc_mutex_mark(mutex); + } - if (val != EBUSY) - VLC_THREAD_ASSERT ("locking mutex"); return val; } -void vlc_mutex_unlock (vlc_mutex_t *p_mutex) +void vlc_mutex_unlock(vlc_mutex_t *mutex) { - int val = pthread_mutex_unlock( p_mutex ); - VLC_THREAD_ASSERT ("unlocking mutex"); + int val = pthread_mutex_unlock(mutex); + + VLC_THREAD_ASSERT("unlocking mutex"); + vlc_mutex_unmark(mutex); } void vlc_cond_init (vlc_cond_t *p_condvar) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
