[vlc-devel] [PATCH 3/3] win32: implement vlc_assert_locked()
Steve Lhomme
robux4 at videolabs.io
Mon Jun 6 10:19:41 CEST 2016
---
src/libvlc.h | 2 +-
src/win32/thread.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/libvlc.h b/src/libvlc.h
index 21bdfdc..206a10a 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -62,7 +62,7 @@ void vlc_threads_setup (libvlc_int_t *);
void vlc_trace (const char *fn, const char *file, unsigned line);
#define vlc_backtrace() vlc_trace(__func__, __FILE__, __LINE__)
-#if (defined (LIBVLC_USE_PTHREAD) || defined(__ANDROID__)) && !defined (NDEBUG)
+#if (defined (LIBVLC_USE_PTHREAD) || defined(__ANDROID__) || defined(_WIN32)) && !defined (NDEBUG)
void vlc_assert_locked (vlc_mutex_t *);
#else
# define vlc_assert_locked( m ) (void)m
diff --git a/src/win32/thread.c b/src/win32/thread.c
index de611e8..83ba3fe 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -161,6 +161,23 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
LeaveCriticalSection (&p_mutex->mutex);
}
+void vlc_assert_locked (vlc_mutex_t *p_mutex)
+{
+ if (!p_mutex->dynamic)
+ { /* static mutexes */
+ assert (p_mutex != &super_mutex); /* this one cannot be static */
+
+ vlc_mutex_lock (&super_mutex);
+ assert (p_mutex->locked);
+ vlc_mutex_unlock (&super_mutex);
+ return;
+ }
+
+ int ret = TryEnterCriticalSection (&p_mutex->mutex);
+ assert(ret != 0 && p_mutex->lock_thread_id == vlc_thread_id());
+ LeaveCriticalSection (&p_mutex->mutex);
+}
+
/*** Semaphore ***/
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
# include <stdalign.h>
--
2.7.0
More information about the vlc-devel
mailing list