[asterisk-commits] mmichelson: branch mmichelson/lock_backtraces r115356 - in /team/mmichelson/l...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 6 12:53:25 CDT 2008


Author: mmichelson
Date: Tue May  6 12:53:25 2008
New Revision: 115356

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115356
Log:
Progress commit for adding HAVE_BKTR to files. Done with logger.[hc] and
halfway through lock.h


Modified:
    team/mmichelson/lock_backtraces/include/asterisk/lock.h
    team/mmichelson/lock_backtraces/include/asterisk/logger.h
    team/mmichelson/lock_backtraces/main/logger.c

Modified: team/mmichelson/lock_backtraces/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/team/mmichelson/lock_backtraces/include/asterisk/lock.h?view=diff&rev=115356&r1=115355&r2=115356
==============================================================================
--- team/mmichelson/lock_backtraces/include/asterisk/lock.h (original)
+++ team/mmichelson/lock_backtraces/include/asterisk/lock.h Tue May  6 12:53:25 2008
@@ -127,7 +127,9 @@
 	int reentrancy;
 	const char *func[AST_MAX_REENTRANCY];
 	pthread_t thread[AST_MAX_REENTRANCY];
+#ifdef HAVE_BKTR
 	struct ast_bt backtrace[AST_MAX_REENTRANCY];
+#endif
 	pthread_mutex_t reentr_mutex;
 };
 
@@ -153,11 +155,21 @@
  */
 #if !defined(LOW_MEMORY)
 void ast_store_lock_info(enum ast_lock_type type, const char *filename,
-	int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt);
-#else
-#define ast_store_lock_info(I,DONT,CARE,ABOUT,THE,PARAMETERS,BITCH)
-#endif
-
+	int line_num, const char *func, const char *lock_name, void *lock_addr
+#ifdef HAVE_BKTR
+	, struct ast_bt *bt);
+#else
+	);
+#endif /* HAVE_BKTR */
+
+#else
+#define ast_store_lock_info(I,DONT,CARE,ABOUT,THE,PARAMETERS
+#ifdef HAVE_BKTR
+,BUD)
+#else
+)
+#endif /* HAVE_BKTR */
+#endif /* !defined(LOW_MEMORY) */
 
 /*!
  * \brief Mark the last lock as acquired
@@ -184,11 +196,22 @@
  * be removed from the current thread's lock info struct.
  */
 #if !defined(LOW_MEMORY)
-void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt);
-#else
-#define ast_remove_lock_info(ignore,me)
-#endif
-
+void ast_remove_lock_info(void *lock_addr
+#ifdef HAVE_BKTR
+, struct ast_bt *bt);
+#else
+);
+#endif /* HAVE_BKTR */
+#else
+#define ast_remove_lock_info(ignore
+#ifdef HAVE_BKTR
+,me)
+#else
+)
+#endif /* HAVE_BKTR */
+#endif /* !defined(LOW_MEMORY) */
+
+#ifdef HAVE_BKTR
 static inline void __dump_backtrace(struct ast_bt *bt, int canlog)
 {
 	char **strings;
@@ -202,6 +225,7 @@
 
 	free(strings);
 }
