[vlc-devel] [PATCH 2/2] win32: implement vlc_assert_locked()
Steve Lhomme
robux4 at videolabs.io
Wed Jun 22 14:20:46 CEST 2016
--
fixes super_mutex usage in https://patches.videolan.org/patch/13759/
---
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 63d8b54..86f31fc 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 8d53185..fb43fc5 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -187,6 +187,23 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
LeaveCriticalSection (&p_mutex->mutex);
}
+#ifndef NDEBUG
+void vlc_assert_locked (vlc_mutex_t *p_mutex)
+{
+ if (!p_mutex->dynamic)
+ { /* static mutexes */
+ EnterCriticalSection(&super_mutex);
+ assert (p_mutex->locked);
+ LeaveCriticalSection (&super_mutex);
+ return;
+ }
+
+ int ret = TryEnterCriticalSection (&p_mutex->mutex);
+ assert(ret != 0 && p_mutex->locked);
+ LeaveCriticalSection (&p_mutex->mutex);
+}
+#endif
+
/*** Semaphore ***/
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
# include <stdalign.h>
--
2.7.2.windows.1
More information about the vlc-devel
mailing list