[Asterisk-code-review] Single API for ast store lock info and ast remove lock info. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Mon Oct 23 14:52:27 CDT 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/6888


Change subject: Single API for ast_store_lock_info and ast_remove_lock_info.
......................................................................

Single API for ast_store_lock_info and ast_remove_lock_info.

This makes the 'bt' parameter unconditional for ast_store_lock_info and
ast_remove_lock_info.  The 'bt' parameter is unused when HAVE_BKTR is
undefined.

Change-Id: Ieced0e920928b735a39c3b5952b806c473d67453
---
M include/asterisk/lock.h
M main/lock.c
M main/utils.c
M utils/ael_main.c
M utils/check_expr.c
M utils/conf2ael.c
6 files changed, 16 insertions(+), 125 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/88/6888/1

diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 5b6817f..2191ae6 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -240,13 +240,8 @@
  * lock info struct.  The lock is marked as pending as the thread is waiting
  * on the lock.  ast_mark_lock_acquired() will mark it as held by this thread.
  */
-#ifdef HAVE_BKTR
 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
-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);
-#endif /* HAVE_BKTR */
 
 /*!
  * \brief Mark the last lock as acquired
diff --git a/main/lock.c b/main/lock.c
index 9c1d383..dec814f 100644
--- a/main/lock.c
+++ b/main/lock.c
@@ -245,9 +245,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -268,11 +266,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
-#else
-		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
 #endif
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -346,10 +341,8 @@
 		} else {
 			bt = NULL;
 		}
-		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
 #endif
+		ast_remove_lock_info(t, bt);
 	}
 	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",
@@ -369,9 +362,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -392,11 +383,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
-#else
-		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t);
 #endif
+		ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -433,9 +421,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
 	if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
@@ -483,11 +469,7 @@
 #endif
 		ast_reentrancy_unlock(lt);
 
-#ifdef HAVE_BKTR
 		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
-#endif
 	}
 #endif /* DEBUG_THREADS */
 
@@ -773,9 +755,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 	int lock_found = 0;
 
 #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
@@ -825,11 +805,7 @@
 
 		ast_reentrancy_unlock(lt);
 
-#ifdef HAVE_BKTR
 		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
-#endif
 	}
 #endif /* DEBUG_THREADS */
 
@@ -853,9 +829,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -876,11 +850,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -939,10 +910,8 @@
 		} else {
 			bt = NULL;
 		}
-		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
 #endif
+		ast_remove_lock_info(t, bt);
 	}
 
 	if (res) {
@@ -962,9 +931,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -985,11 +952,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -1048,10 +1012,8 @@
 		} else {
 			bt = NULL;
 		}
-		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
 #endif
+		ast_remove_lock_info(t, bt);
 	}
 	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",
@@ -1071,9 +1033,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -1094,11 +1054,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -1141,10 +1098,8 @@
 		} else {
 			bt = NULL;
 		}
-		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
 #endif
+		ast_remove_lock_info(t, bt);
 	}
 	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
@@ -1164,9 +1119,7 @@
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
 	int canlog = t->tracking && strcmp(filename, "logger.c");
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -1187,11 +1140,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -1234,10 +1184,8 @@
 		} else {
 			bt = NULL;
 		}
-		ast_remove_lock_info(t, bt);
-#else
-		ast_remove_lock_info(t);
 #endif
+		ast_remove_lock_info(t, bt);
 	}
 	if (res) {
 		__ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
@@ -1255,9 +1203,7 @@
 
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -1278,11 +1224,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_RDLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
@@ -1314,9 +1257,7 @@
 
 #ifdef DEBUG_THREADS
 	struct ast_lock_track *lt = NULL;
-#ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
-#endif
 
 	if (t->tracking) {
 		lt = ast_get_reentrancy(&t->track);
@@ -1337,11 +1278,8 @@
 			bt = &lt->backtrace[lt->reentrancy];
 		}
 		ast_reentrancy_unlock(lt);
-
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
-#else
-		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
 #endif
+		ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
 	}
 #endif /* DEBUG_THREADS */
 