+#endif
 
 /*!
  * \brief log info for the current lock with ast_log().
@@ -238,7 +262,9 @@
 		p_ast_mutex->lineno[i] = 0;
 		p_ast_mutex->func[i] = NULL;
 		p_ast_mutex->thread[i] = 0;
+#ifdef HAVE_BKTR
 		memset(&p_ast_mutex->backtrace[i], 0, sizeof(p_ast_mutex->backtrace[i]));
+#endif
 	}
 
 	p_ast_mutex->reentrancy = 0;
@@ -324,7 +350,9 @@
 		ast_reentrancy_lock(t);
 		__ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
 			    t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
+#ifdef HAVE_BKTR
 		__dump_backtrace(&t->backtrace[t->reentrancy-1], canlog);
+#endif
 		ast_reentrancy_unlock(t);
 		break;
 	}
@@ -342,7 +370,9 @@
 	t->func[0] = func;
 	t->reentrancy = 0;
 	t->thread[0] = 0;
+#ifdef HAVE_BKTR
 	memset(&t->backtrace[0], 0, sizeof(t->backtrace[0]));
+#endif
 	ast_reentrancy_unlock(t);
 	delete_reentrancy_cs(t);
 
@@ -354,7 +384,9 @@
 {
 	int res;
 	int canlog = strcmp(filename, "logger.c") & t->track;
+#if HAVE_BKTR
 	struct ast_bt *bt = NULL;
+#endif
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -372,11 +404,15 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	if (t->track) {
+#ifdef HAVE_BKTR
 		ast_reentrancy_lock(t);
 		ast_bt_get_addresses(&t->backtrace[t->reentrancy]);
 		bt = &t->backtrace[t->reentrancy];
 		ast_reentrancy_unlock(t);
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex, bt);
+#else
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
+#endif
 	}
 
 #ifdef DETECT_DEADLOCKS
@@ -397,11 +433,15 @@
 					__ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
 							   filename, lineno, func, (int) wait_time, mutex_name);
 					ast_reentrancy_lock(t);
+#ifdef HAVE_BKTR
 					__dump_backtrace(&t->backtrace[t->reentrancy], canlog);
+#endif
 					__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
 							   t->file[t->reentrancy-1], t->lineno[t->reentrancy-1],
 							   t->func[t->reentrancy-1], mutex_name);
+#ifdef HAVE_BKTR
 					__dump_backtrace(&t->backtrace[t->reentrancy-1], canlog);
+#endif
 					ast_reentrancy_unlock(t);
 					reported_wait = wait_time;
 				}
@@ -435,6 +475,7 @@
 		if (t->track)
 			ast_mark_lock_acquired(&t->mutex);
 	} else {
+#ifdef HAVE_BKTR
 		if (t->reentrancy) {
 			ast_reentrancy_lock(t);
 			bt = &t->backtrace[t->reentrancy-1];
@@ -444,6 +485,10 @@
 		}
 		if (t->track)
 			ast_remove_lock_info(&t->mutex, bt);
+#else
+		if (t->track)
+			ast_remove_lock_info(&t->mutex);
+#endif
 		__ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
 				   filename, lineno, func, strerror(res));
 		DO_THREAD_CRASH;
@@ -457,7 +502,9 @@
 {
 	int res;
 	int canlog = strcmp(filename, "logger.c") & t->track;
+#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
+#endif
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -475,11 +522,15 @@
 #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
 
 	if (t->track) {
+#ifdef HAVE_BKTR
 		ast_reentrancy_lock(t);
 		ast_bt_get_addresses(&t->backtrace[t->reentrancy]);
 		bt = &t->backtrace[t->reentrancy];
 		ast_reentrancy_unlock(t);
 		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex, bt);
+#else
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
+#endif
 	}
 
 	if (!(res = pthread_mutex_trylock(&t->mutex))) {
@@ -530,7 +581,9 @@
 				   filename, lineno, func, mutex_name);
 		__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
 				   t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
+#ifdef HAVE_BKTR
 		__dump_backtrace(&t->backtrace[t->reentrancy-1], canlog);
+#endif
 		DO_THREAD_CRASH;
 	}
 
@@ -547,15 +600,20 @@
 		t->thread[t->reentrancy] = 0;
 	}
 
+#ifdef HAVE_BKTR
 	if (t->reentrancy) {
 		bt = &t->backtrace[t->reentrancy - 1];
 	}
-
+#endif
 	ast_reentrancy_unlock(t);
 
-	if (t->track)
+	if (t->track) {
+#ifdef HAVE_BKTR
 		ast_remove_lock_info(&t->mutex, bt);
-
+#else
+		ast_remove_lock_info(&t->mutex);
+#endif
+	}
 	if ((res = pthread_mutex_unlock(&t->mutex))) {
 		__ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n", 
 				   filename, lineno, func, strerror(res));
@@ -595,7 +653,9 @@
 {
 	int res;
 	int canlog = strcmp(filename, "logger.c") & t->track;
+#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
+#endif
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -616,7 +676,9 @@
 				   filename, lineno, func, mutex_name);
 		__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
 				   t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
+#ifdef HAVE_BKTR
 		__dump_backtrace(&t->backtrace[t->reentrancy-1], canlog);
+#endif
 		DO_THREAD_CRASH;
 	}
 
@@ -633,28 +695,36 @@
 		t->thread[t->reentrancy] = 0;
 	}
 
+#ifdef HAVE_BKTR
 	if (t->reentrancy) {
 		bt = &t->backtrace[t->reentrancy - 1];
 	}
+#endif
 	ast_reentrancy_unlock(t);
 
-	if (t->track)
+	if (t->track) {
+#ifdef HAVE_BKTR
 		ast_remove_lock_info(&t->mutex, bt);
+#else
+		ast_remove_lock_info(&t->mutex);
+#endif
+	}
 
 	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));
 		DO_THREAD_CRASH;
 	} else {
-		struct ast_bt *bt = NULL;
 		ast_reentrancy_lock(t);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
 			t->func[t->reentrancy] = func;
 			t->thread[t->reentrancy] = pthread_self();
+#ifdef HAVE_BKTR
 			ast_bt_get_addresses(&t->backtrace[t->reentrancy]);
 			bt = &t->backtrace[t->reentrancy];
+#endif
 			t->reentrancy++;
 		} else {
 			__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
@@ -662,8 +732,13 @@
 		}
 		ast_reentrancy_unlock(t);
 
-		if (t->track)
+		if (t->track) {
+#ifdef HAVE_BKTR
 			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex, bt);
+#else
+			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
+#endif
+		}
 	}
 
 	return res;
@@ -675,7 +750,9 @@
 {
 	int res;
 	int canlog = strcmp(filename, "logger.c") & t->track;
+#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
+#endif
 
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -696,7 +773,9 @@
 				   filename, lineno, func, mutex_name);
 		__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
 				   t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
+#ifdef HAVE_BKTR
 		__dump_backtrace(&t->backtrace[t->reentrancy-1], canlog);
+#endif
 		DO_THREAD_CRASH;
 	}
 
@@ -712,29 +791,35 @@
 		t->func[t->reentrancy] = NULL;
 		t->thread[t->reentrancy] = 0;
 	}
-
+#ifdef HAVE_BKTR
 	if (t->reentrancy) {
 		bt = &t->backtrace[t->reentrancy - 1];
 	}
+#endif
 	ast_reentrancy_unlock(t);
 
 	if (t->track)
+#ifdef HAVE_BKTR
 		ast_remove_lock_info(&t->mutex, bt);
+#else
+		ast_remove_lock_info(&t->mutex);
+#endif
 
 	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));
 		DO_THREAD_CRASH;
 	} else {
-		struct ast_bt *bt = NULL;
 		ast_reentrancy_lock(t);
 		if (t->reentrancy < AST_MAX_REENTRANCY) {
 			t->file[t->reentrancy] = filename;
 			t->lineno[t->reentrancy] = lineno;
 			t->func[t->reentrancy] = func;
 			t->thread[t->reentrancy] = pthread_self();
+#ifdef HAVE_BKTR
 			ast_bt_get_addresses(&t->backtrace[t->reentrancy]);
 			bt = &t->backtrace[t->reentrancy];
+#endif
 			t->reentrancy++;
 		} else {
 			__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
@@ -742,8 +827,13 @@
 		}
 		ast_reentrancy_unlock(t);
 
-		if (t->track)
+		if (t->track) {
+#ifdef HAVE_BKTR
 			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex, bt);
+#else
+			ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
+#endif
+		}
 	}
 
 	return res;

Modified: team/mmichelson/lock_backtraces/include/asterisk/logger.h
URL: http://svn.digium.com/view/asterisk/team/mmichelson/lock_backtraces/include/asterisk/logger.h?view=diff&rev=115356&r1=115355&r2=115356
==============================================================================
--- team/mmichelson/lock_backtraces/include/asterisk/logger.h (original)
+++ team/mmichelson/lock_backtraces/include/asterisk/logger.h Tue May  6 12:53:25 2008
@@ -217,7 +217,7 @@
 	} \
 } while (0)
 
-
+#ifdef HAVE_BKTR
 #define AST_MAX_BT_FRAMES 32
 /* I'd like to call this ast_backtrace, but that name is already taken by a function */
 /* \brief
@@ -236,6 +236,8 @@
 
 void *ast_bt_destroy(struct ast_bt *bt);
 
+#endif /* HAVE_BKTR */
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/mmichelson/lock_backtraces/main/logger.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/lock_backtraces/main/logger.c?view=diff&rev=115356&r1=115355&r2=115356
==============================================================================
--- team/mmichelson/lock_backtraces/main/logger.c (original)
+++ team/mmichelson/lock_backtraces/main/logger.c Tue May  6 12:53:25 2008
@@ -1127,6 +1127,8 @@
 	return;
 }
 
+#ifdef HAVE_BKTR
+
 /* \brief
  * Allocates memory for an ast_bt and stores addresses and symbols.
  *
@@ -1173,6 +1175,8 @@
 
 	return NULL;
 }
+
+#endif /* HAVE_BKTR */
 
 void ast_backtrace(void)
 {




More information about the asterisk-commits mailing list