int __ast_rwlock_destroy(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *t) { int res; #ifdef DEBUG_THREADS struct ast_lock_track *lt = t->track; int canlog = t->tracking && strcmp(filename, "logger.c"); #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE) if (t->lock == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) { __ast_mutex_logger("%s line %d (%s): Warning: rwlock '%s' is uninitialized.\n", filename, lineno, func, rwlock_name); DO_THREAD_CRASH; res = EINVAL; goto lt_cleanup; } #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ #endif /* DEBUG_THREADS */ res = pthread_rwlock_destroy(&t->lock); #ifdef DEBUG_THREADS if (res) { __ast_mutex_logger("%s line %d (%s): Error destroying rwlock %s: %s\n", filename, lineno, func, rwlock_name, strerror(res)); } #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE) lt_cleanup: #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ if (lt) { ast_reentrancy_lock(lt); lt->file[0] = filename; lt->lineno[0] = lineno; lt->func[0] = func; lt->reentrancy = 0; lt->thread[0] = 0; #ifdef HAVE_BKTR memset(<->backtrace[0], 0, sizeof(lt->backtrace[0])); #endif ast_reentrancy_unlock(lt); delete_reentrancy_cs(&t->track); } #endif /* DEBUG_THREADS */ return res; }
int __ast_pthread_mutex_destroy(const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t) { int res; #ifdef DEBUG_THREADS struct ast_lock_track *lt; int canlog = strcmp(filename, "logger.c") & t->tracking; #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE) if ((t->mutex) == ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) { /* Don't try to uninitialize non initialized mutex * This may no effect on linux * And always ganerate core on *BSD with * linked libpthread * This not error condition if the mutex created on the fly. */ __ast_mutex_logger("%s line %d (%s): NOTICE: mutex '%s' is uninitialized.\n", filename, lineno, func, mutex_name); return 0; } #endif if (t->tracking && !t->track) { ast_reentrancy_init(&t->track); } lt = t->track; res = pthread_mutex_trylock(&t->mutex); switch (res) { case 0: pthread_mutex_unlock(&t->mutex); break; case EINVAL: __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy invalid mutex '%s'.\n", filename, lineno, func, mutex_name); break; case EBUSY: __ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n", filename, lineno, func, mutex_name); if (t->tracking) { ast_reentrancy_lock(lt); __ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n", lt->file[ROFFSET], lt->lineno[ROFFSET], lt->func[ROFFSET], mutex_name); #ifdef HAVE_BKTR __dump_backtrace(<->backtrace[ROFFSET], canlog); #endif ast_reentrancy_unlock(lt); } break; } #endif /* DEBUG_THREADS */ res = pthread_mutex_destroy(&t->mutex); #ifdef DEBUG_THREADS if (res) { __ast_mutex_logger("%s line %d (%s): Error destroying mutex %s: %s\n", filename, lineno, func, mutex_name, strerror(res)); } if (t->tracking) { ast_reentrancy_lock(lt); lt->file[0] = filename; lt->lineno[0] = lineno; lt->func[0] = func; lt->reentrancy = 0; lt->thread[0] = 0; #ifdef HAVE_BKTR memset(<->backtrace[0], 0, sizeof(lt->backtrace[0])); #endif ast_reentrancy_unlock(lt); delete_reentrancy_cs(&t->track); } #endif /* DEBUG_THREADS */ return res; }