From 9afdee2052f184e611b5353bd52600805e152783 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Tue, 13 Mar 2018 13:56:32 +0900 Subject: [PATCH] macro: add some macros for debug Change-Id: I0f9c9738ff849d13877b0b383da5578848f4f860 --- src/tdm.c | 4 ++++ src/tdm_macro.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/tdm.c b/src/tdm.c index 5146f7e..effa0f3 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -46,6 +46,10 @@ int tdm_mutex_lock_line; const char *tdm_mutex_unlock_func; int tdm_mutex_unlock_line; +pthread_mutex_t tdm_debug_mutex_check_lock = PTHREAD_MUTEX_INITIALIZER; +const char *tdm_debug_mutex_lock_func; +int tdm_debug_mutex_lock_line; + /* LCOV_EXCL_START */ static tdm_private_layer * _tdm_display_find_private_layer(tdm_private_output *private_output, diff --git a/src/tdm_macro.h b/src/tdm_macro.h index 80be131..acdc9f3 100644 --- a/src/tdm_macro.h +++ b/src/tdm_macro.h @@ -461,6 +461,29 @@ static inline int TDM_MUTEX_IS_LOCKED(void) #define tdm_display_unlock(dpy) _pthread_mutex_unlock(&((tdm_private_display *)dpy)->lock) +/* debugging mutex ************************************************************/ +extern pthread_mutex_t tdm_debug_mutex_check_lock; +extern const char *tdm_debug_mutex_lock_func; +extern int tdm_debug_mutex_lock_line; + +#define _debug_pthread_mutex_lock(l) \ + do { \ + pthread_mutex_lock(l); \ + pthread_mutex_lock(&tdm_debug_mutex_check_lock); \ + tdm_debug_mutex_lock_func = __FUNCTION__; \ + tdm_debug_mutex_lock_line = __LINE__; \ + pthread_mutex_unlock(&tdm_debug_mutex_check_lock); \ + } while (0) + +#define _debug_pthread_mutex_unlock(l) \ + do { \ + pthread_mutex_lock(&tdm_debug_mutex_check_lock); \ + tdm_debug_mutex_lock_func = NULL; \ + tdm_debug_mutex_lock_line = 0; \ + pthread_mutex_unlock(&tdm_debug_mutex_check_lock); \ + pthread_mutex_unlock(l); \ + } while (0) + #ifdef __cplusplus } #endif -- 2.7.4