From 569e9a8391ab12bbf4274ee2fd6f0e9462a56923 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Mon, 23 Oct 2017 01:55:18 -0400 Subject: 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 --- include/asterisk/lock.h | 9 ----- main/lock.c | 88 ++++++++----------------------------------------- main/utils.c | 9 ----- utils/ael_main.c | 11 +------ utils/check_expr.c | 16 +-------- utils/conf2ael.c | 12 +------ 6 files changed, 16 insertions(+), 129 deletions(-) diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index 5b6817f6b..58c9a8383 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -240,13 +240,8 @@ enum ast_lock_type { * 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 @@ -264,11 +259,7 @@ void ast_mark_lock_failed(void *lock_addr); * this gets called by ast_mutex_unlock so that information on the lock can * be removed from the current thread's lock info struct. */ -#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 /* HAVE_BKTR */ void ast_suspend_lock_info(void *lock_addr); void ast_restore_lock_info(void *lock_addr); diff --git a/main/lock.c b/main/lock.c index 9c1d38383..dec814fb1 100644 --- a/main/lock.c +++ b/main/lock.c @@ -245,9 +245,7 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func, #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 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func, bt = <->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 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func, } 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 @@ int __ast_pthread_mutex_trylock(const char *filename, int lineno, const char *fu #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 @@ int __ast_pthread_mutex_trylock(const char *filename, int lineno, const char *fu bt = <->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 @@ int __ast_pthread_mutex_unlock(const char *filename, int lineno, const char *fun #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 @@ int __ast_pthread_mutex_unlock(const char *filename, int lineno, const char *fun #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 @@ int __ast_rwlock_unlock(const char *filename, int line, const char *func, ast_rw #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 @@ int __ast_rwlock_unlock(const char *filename, int line, const char *func, ast_rw 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 @@ int __ast_rwlock_rdlock(const char *filename, int line, const char *func, ast_rw #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 @@ int __ast_rwlock_rdlock(const char *filename, int line, const char *func, ast_rw bt = <->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 @@ int __ast_rwlock_rdlock(const char *filename, int line, const char *func, ast_rw } 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 @@ int __ast_rwlock_wrlock(const char *filename, int line, const char *func, ast_rw #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 @@ int __ast_rwlock_wrlock(const char *filename, int line, const char *func, ast_rw bt = <->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 @@ int __ast_rwlock_wrlock(const char *filename, int line, const char *func, ast_rw } 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 @@ int __ast_rwlock_timedrdlock(const char *filename, int line, const char *func, a #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 @@ int __ast_rwlock_timedrdlock(const char *filename, int line, const char *func, a bt = <->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 @@ int __ast_rwlock_timedrdlock(const char *filename, int line, const char *func, a } 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 @@ int __ast_rwlock_timedwrlock(const char *filename, int line, const char *func, a #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 @@ int __ast_rwlock_timedwrlock(const char *filename, int line, const char *func, a bt = <->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 @@ int __ast_rwlock_timedwrlock(const char *filename, int line, const char *func, a } 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 @@ int __ast_rwlock_tryrdlock(const char *filename, int line, const char *func, ast #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 @@ int __ast_rwlock_tryrdlock(const char *filename, int line, const char *func, ast bt = <->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 @@ int __ast_rwlock_trywrlock(const char *filename, int line, const char *func, ast #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 @@ int __ast_rwlock_trywrlock(const char *filename, int line, const char *func, ast bt = <->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 f20ccd36e..a73bf9d42 100644 --- a/main/utils.c +++ b/main/utils.c @@ -722,13 +722,8 @@ static void lock_info_destroy(void *data) 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 @@ void ast_restore_lock_info(void *lock_addr) } -#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 f22e9a05b..3a91ef167 100644 --- a/utils/ael_main.c +++ b/utils/ael_main.c @@ -601,7 +601,6 @@ unsigned int ast_hashtab_hash_contexts(const void *obj) 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 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename, { } +#ifdef HAVE_BKTR int __ast_bt_get_addresses(struct ast_bt *bt) { return 0; @@ -627,15 +627,6 @@ char **__ast_bt_get_symbols(void **addresses, size_t num_frames) } 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 201fa04d2..e15705e1b 100644 --- a/utils/check_expr.c +++ b/utils/check_expr.c @@ -55,7 +55,6 @@ void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, i #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 @@ void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt) /* 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) { @@ -88,20 +88,6 @@ char **__ast_bt_get_symbols(void **addresses, size_t num_frames) } 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 */ void ast_suspend_lock_info(void *lock_addr) diff --git a/utils/conf2ael.c b/utils/conf2ael.c index 5fdc570a0..567dc56f1 100644 --- a/utils/conf2ael.c +++ b/utils/conf2ael.c @@ -699,7 +699,6 @@ unsigned int ast_hashtab_hash_contexts(const void *obj) 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 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename, { } +#ifdef HAVE_BKTR int __ast_bt_get_addresses(struct ast_bt *bt) { return 0; @@ -725,16 +725,6 @@ char **__ast_bt_get_symbols(void **addresses, size_t num_frames) } 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) { -- cgit v1.2.3