diff --git a/main/utils.c b/main/utils.c
index f20ccd3..a73bf9d 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -722,13 +722,8 @@
 AST_THREADSTORAGE_CUSTOM(thread_lock_info, NULL, lock_info_destroy);
 #endif /* ! LOW_MEMORY */
 
-#ifdef HAVE_BKTR
 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
-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)
-#endif
 {
 #if !defined(LOW_MEMORY)
 	struct thr_lock_info *lock_info;
@@ -910,11 +905,7 @@
 }
 
 
-#ifdef HAVE_BKTR
 void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
-#else
-void ast_remove_lock_info(void *lock_addr)
-#endif
 {
 #if !defined(LOW_MEMORY)
 	struct thr_lock_info *lock_info;
diff --git a/utils/ael_main.c b/utils/ael_main.c
index f22e9a0..3a91ef1 100644
--- a/utils/ael_main.c
+++ b/utils/ael_main.c
@@ -601,7 +601,6 @@
 void ast_mark_lock_acquired(void *lock_addr)
 {
 }
-#ifdef HAVE_BKTR
 void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
 {
 }
@@ -611,6 +610,7 @@
 {
 }
 
+#ifdef HAVE_BKTR
 int __ast_bt_get_addresses(struct ast_bt *bt)
 {
 	return 0;
@@ -626,15 +626,6 @@
 		}
 	}
 	return foo;
-}
-#else
-void ast_remove_lock_info(void *lock_addr)
-{
-}
-
-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)
-{
 }
 #endif /* HAVE_BKTR */
 void ast_suspend_lock_info(void *lock_addr)
diff --git a/utils/check_expr.c b/utils/check_expr.c
index 201fa04..e15705e 100644
--- a/utils/check_expr.c
+++ b/utils/check_expr.c
@@ -55,7 +55,6 @@
 #endif
 
 #ifdef DEBUG_THREADS
-#ifdef HAVE_BKTR
 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);
 void ast_store_lock_info(enum ast_lock_type type, const char *filename,
@@ -70,6 +69,7 @@
     /* not a lot to do in a standalone w/o threading! */
 }
 
+#ifdef HAVE_BKTR
 int __ast_bt_get_addresses(struct ast_bt *bt);
 int __ast_bt_get_addresses(struct ast_bt *bt)
 {
@@ -87,20 +87,6 @@
 		}
 	}
 	return foo;
-}
-#else
-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);
-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)
-{
-    /* not a lot to do in a standalone w/o threading! */
-}
-
-void ast_remove_lock_info(void *lock_addr);
-void ast_remove_lock_info(void *lock_addr)
-{
-    /* not a lot to do in a standalone w/o threading! */
 }
 #endif /* HAVE_BKTR */
 
diff --git a/utils/conf2ael.c b/utils/conf2ael.c
index 5fdc570..567dc56 100644
--- a/utils/conf2ael.c
+++ b/utils/conf2ael.c
@@ -699,7 +699,6 @@
 void ast_mark_lock_acquired(void *lock_addr)
 {
 }
-#ifdef HAVE_BKTR
 void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
 {
 }
@@ -709,6 +708,7 @@
 {
 }
 
+#ifdef HAVE_BKTR
 int __ast_bt_get_addresses(struct ast_bt *bt)
 {
 	return 0;
@@ -724,16 +724,6 @@
 		}
 	}
 	return foo;
-}
-
-#else
-void ast_remove_lock_info(void *lock_addr)
-{
-}
-
-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)
-{
 }
 #endif /* HAVE_BKTR */
 void ast_suspend_lock_info(void *lock_addr)

-- 
To view, visit https://gerrit.asterisk.org/6888
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieced0e920928b735a39c3b5952b806c473d67453
Gerrit-Change-Number: 6888
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171023/fe8d9516/attachment-0001.html>


More information about the asterisk-code-review mailing list