<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10520">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 b409a27..3cf6f16 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 5ad9e13..fcf0839 100644</span><br><span>--- a/main/lock.c</span><br><span>+++ b/main/lock.c</span><br><span>@@ -53,6 +53,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>@@ -62,7 +73,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>@@ -141,7 +152,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>@@ -178,7 +189,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>@@ -192,15 +203,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(&lt->backtrace[ROFFSET], canlog);</span><br><span>@@ -215,7 +226,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>@@ -284,14 +295,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(&lt->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>@@ -325,7 +336,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>             ast_remove_lock_info(t, bt);</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>@@ -394,7 +405,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>@@ -419,7 +430,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>@@ -430,9 +441,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(&lt->backtrace[ROFFSET], canlog);</span><br><span>@@ -441,7 +452,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>@@ -468,7 +479,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>@@ -538,7 +549,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>@@ -549,16 +560,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(&lt->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>@@ -578,7 +589,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>@@ -603,7 +614,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>@@ -614,16 +625,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(&lt->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>@@ -643,7 +654,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>@@ -665,7 +676,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>@@ -697,7 +708,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>@@ -710,7 +721,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>@@ -746,7 +757,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>@@ -781,7 +792,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>@@ -796,7 +807,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>@@ -843,14 +854,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(&lt->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>@@ -894,7 +905,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>@@ -941,14 +952,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(&lt->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>@@ -991,7 +1002,7 @@</span><br><span>          ast_remove_lock_info(t, bt);</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>@@ -1073,7 +1084,7 @@</span><br><span>            ast_remove_lock_info(t, bt);</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>@@ -1155,7 +1166,7 @@</span><br><span>            ast_remove_lock_info(t, bt);</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 2beaef4..129dcc8 100644</span><br><span>--- a/utils/extconf.c</span><br><span>+++ b/utils/extconf.c</span><br><span>@@ -196,7 +196,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>@@ -239,9 +239,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>@@ -278,7 +278,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>@@ -289,19 +289,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>@@ -322,7 +322,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>@@ -343,9 +343,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>@@ -371,11 +371,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>@@ -391,7 +391,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>@@ -405,11 +405,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>@@ -424,21 +424,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>@@ -451,7 +451,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/10520">change 10520</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/10520"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </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: 10520 </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: 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>