[svn-commits] russell: branch russell/debug_threads r77880 - in /team/russell/debug_threads...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 1 15:14:32 CDT 2007


Author: russell
Date: Wed Aug  1 15:14:31 2007
New Revision: 77880

URL: http://svn.digium.com/view/asterisk?view=rev&rev=77880
Log:
Fix the combination of MALLOC_DEBUG and DEBUG_THREADS.  The replacement malloc
routines use a mutex, and the mutex tracking code allocates memory, which
caused infinite recursion.

Modified:
    team/russell/debug_threads/astmm.c
    team/russell/debug_threads/include/asterisk/lock.h

Modified: team/russell/debug_threads/astmm.c
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/astmm.c?view=diff&rev=77880&r1=77879&r2=77880
==============================================================================
--- team/russell/debug_threads/astmm.c (original)
+++ team/russell/debug_threads/astmm.c Wed Aug  1 15:14:31 2007
@@ -75,7 +75,7 @@
 #define HASH(a) \
 	(((unsigned long)(a)) % SOME_PRIME)
 	
-AST_MUTEX_DEFINE_STATIC(reglock);
+AST_MUTEX_DEFINE_STATIC_NOTRACKING(reglock);
 AST_MUTEX_DEFINE_STATIC(showmemorylock);
 
 static inline void *__ast_alloc_region(size_t size, int which, const char *file, int lineno, const char *func)

Modified: team/russell/debug_threads/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/team/russell/debug_threads/include/asterisk/lock.h?view=diff&rev=77880&r1=77879&r2=77880
==============================================================================
--- team/russell/debug_threads/include/asterisk/lock.h (original)
+++ team/russell/debug_threads/include/asterisk/lock.h Wed Aug  1 15:14:31 2007
@@ -80,12 +80,15 @@
 #include <stdio.h>
 #include <unistd.h>
 
-#define AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE, { NULL }, { 0 }, 0, { NULL }, { 0 } }
+#define AST_MUTEX_INIT_VALUE { PTHREAD_MUTEX_INIT_VALUE, 1, { NULL }, { 0 }, 0, { NULL }, { 0 } }
+#define AST_MUTEX_INIT_VALUE_NOTRACKING \
+                             { PTHREAD_MUTEX_INIT_VALUE, 0, { NULL }, { 0 }, 0, { NULL }, { 0 } }
 
 #define AST_MAX_REENTRANCY 10
 
 struct ast_mutex_info {
 	pthread_mutex_t mutex;
+	unsigned int track:1;
 	const char *file[AST_MAX_REENTRANCY];
 	int lineno[AST_MAX_REENTRANCY];
 	int reentrancy;
@@ -192,8 +195,8 @@
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 /* if AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope
  constrictors/destructors to create/destroy mutexes.  */
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE; \
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val; \
 static void  __attribute__ ((constructor)) init_##mutex(void) \
 { \
 	ast_mutex_init(&mutex); \
@@ -208,12 +211,12 @@
  the pthreads library does this itself to initialize errror checking
  (defaulty type) mutexes.  If nither is defined, the pthreads librariy
  does the initialization itself on first use. */ 
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val
 #else /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 /* By default, use static initialization of mutexes.*/ 
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 void ast_store_lock_info(const char *filename, int line_num, 
@@ -229,7 +232,8 @@
 	int res;
 	int canlog = strcmp(filename, "logger.c");
 
-	ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+	if (t->track)
+		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -265,7 +269,8 @@
 #endif /* DETECT_DEADLOCKS */
 
 	if (!res) {
-		ast_mark_lock_acquired();
+		if (t->track)
+			ast_mark_lock_acquired();
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
@@ -277,7 +282,8 @@
 							   filename, lineno, func, mutex_name);
 		}
 	} else {
-		ast_remove_lock_info(&t->mutex);
+		if (t->track)
+			ast_remove_lock_info(&t->mutex);
 		__ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
 				   filename, lineno, func, strerror(res));
 #ifdef THREAD_CRASH
@@ -305,10 +311,12 @@
 	}
 #endif /* defined(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */
 
-	ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+	if (t->track)
+		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
 
 	if (!(res = pthread_mutex_trylock(&t->mutex))) {
-		ast_mark_lock_acquired();
+		if (t->track)
+			ast_mark_lock_acquired();
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
@@ -319,7 +327,7 @@
 			__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
 							   filename, lineno, func, mutex_name);
 		}
