mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 02:26:23 +00:00
Fulfull a feature request from Qwell on the "core show locks" output. It will
now note the lock type for each lock that a thread holds. (mutex, rdlock, or wrlock) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@84271 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
26
main/utils.c
26
main/utils.c
@@ -538,6 +538,7 @@ struct thr_lock_info {
|
||||
const char *lock_name;
|
||||
void *lock_addr;
|
||||
int times_locked;
|
||||
enum ast_lock_type type;
|
||||
/*! This thread is waiting on this lock */
|
||||
unsigned int pending:1;
|
||||
} locks[AST_MAX_LOCKS];
|
||||
@@ -583,8 +584,8 @@ static void lock_info_destroy(void *data)
|
||||
*/
|
||||
AST_THREADSTORAGE_CUSTOM(thread_lock_info, thread_lock_info_init, lock_info_destroy);
|
||||
|
||||
void ast_store_lock_info(const char *filename, int line_num,
|
||||
const char *func, const char *lock_name, void *lock_addr)
|
||||
void ast_store_lock_info(enum ast_lock_type type, const char *filename,
|
||||
int line_num, const char *func, const char *lock_name, void *lock_addr)
|
||||
{
|
||||
struct thr_lock_info *lock_info;
|
||||
int i;
|
||||
@@ -616,6 +617,7 @@ void ast_store_lock_info(const char *filename, int line_num,
|
||||
lock_info->locks[i].lock_name = lock_name;
|
||||
lock_info->locks[i].lock_addr = lock_addr;
|
||||
lock_info->locks[i].times_locked = 1;
|
||||
lock_info->locks[i].type = type;
|
||||
lock_info->locks[i].pending = 1;
|
||||
lock_info->num_locks++;
|
||||
|
||||
@@ -672,6 +674,20 @@ void ast_remove_lock_info(void *lock_addr)
|
||||
pthread_mutex_unlock(&lock_info->lock);
|
||||
}
|
||||
|
||||
static const char *locktype2str(enum ast_lock_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case AST_MUTEX:
|
||||
return "MUTEX";
|
||||
case AST_RDLOCK:
|
||||
return "RDLOCK";
|
||||
case AST_WRLOCK:
|
||||
return "WRLOCK";
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
static int handle_show_locks(int fd, int argc, char *argv[])
|
||||
{
|
||||
struct thr_lock_info *lock_info;
|
||||
@@ -691,9 +707,11 @@ static int handle_show_locks(int fd, int argc, char *argv[])
|
||||
lock_info->thread_name);
|
||||
pthread_mutex_lock(&lock_info->lock);
|
||||
for (i = 0; i < lock_info->num_locks; i++) {
|
||||
ast_cli(fd, "=== ---> %sLock #%d: %s %d %s %s %p (%d)\n",
|
||||
ast_cli(fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
|
||||
lock_info->locks[i].pending ? "Waiting for " : "", i,
|
||||
lock_info->locks[i].file, lock_info->locks[i].line_num,
|
||||
lock_info->locks[i].file,
|
||||
locktype2str(lock_info->locks[i].type),
|
||||
lock_info->locks[i].line_num,
|
||||
lock_info->locks[i].func, lock_info->locks[i].lock_name,
|
||||
lock_info->locks[i].lock_addr,
|
||||
lock_info->locks[i].times_locked);
|
||||
|
Reference in New Issue
Block a user