Merge pull request #2579 from akallabeth/mutex_debug_log

winpr mutex unlock on destroy
This commit is contained in:
Norbert Federa 2015-04-29 18:04:59 +02:00
commit 19dc7b7440
3 changed files with 53 additions and 1 deletions

View File

@ -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_SVC "Print static virtual channel debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_TRANSPORT "Print transport 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_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_TIMEZONE "Print timezone debug messages." ${DEFAULT_DEBUG_OPTION})
option(WITH_DEBUG_WND "Print window order 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}) option(WITH_DEBUG_X11_CLIPRDR "Print X11 clipboard redirection debug messages" ${DEFAULT_DEBUG_OPTION})

View File

@ -88,6 +88,7 @@
#cmakedefine WITH_DEBUG_RDPEI #cmakedefine WITH_DEBUG_RDPEI
#cmakedefine WITH_DEBUG_TIMEZONE #cmakedefine WITH_DEBUG_TIMEZONE
#cmakedefine WITH_DEBUG_THREADS #cmakedefine WITH_DEBUG_THREADS
#cmakedefine WITH_DEBUG_MUTEX
#cmakedefine WITH_DEBUG_TRANSPORT #cmakedefine WITH_DEBUG_TRANSPORT
#cmakedefine WITH_DEBUG_WND #cmakedefine WITH_DEBUG_WND
#cmakedefine WITH_DEBUG_X11 #cmakedefine WITH_DEBUG_X11

View File

@ -22,12 +22,20 @@
#endif #endif
#include <winpr/synch.h> #include <winpr/synch.h>
#include <winpr/debug.h>
#include <winpr/wlog.h>
#include "synch.h" #include "synch.h"
#ifndef _WIN32 #ifndef _WIN32
#include <errno.h>
#include "../handle/handle.h" #include "../handle/handle.h"
#include "../log.h"
#define TAG WINPR_TAG("sync.mutex")
static BOOL MutexCloseHandle(HANDLE handle); static BOOL MutexCloseHandle(HANDLE handle);
static BOOL MutexIsHandled(HANDLE handle) static BOOL MutexIsHandled(HANDLE handle)
@ -57,12 +65,54 @@ static int MutexGetFd(HANDLE handle)
BOOL MutexCloseHandle(HANDLE handle) BOOL MutexCloseHandle(HANDLE handle)
{ {
WINPR_MUTEX* mutex = (WINPR_MUTEX*) handle; WINPR_MUTEX* mutex = (WINPR_MUTEX*) handle;
int rc;
if (!MutexIsHandled(handle)) if (!MutexIsHandled(handle))
return FALSE; return FALSE;
if (!pthread_mutex_destroy(&mutex->mutex)) rc = pthread_mutex_trylock(&mutex->mutex);
switch(rc)
{
/* If we already own the mutex consider it a success. */
case EDEADLK:
case EBUSY:
break;
default:
#if defined(WITH_DEBUG_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; i<used; i++)
WLog_ERR(TAG, "%2d: %s", i, msg[i]);
}
free (msg);
winpr_backtrace_free(stack);
}
#endif
WLog_ERR(TAG, "pthread_mutex_trylock failed with %s [%d]", strerror(rc), rc);
return FALSE; return FALSE;
}
rc = pthread_mutex_unlock(&mutex->mutex);
if (rc != 0)
{
WLog_ERR(TAG, "pthread_mutex_unlock failed with %s [%d]", strerror(rc), rc);
return FALSE;
}
rc = pthread_mutex_destroy(&mutex->mutex);
if (rc != 0)
{
WLog_ERR(TAG, "pthread_mutex_destroy failed with %s [%d]", strerror(rc), rc);
return FALSE;
}
free(handle); free(handle);