-	} else {
+	} else if (t->track) {
 		ast_remove_lock_info(&t->mutex);
 	}
 
@@ -362,7 +370,8 @@
 		t->thread[t->reentrancy] = 0;
 	}
 
-	ast_remove_lock_info(&t->mutex);
+	if (t->track)
+		ast_remove_lock_info(&t->mutex);
 
 	if ((res = pthread_mutex_unlock(&t->mutex))) {
 		__ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n", 
@@ -440,7 +449,8 @@
 		t->thread[t->reentrancy] = 0;
 	}
 
-	ast_remove_lock_info(&t->mutex);
+	if (t->track)
+		ast_remove_lock_info(&t->mutex);
 	if ((res = pthread_cond_wait(cond, &t->mutex))) {
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n", 
 				   filename, lineno, func, strerror(res));
@@ -448,7 +458,8 @@
 		DO_THREAD_CRASH;
 #endif
 	} else {
-		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+		if (t->track)
+			ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
@@ -505,7 +516,8 @@
 		t->thread[t->reentrancy] = 0;
 	}
 
-	ast_remove_lock_info(&t->mutex);
+	if (t->track)
+		ast_remove_lock_info(&t->mutex);
 	if ((res = pthread_cond_timedwait(cond, &t->mutex, abstime)) && (res != ETIMEDOUT)) {
 		__ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n", 
 				   filename, lineno, func, strerror(res));
@@ -513,7 +525,8 @@
 		DO_THREAD_CRASH;
 #endif
 	} else {
-		ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
+		if (t->track)
+			ast_store_lock_info(filename, lineno, func, mutex_name, &t->mutex);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
@@ -544,7 +557,8 @@
 #else /* !DEBUG_THREADS */
 
 
-#define AST_MUTEX_INIT_VALUE	PTHREAD_MUTEX_INIT_VALUE
+#define AST_MUTEX_INIT_VALUE            PTHREAD_MUTEX_INIT_VALUE
+#define AST_MUTEX_INIT_VALUE_NOTRACKING PTHREAD_MUTEX_INIT_VALUE
 
 
 typedef pthread_mutex_t ast_mutex_t;
@@ -572,8 +586,8 @@
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 /* if AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope
  constrictors/destructors to create/destroy mutexes.  */ 
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE; \
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val; \
 static void  __attribute__ ((constructor)) init_##mutex(void) \
 { \
 	ast_mutex_init(&mutex); \
@@ -598,8 +612,8 @@
  first use.  The performance impact on FreeBSD should be small since
  the pthreads library does this itself to initialize errror checking
  (defaulty type) mutexes.*/ 
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val
 
 static inline int ast_mutex_lock(ast_mutex_t *pmutex)
 {
@@ -615,8 +629,8 @@
 }
 #else
 /* By default, use static initialization of mutexes.*/ 
-#define __AST_MUTEX_DEFINE(scope,mutex) \
-	scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
+#define __AST_MUTEX_DEFINE(scope,mutex,init_val) \
+	scope ast_mutex_t mutex = init_val
 
 static inline int ast_mutex_lock(ast_mutex_t *pmutex)
 {
@@ -678,8 +692,9 @@
 #define pthread_cond_wait use_ast_cond_wait_instead_of_pthread_cond_wait
 #define pthread_cond_timedwait use_ast_cond_wait_instead_of_pthread_cond_timedwait
 
-#define AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static,mutex)
-#define AST_MUTEX_DEFINE_EXPORTED(mutex) __AST_MUTEX_DEFINE(/**/,mutex)
+#define AST_MUTEX_DEFINE_STATIC(mutex) __AST_MUTEX_DEFINE(static,mutex,AST_MUTEX_INIT_VALUE)
+#define AST_MUTEX_DEFINE_STATIC_NOTRACKING(mutex) __AST_MUTEX_DEFINE(static,mutex,AST_MUTEX_INIT_VALUE_NOTRACKING)
+#define AST_MUTEX_DEFINE_EXPORTED(mutex) __AST_MUTEX_DEFINE(/**/,mutex,AST_MUTEX_INIT_VALUE)
 
 #define AST_MUTEX_INITIALIZER __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
 




More information about the svn-commits mailing list