mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 12:20:12 +00:00
Merged revisions 87396 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r87396 | russell | 2007-10-29 15:22:07 -0500 (Mon, 29 Oct 2007) | 5 lines Add some more details to the output of "core show locks". When a thread is waiting for a lock, this will now show the details about who currently has it locked. (inspired by issue #11100) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@87397 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -167,17 +167,17 @@ static void __attribute__((constructor)) init_empty_mutex(void)
|
|||||||
memset(&empty_mutex, 0, sizeof(empty_mutex));
|
memset(&empty_mutex, 0, sizeof(empty_mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void reentrancy_lock_cs(ast_mutex_t *p_ast_mutex)
|
static inline void ast_reentrancy_lock(ast_mutex_t *p_ast_mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&p_ast_mutex->reentr_mutex);
|
pthread_mutex_lock(&p_ast_mutex->reentr_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void reentrancy_unlock_cs(ast_mutex_t *p_ast_mutex)
|
static inline void ast_reentrancy_unlock(ast_mutex_t *p_ast_mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&p_ast_mutex->reentr_mutex);
|
pthread_mutex_unlock(&p_ast_mutex->reentr_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void init_reentrancy_cs(ast_mutex_t *p_ast_mutex)
|
static inline void ast_reentrancy_init(ast_mutex_t *p_ast_mutex)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
static pthread_mutexattr_t reentr_attr;
|
static pthread_mutexattr_t reentr_attr;
|
||||||
@@ -225,7 +225,7 @@ static inline int __ast_pthread_mutex_init_attr(int track, const char *filename,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
init_reentrancy_cs(t);
|
ast_reentrancy_init(t);
|
||||||
t->track = track;
|
t->track = track;
|
||||||
|
|
||||||
return pthread_mutex_init(&t->mutex, attr);
|
return pthread_mutex_init(&t->mutex, attr);
|
||||||
@@ -272,10 +272,10 @@ static inline int __ast_pthread_mutex_destroy(const char *filename, int lineno,
|
|||||||
case EBUSY:
|
case EBUSY:
|
||||||
__ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
|
__ast_mutex_logger("%s line %d (%s): Error: attempt to destroy locked mutex '%s'.\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
__ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
|
__ast_mutex_logger("%s line %d (%s): Error: '%s' was locked here.\n",
|
||||||
t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
|
t->file[t->reentrancy-1], t->lineno[t->reentrancy-1], t->func[t->reentrancy-1], mutex_name);
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,13 +286,13 @@ static inline int __ast_pthread_mutex_destroy(const char *filename, int lineno,
|
|||||||
else
|
else
|
||||||
t->mutex = PTHREAD_MUTEX_INIT_VALUE;
|
t->mutex = PTHREAD_MUTEX_INIT_VALUE;
|
||||||
#endif
|
#endif
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
t->file[0] = filename;
|
t->file[0] = filename;
|
||||||
t->lineno[0] = lineno;
|
t->lineno[0] = lineno;
|
||||||
t->func[0] = func;
|
t->func[0] = func;
|
||||||
t->reentrancy = 0;
|
t->reentrancy = 0;
|
||||||
t->thread[0] = 0;
|
t->thread[0] = 0;
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
delete_reentrancy_cs(t);
|
delete_reentrancy_cs(t);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -335,11 +335,11 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
|
|||||||
if ((current - seconds) && (!((current - seconds) % 5))) {
|
if ((current - seconds) && (!((current - seconds) % 5))) {
|
||||||
__ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
|
__ast_mutex_logger("%s line %d (%s): Deadlock? waited %d sec for mutex '%s'?\n",
|
||||||
filename, lineno, func, (int)(current - seconds), mutex_name);
|
filename, lineno, func, (int)(current - seconds), mutex_name);
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
|
__ast_mutex_logger("%s line %d (%s): '%s' was locked here.\n",
|
||||||
t->file[t->reentrancy-1], t->lineno[t->reentrancy-1],
|
t->file[t->reentrancy-1], t->lineno[t->reentrancy-1],
|
||||||
t->func[t->reentrancy-1], mutex_name);
|
t->func[t->reentrancy-1], mutex_name);
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
}
|
}
|
||||||
usleep(200);
|
usleep(200);
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
|
|||||||
#endif /* DETECT_DEADLOCKS */
|
#endif /* DETECT_DEADLOCKS */
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
||||||
t->file[t->reentrancy] = filename;
|
t->file[t->reentrancy] = filename;
|
||||||
t->lineno[t->reentrancy] = lineno;
|
t->lineno[t->reentrancy] = lineno;
|
||||||
@@ -367,7 +367,7 @@ static inline int __ast_pthread_mutex_lock(const char *filename, int lineno, con
|
|||||||
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_mark_lock_acquired();
|
ast_mark_lock_acquired();
|
||||||
} else {
|
} else {
|
||||||
@@ -401,7 +401,7 @@ static inline int __ast_pthread_mutex_trylock(const char *filename, int lineno,
|
|||||||
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
||||||
|
|
||||||
if (!(res = pthread_mutex_trylock(&t->mutex))) {
|
if (!(res = pthread_mutex_trylock(&t->mutex))) {
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
||||||
t->file[t->reentrancy] = filename;
|
t->file[t->reentrancy] = filename;
|
||||||
t->lineno[t->reentrancy] = lineno;
|
t->lineno[t->reentrancy] = lineno;
|
||||||
@@ -412,7 +412,7 @@ static inline int __ast_pthread_mutex_trylock(const char *filename, int lineno,
|
|||||||
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_mark_lock_acquired();
|
ast_mark_lock_acquired();
|
||||||
} else if (t->track) {
|
} else if (t->track) {
|
||||||
@@ -437,7 +437,7 @@ static inline int __ast_pthread_mutex_unlock(const char *filename, int lineno, c
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
||||||
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
@@ -458,7 +458,7 @@ static inline int __ast_pthread_mutex_unlock(const char *filename, int lineno, c
|
|||||||
t->func[t->reentrancy] = NULL;
|
t->func[t->reentrancy] = NULL;
|
||||||
t->thread[t->reentrancy] = 0;
|
t->thread[t->reentrancy] = 0;
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
|
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_remove_lock_info(&t->mutex);
|
ast_remove_lock_info(&t->mutex);
|
||||||
@@ -511,7 +511,7 @@ static inline int __ast_cond_wait(const char *filename, int lineno, const char *
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
||||||
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
@@ -532,7 +532,7 @@ static inline int __ast_cond_wait(const char *filename, int lineno, const char *
|
|||||||
t->func[t->reentrancy] = NULL;
|
t->func[t->reentrancy] = NULL;
|
||||||
t->thread[t->reentrancy] = 0;
|
t->thread[t->reentrancy] = 0;
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
|
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_remove_lock_info(&t->mutex);
|
ast_remove_lock_info(&t->mutex);
|
||||||
@@ -542,7 +542,7 @@ static inline int __ast_cond_wait(const char *filename, int lineno, const char *
|
|||||||
filename, lineno, func, strerror(res));
|
filename, lineno, func, strerror(res));
|
||||||
DO_THREAD_CRASH;
|
DO_THREAD_CRASH;
|
||||||
} else {
|
} else {
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
||||||
t->file[t->reentrancy] = filename;
|
t->file[t->reentrancy] = filename;
|
||||||
t->lineno[t->reentrancy] = lineno;
|
t->lineno[t->reentrancy] = lineno;
|
||||||
@@ -553,7 +553,7 @@ static inline int __ast_cond_wait(const char *filename, int lineno, const char *
|
|||||||
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
|
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
||||||
@@ -577,7 +577,7 @@ static inline int __ast_cond_timedwait(const char *filename, int lineno, const c
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
if (t->reentrancy && (t->thread[t->reentrancy-1] != pthread_self())) {
|
||||||
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
__ast_mutex_logger("%s line %d (%s): attempted unlock mutex '%s' without owning it!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
@@ -598,7 +598,7 @@ static inline int __ast_cond_timedwait(const char *filename, int lineno, const c
|
|||||||
t->func[t->reentrancy] = NULL;
|
t->func[t->reentrancy] = NULL;
|
||||||
t->thread[t->reentrancy] = 0;
|
t->thread[t->reentrancy] = 0;
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
|
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_remove_lock_info(&t->mutex);
|
ast_remove_lock_info(&t->mutex);
|
||||||
@@ -608,7 +608,7 @@ static inline int __ast_cond_timedwait(const char *filename, int lineno, const c
|
|||||||
filename, lineno, func, strerror(res));
|
filename, lineno, func, strerror(res));
|
||||||
DO_THREAD_CRASH;
|
DO_THREAD_CRASH;
|
||||||
} else {
|
} else {
|
||||||
reentrancy_lock_cs(t);
|
ast_reentrancy_lock(t);
|
||||||
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
if (t->reentrancy < AST_MAX_REENTRANCY) {
|
||||||
t->file[t->reentrancy] = filename;
|
t->file[t->reentrancy] = filename;
|
||||||
t->lineno[t->reentrancy] = lineno;
|
t->lineno[t->reentrancy] = lineno;
|
||||||
@@ -619,7 +619,7 @@ static inline int __ast_cond_timedwait(const char *filename, int lineno, const c
|
|||||||
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
__ast_mutex_logger("%s line %d (%s): '%s' really deep reentrancy!\n",
|
||||||
filename, lineno, func, mutex_name);
|
filename, lineno, func, mutex_name);
|
||||||
}
|
}
|
||||||
reentrancy_unlock_cs(t);
|
ast_reentrancy_unlock(t);
|
||||||
|
|
||||||
if (t->track)
|
if (t->track)
|
||||||
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
ast_store_lock_info(AST_MUTEX, filename, lineno, func, mutex_name, &t->mutex);
|
||||||
|
15
main/utils.c
15
main/utils.c
@@ -749,6 +749,9 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_
|
|||||||
lock_info->thread_name);
|
lock_info->thread_name);
|
||||||
pthread_mutex_lock(&lock_info->lock);
|
pthread_mutex_lock(&lock_info->lock);
|
||||||
for (i = 0; str && i < lock_info->num_locks; i++) {
|
for (i = 0; str && i < lock_info->num_locks; i++) {
|
||||||
|
int j;
|
||||||
|
ast_mutex_t *lock;
|
||||||
|
|
||||||
ast_str_append(&str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
|
ast_str_append(&str, 0, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
|
||||||
lock_info->locks[i].pending > 0 ? "Waiting for " :
|
lock_info->locks[i].pending > 0 ? "Waiting for " :
|
||||||
lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
|
lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
|
||||||
@@ -758,6 +761,18 @@ static char *handle_show_locks(struct ast_cli_entry *e, int cmd, struct ast_cli_
|
|||||||
lock_info->locks[i].func, lock_info->locks[i].lock_name,
|
lock_info->locks[i].func, lock_info->locks[i].lock_name,
|
||||||
lock_info->locks[i].lock_addr,
|
lock_info->locks[i].lock_addr,
|
||||||
lock_info->locks[i].times_locked);
|
lock_info->locks[i].times_locked);
|
||||||
|
|
||||||
|
if (!lock_info->locks[i].pending)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
lock = lock_info->locks[i].lock_addr;
|
||||||
|
|
||||||
|
ast_reentrancy_lock(lock);
|
||||||
|
for (j = 0; str && j < lock->reentrancy; j++) {
|
||||||
|
ast_str_append(&str, 0, "=== --- ---> Locked Here: %s line %d (%s)\n",
|
||||||
|
lock->file[j], lock->lineno[j], lock->func[j]);
|
||||||
|
}
|
||||||
|
ast_reentrancy_unlock(lock);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&lock_info->lock);
|
pthread_mutex_unlock(&lock_info->lock);
|
||||||
if (!str)
|
if (!str)
|
||||||
|
Reference in New Issue
Block a user