diff --git a/Makefile b/Makefile index 484c1386ed7cfbc5c2af77622496056fc2271be5..d4362e1d47ccb03716f89f53129691fe99b7e787 100755 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ DEBUG=-g #-pg #OPTIONS += -DLOW_MEMORY # Optional debugging parameters -DEBUG_THREADS = #-DDEBUG_THREADS #-DDO_CRASH +DEBUG_THREADS = #-DDEBUG_THREADS #-DDO_CRASH #-DDETECT_DEADLOCKS # Uncomment next one to enable ast_frame tracing (for debugging) TRACE_FRAMES = #-DTRACE_FRAMES diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index 69aaaeefdb15ae3037f5006449458da954aa743b..37c971ccd1a3a599f2b76300d09df3859f1b3779 100755 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -194,17 +194,19 @@ static inline int __ast_pthread_mutex_lock(char *filename, int lineno, char *fun filename, lineno, func, mutex_name); #endif ast_mutex_init(t); - } + } #endif /* definded(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */ #ifdef DETECT_DEADLOCKS { - time_t seconds seconds = time(NULL); + time_t seconds = time(NULL); + time_t current; do { res = pthread_mutex_trylock(&t->mutex); if (res == EBUSY) { - if ((time(NULL) - seconds) % 5) { + current = time(NULL); + if ((current - seconds) && (!((current - seconds) % 5))) { fprintf(stderr, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n", - filename, lineno, func, (time(NULL) - seconds), mutex_name); + filename, lineno, func, (int)(current - seconds), mutex_name); fprintf(stderr, "%s line %d (%s): '%s' was locked here.\n", t->file, t->lineno, t->func, mutex_name); }