From ac15ce2da84080df06d26556c641c85bca02385f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 28 Apr 2015 08:55:26 +0200 Subject: [PATCH] Added mutex debug flag. When mutex debugging is enabled now a stack trace is logged, if a mutex is locked on destruction. --- cmake/ConfigOptions.cmake | 1 + config.h.in | 1 + winpr/libwinpr/synch/mutex.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 282659e..b51a46b 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -115,6 +115,7 @@ option(WITH_DEBUG_SND "Print rdpsnd debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_SVC "Print static virtual channel debug messages." ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_TRANSPORT "Print transport debug messages." ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_THREADS "Print thread debug messages, enables handle dump" ${DEFAULT_DEBUG_OPTION}) +option(WITH_DEBUG_MUTEX "Print mutex debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_TIMEZONE "Print timezone debug messages." ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_WND "Print window order debug messages" ${DEFAULT_DEBUG_OPTION}) option(WITH_DEBUG_X11_CLIPRDR "Print X11 clipboard redirection debug messages" ${DEFAULT_DEBUG_OPTION}) diff --git a/config.h.in b/config.h.in index 82c75ee..807148d 100644 --- a/config.h.in +++ b/config.h.in @@ -88,6 +88,7 @@ #cmakedefine WITH_DEBUG_RDPEI #cmakedefine WITH_DEBUG_TIMEZONE #cmakedefine WITH_DEBUG_THREADS +#cmakedefine WITH_DEBUG_MUTEX #cmakedefine WITH_DEBUG_TRANSPORT #cmakedefine WITH_DEBUG_WND #cmakedefine WITH_DEBUG_X11 diff --git a/winpr/libwinpr/synch/mutex.c b/winpr/libwinpr/synch/mutex.c index 50d9508..37c54ba 100644 --- a/winpr/libwinpr/synch/mutex.c +++ b/winpr/libwinpr/synch/mutex.c @@ -22,12 +22,18 @@ #endif #include +#include +#include #include "synch.h" #ifndef _WIN32 #include "../handle/handle.h" + +#include "../log.h" +#define TAG WINPR_TAG("sync.mutex") + static BOOL MutexCloseHandle(HANDLE handle); static BOOL MutexIsHandled(HANDLE handle) @@ -61,6 +67,28 @@ BOOL MutexCloseHandle(HANDLE handle) if (!MutexIsHandled(handle)) return FALSE; +#if defined(WITH_DEBUG_MUTEX) + if (pthread_mutex_trylock(&mutex->mutex)) + { + size_t used = 0, i; + void* stack = winpr_backtrace(20); + char **msg = NULL; + + if (stack) + msg = winpr_backtrace_symbols(stack, &used); + + if (msg) + { + for(i=0; imutex); +#endif + if (!pthread_mutex_destroy(&mutex->mutex)) return FALSE; -- 2.7.4