Minor deadlock detect fix (bug #3531)
authorMark Spencer <markster@digium.com>
Tue, 8 Feb 2005 18:48:01 +0000 (18:48 +0000)
committerMark Spencer <markster@digium.com>
Tue, 8 Feb 2005 18:48:01 +0000 (18:48 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4986 65c4cc65-6c06-0410-ace0-fbb531ad65f3

Makefile
include/asterisk/lock.h

index 484c138..d4362e1 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -86,7 +86,7 @@ DEBUG=-g #-pg
 #OPTIONS += -DLOW_MEMORY
 
 # Optional debugging parameters
 #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
 
 # Uncomment next one to enable ast_frame tracing (for debugging)
 TRACE_FRAMES = #-DTRACE_FRAMES
index 69aaaee..37c971c 100755 (executable)
@@ -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);
                        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
        {
 #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) {
                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",
                                        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);
                                }
                                        fprintf(stderr, "%s line %d (%s): '%s' was locked here.\n",
                                                t->file, t->lineno, t->func, mutex_name);
                                }