<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10521">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
George Joseph: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">lock: Replace __ast_mutex_logger with private log_mutex_error.<br><br>__ast_mutex_logger used the variable `canlog` without accepting it as a<br>argument. Replace with internal macro `log_mutex_error` which takes<br>canlog as the first arguement. This will prevent confusion when working<br>with lock.c code, many of the function declare the canlog variable and<br>in some cases it previously appeared to be unused.<br><br>Change-Id: I83b372cb0654c5c18eadc512f65a57fa6c2e9853<br>---<br>M include/asterisk/lock.h<br>M main/lock.c<br>M utils/extconf.c<br>3 files changed, 73 insertions(+), 64 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h</span><br><span>index 5b596d2..a59132e 100644</span><br><span>--- a/include/asterisk/lock.h</span><br><span>+++ b/include/asterisk/lock.h</span><br><span>@@ -241,8 +241,6 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define __ast_mutex_logger(...) do { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); } while (0)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #ifdef THREAD_CRASH</span><br><span> #define DO_THREAD_CRASH do { *((int *)(0)) = 1; } while(0)</span><br><span> #else</span><br><span>diff --git a/main/lock.c b/main/lock.c</span><br><span>index 23dff4f..b0c2d65 100644</span><br><span>--- a/main/lock.c</span><br><span>+++ b/main/lock.c</span><br><span>@@ -46,6 +46,17 @@</span><br><span> #undef pthread_cond_wait</span><br><span> #undef pthread_cond_timedwait</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#if defined(DEBUG_THREADS)</span><br><span style="color: hsl(120, 100%, 40%);">+#define log_mutex_error(canlog, ...) \</span><br><span style="color: hsl(120, 100%, 40%);">+ do { \</span><br><span style="color: hsl(120, 100%, 40%);">+ if (canlog) { \</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, __VA_ARGS__); \</span><br><span style="color: hsl(120, 100%, 40%);">+ } else { \</span><br><span style="color: hsl(120, 100%, 40%);">+ fprintf(stderr, __VA_ARGS__); \</span><br><span style="color: hsl(120, 100%, 40%);">+ } \</span><br><span style="color: hsl(120, 100%, 40%);">+ } while (0)</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #if defined(DEBUG_THREADS) && defined(HAVE_BKTR)</span><br><span> static void __dump_backtrace(struct ast_bt *bt, int canlog)</span><br><span> {</span><br><span>@@ -55,7 +66,7 @@</span><br><span> strings = backtrace_symbols(bt->addresses, bt->num_frames);</span><br><span> </span><br><span> for (i = 0; i < bt->num_frames; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s\n", strings[i]);</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s\n", strings[i]);</span><br><span> }</span><br><span> </span><br><span> ast_std_free(strings);</span><br><span>@@ -134,7 +145,7 @@</span><br><span> if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span> int canlog = tracking && strcmp(filename, "logger.c");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): NOTICE: mutex '%s' is already initialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EBUSY;</span><br><span>@@ -171,7 +182,7 @@</span><br><span> * linked with libpthread.</span><br><span> * This is not an error condition if the mutex is created on the fly.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> res = EINVAL;</span><br><span>@@ -185,15 +196,15 @@</span><br><span> pthread_mutex_unlock(&t->mutex);</span><br><span> break;</span><br><span> case EINVAL:</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> break;</span><br><span> case EBUSY:</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: '%s' was locked here.\n",</span><br><span> lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[ROFFSET], canlog);</span><br><span>@@ -208,7 +219,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error destroying mutex %s: %s\n",</span><br><span> filename, lineno, func, mutex_name, strerror(res));</span><br><span> }</span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span>@@ -282,14 +293,14 @@</span><br><span> if (res == EBUSY) {</span><br><span> wait_time = time(NULL) - seconds;</span><br><span> if (wait_time > reported_wait && (wait_time % 5) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",</span><br><span> filename, lineno, func, (int) wait_time, mutex_name);</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[lt->reentrancy], canlog);</span><br><span> #endif</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[ROFFSET], lt->lineno[ROFFSET],</span><br><span> lt->func[ROFFSET], mutex_name);</span><br><span> #ifdef HAVE_BKTR</span><br><span>@@ -323,7 +334,7 @@</span><br><span> lt->thread_id[lt->reentrancy] = pthread_self();</span><br><span> lt->reentrancy++;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> ast_reentrancy_unlock(lt);</span><br><span>@@ -343,7 +354,7 @@</span><br><span> #endif</span><br><span> }</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining mutex: %s\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -399,7 +410,7 @@</span><br><span> lt->thread_id[lt->reentrancy] = pthread_self();</span><br><span> lt->reentrancy++;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> ast_reentrancy_unlock(lt);</span><br><span>@@ -426,7 +437,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EINVAL;</span><br><span>@@ -437,9 +448,9 @@</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[ROFFSET], canlog);</span><br><span>@@ -448,7 +459,7 @@</span><br><span> }</span><br><span> </span><br><span> if (--lt->reentrancy < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): mutex '%s' freed more times than we've locked!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> lt->reentrancy = 0;</span><br><span> }</span><br><span>@@ -479,7 +490,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error releasing mutex: %s\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -549,7 +560,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EINVAL;</span><br><span>@@ -560,16 +571,16 @@</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[ROFFSET], canlog);</span><br><span> #endif</span><br><span> DO_THREAD_CRASH;</span><br><span> } else if (lt->reentrancy <= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -589,7 +600,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error waiting on condition mutex '%s'\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> } else if (lt) {</span><br><span>@@ -614,7 +625,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EINVAL;</span><br><span>@@ -625,16 +636,16 @@</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> if (lt->reentrancy && (lt->thread_id[ROFFSET] != pthread_self())) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted wait using mutex '%s' without owning it!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[ROFFSET], canlog);</span><br><span> #endif</span><br><span> DO_THREAD_CRASH;</span><br><span> } else if (lt->reentrancy <= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted wait using an unlocked mutex '%s'\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -654,7 +665,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res && (res != ETIMEDOUT)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error waiting on condition mutex '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error waiting on condition mutex '%s'\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> } else if (lt) {</span><br><span>@@ -676,7 +687,7 @@</span><br><span> if (t->lock != ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {</span><br><span> int canlog = tracking && strcmp(filename, "logger.c");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is already initialized.\n",</span><br><span> filename, lineno, func, rwlock_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EBUSY;</span><br><span>@@ -708,7 +719,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span> if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, rwlock_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> res = EINVAL;</span><br><span>@@ -721,7 +732,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error destroying rwlock %s: %s\n",</span><br><span> filename, lineno, func, rwlock_name, strerror(res));</span><br><span> }</span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span>@@ -759,7 +770,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)</span><br><span> if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n",</span><br><span> filename, line, func, name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return EINVAL;</span><br><span>@@ -794,7 +805,7 @@</span><br><span> }</span><br><span> </span><br><span> if (lock_found && --lt->reentrancy < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): rwlock '%s' freed more times than we've locked!\n",</span><br><span> filename, line, func, name);</span><br><span> lt->reentrancy = 0;</span><br><span> }</span><br><span>@@ -813,7 +824,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error releasing rwlock: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error releasing rwlock: %s\n",</span><br><span> filename, line, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -865,14 +876,14 @@</span><br><span> if (res == EBUSY) {</span><br><span> wait_time = time(NULL) - seconds;</span><br><span> if (wait_time > reported_wait && (wait_time % 5) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for readlock '%s'?\n",</span><br><span> filename, line, func, (int)wait_time, name);</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[lt->reentrancy], canlog);</span><br><span> #endif</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],</span><br><span> lt->func[lt->reentrancy-1], name);</span><br><span> #ifdef HAVE_BKTR</span><br><span>@@ -918,7 +929,7 @@</span><br><span> }</span><br><span> </span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span> filename, line, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -970,14 +981,14 @@</span><br><span> if (res == EBUSY) {</span><br><span> wait_time = time(NULL) - seconds;</span><br><span> if (wait_time > reported_wait && (wait_time % 5) == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for writelock '%s'?\n",</span><br><span> filename, line, func, (int)wait_time, name);</span><br><span> if (lt) {</span><br><span> ast_reentrancy_lock(lt);</span><br><span> #ifdef HAVE_BKTR</span><br><span> __dump_backtrace(<->backtrace[lt->reentrancy], canlog);</span><br><span> #endif</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> lt->file[lt->reentrancy-1], lt->lineno[lt->reentrancy-1],</span><br><span> lt->func[lt->reentrancy-1], name);</span><br><span> #ifdef HAVE_BKTR</span><br><span>@@ -1022,7 +1033,7 @@</span><br><span> #endif</span><br><span> }</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining write lock: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining write lock: %s\n",</span><br><span> filename, line, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -1111,7 +1122,7 @@</span><br><span> #endif</span><br><span> }</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span> filename, line, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -1200,7 +1211,7 @@</span><br><span> #endif</span><br><span> }</span><br><span> if (res) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining read lock: %s\n",</span><br><span> filename, line, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>diff --git a/utils/extconf.c b/utils/extconf.c</span><br><span>index a080aae..1a80f66 100644</span><br><span>--- a/utils/extconf.c</span><br><span>+++ b/utils/extconf.c</span><br><span>@@ -198,7 +198,7 @@</span><br><span> </span><br><span> #ifdef DEBUG_THREADS</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define __ast_mutex_logger(...) do { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); } while (0)</span><br><span style="color: hsl(120, 100%, 40%);">+#define log_mutex_error(canlog, ...) do { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); } while (0)</span><br><span> </span><br><span> #ifdef THREAD_CRASH</span><br><span> #define DO_THREAD_CRASH do { *((int *)(0)) = 1; } while(0)</span><br><span>@@ -241,9 +241,9 @@</span><br><span> </span><br><span> if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span> if ((t->mutex) != (empty_mutex)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is already initialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is already initialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: previously initialization of mutex '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: previously initialization of mutex '%s'.\n",</span><br><span> t->file[0], t->lineno[0], t->func[0], mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> return 0;</span><br><span>@@ -280,7 +280,7 @@</span><br><span> </span><br><span> #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> #endif</span><br><span>@@ -291,19 +291,19 @@</span><br><span> pthread_mutex_unlock(&t->mutex);</span><br><span> break;</span><br><span> case EINVAL:</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> break;</span><br><span> case EBUSY:</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: '%s' was locked here.\n",</span><br><span> t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span> if ((res = pthread_mutex_destroy(&t->mutex)))</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error destroying mutex: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error destroying mutex: %s\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP</span><br><span> else</span><br><span>@@ -324,7 +324,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> ast_mutex_init(t);</span><br><span> }</span><br><span>@@ -345,9 +345,9 @@</span><br><span> if (res == EBUSY) {</span><br><span> current = time(NULL);</span><br><span> if ((current - seconds) && (!((current - seconds) % 5))) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",</span><br><span> filename, lineno, func, (int)(current - seconds), mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> t->file[t->reentrancy-1], t->lineno[t->reentrancy-1],</span><br><span> t->func[t->reentrancy-1], mutex_name);</span><br><span> }</span><br><span>@@ -373,11 +373,11 @@</span><br><span> t->thread[t->reentrancy] = pthread_self();</span><br><span> t->reentrancy++;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error obtaining mutex: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error obtaining mutex: %s\n",</span><br><span> filename, lineno, func, strerror(errno));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span>@@ -393,7 +393,7 @@</span><br><span> </span><br><span> #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> ast_mutex_init(t);</span><br><span> }</span><br><span>@@ -407,11 +407,11 @@</span><br><span> t->thread[t->reentrancy] = pthread_self();</span><br><span> t->reentrancy++;</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' really deep reentrancy!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Warning: '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Warning: '%s' was locked here.\n",</span><br><span> t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);</span><br><span> }</span><br><span> </span><br><span>@@ -426,21 +426,21 @@</span><br><span> </span><br><span> #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS</span><br><span> if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error: mutex '%s' is uninitialized.\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> }</span><br><span> #endif</span><br><span> </span><br><span> if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): '%s' was locked here.\n",</span><br><span> t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span> </span><br><span> if (--t->reentrancy < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): mutex '%s' freed more times than we've locked!\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): mutex '%s' freed more times than we've locked!\n",</span><br><span> filename, lineno, func, mutex_name);</span><br><span> t->reentrancy = 0;</span><br><span> }</span><br><span>@@ -453,7 +453,7 @@</span><br><span> }</span><br><span> </span><br><span> if ((res = pthread_mutex_unlock(&t->mutex))) {</span><br><span style="color: hsl(0, 100%, 40%);">- __ast_mutex_logger("%s line %d (%s): Error releasing mutex: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ log_mutex_error(canlog, "%s line %d (%s): Error releasing mutex: %s\n",</span><br><span> filename, lineno, func, strerror(res));</span><br><span> DO_THREAD_CRASH;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10521">change 10521</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10521"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I83b372cb0654c5c18eadc512f65a57fa6c2e9853 </div>
<div style="display:none"> Gerrit-Change-Number: 10521 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>