From 12c9f1761f8f6ea4c74c4cf4634b660df1a326d4 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 31 Jul 2008 20:43:40 +0000 Subject: [PATCH] * Added thread block type constant for rw_locks, so that they are listed correctly by the "thread" and "threads" debugger commands. * Added "rwlock" debugger command. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26703 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/thread_types.h | 1 + src/system/kernel/lock.cpp | 42 ++++++++++++++++++++++++++- src/system/kernel/thread.cpp | 30 ++++++++++++------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h index ef36059e94..d36e37db09 100644 --- a/headers/private/kernel/thread_types.h +++ b/headers/private/kernel/thread_types.h @@ -57,6 +57,7 @@ enum { THREAD_BLOCK_TYPE_SNOOZE = 2, THREAD_BLOCK_TYPE_SIGNAL = 3, THREAD_BLOCK_TYPE_MUTEX = 4, + THREAD_BLOCK_TYPE_RW_LOCK = 5, THREAD_BLOCK_TYPE_OTHER = 9999, THREAD_BLOCK_TYPE_USER_BASE = 10000 diff --git a/src/system/kernel/lock.cpp b/src/system/kernel/lock.cpp index 31cf2e37d9..e63b3d84d1 100644 --- a/src/system/kernel/lock.cpp +++ b/src/system/kernel/lock.cpp @@ -168,7 +168,7 @@ rw_lock_wait(rw_lock* lock, bool writer) lock->waiters->last = &waiter; // block - thread_prepare_to_block(waiter.thread, 0, THREAD_BLOCK_TYPE_MUTEX, lock); + thread_prepare_to_block(waiter.thread, 0, THREAD_BLOCK_TYPE_RW_LOCK, lock); return thread_block_locked(waiter.thread); } @@ -381,6 +381,41 @@ rw_lock_write_unlock(rw_lock* lock) } +static int +dump_rw_lock_info(int argc, char** argv) +{ + if (argc < 2) { + print_debugger_command_usage(argv[0]); + return 0; + } + + rw_lock* lock = (rw_lock*)strtoul(argv[1], NULL, 0); + + if (!IS_KERNEL_ADDRESS(lock)) { + kprintf("invalid address: %p\n", lock); + return 0; + } + + kprintf("rw lock %p:\n", lock); + kprintf(" name: %s\n", lock->name); + kprintf(" holder: %ld\n", lock->holder); + kprintf(" reader count: %ld\n", lock->reader_count); + kprintf(" writer count: %ld\n", lock->writer_count); + kprintf(" owner count: %ld\n", lock->owner_count); + kprintf(" flags: %#lx\n", lock->flags); + + kprintf(" waiting threads:"); + rw_lock_waiter* waiter = lock->waiters; + while (waiter != NULL) { + kprintf(" %ld/%c", waiter->thread->id, waiter->writer ? 'w' : 'r'); + waiter = waiter->next; + } + kputs("\n"); + + return 0; +} + + // #pragma mark - @@ -623,4 +658,9 @@ lock_debug_init() "\n" "Prints info about the specified mutex.\n" " - pointer to the mutex to print the info for.\n", 0); + add_debugger_command_etc("rwlock", &dump_rw_lock_info, + "Dump info about an rw lock", + "\n" + "Prints info about the specified rw lock.\n" + " - pointer to the rw lock to print the info for.\n", 0); } diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 28beeb98cd..70d73bf947 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -1050,9 +1050,9 @@ _dump_thread_info(struct thread *thread) thread->sig_block_mask); kprintf("in_kernel: %d\n", thread->in_kernel); - kprintf("waiting for: "); - if (thread->state == B_THREAD_WAITING) { + kprintf("waiting for: "); + switch (thread->wait.type) { case THREAD_BLOCK_TYPE_SEMAPHORE: { @@ -1080,6 +1080,10 @@ _dump_thread_info(struct thread *thread) kprintf("mutex %p\n", thread->wait.object); break; + case THREAD_BLOCK_TYPE_RW_LOCK: + kprintf("rwlock %p\n", thread->wait.object); + break; + case THREAD_BLOCK_TYPE_OTHER: kprintf("other (%s)\n", (char*)thread->wait.object); break; @@ -1209,7 +1213,7 @@ dump_thread_list(int argc, char **argv) kprintf("ignoring invalid team argument.\n"); } - kprintf("thread id state wait for object cpu pri stack " + kprintf("thread id state wait for object cpu pri stack " " team name\n"); hash_open(sThreadHash, &i); @@ -1233,14 +1237,14 @@ dump_thread_list(int argc, char **argv) { sem_id sem = (sem_id)(addr_t)thread->wait.object; if (sem == thread->msg.read_sem) - kprintf(" "); + kprintf(" "); else - kprintf("sem %12ld ", sem); + kprintf("sem %12ld ", sem); break; } case THREAD_BLOCK_TYPE_CONDITION_VARIABLE: - kprintf("cvar %p ", thread->wait.object); + kprintf("cvar %p ", thread->wait.object); break; case THREAD_BLOCK_TYPE_SNOOZE: @@ -1248,23 +1252,27 @@ dump_thread_list(int argc, char **argv) break; case THREAD_BLOCK_TYPE_SIGNAL: - kprintf("signal "); + kprintf("signal "); break; case THREAD_BLOCK_TYPE_MUTEX: - kprintf("mutex %p ", thread->wait.object); + kprintf("mutex %p ", thread->wait.object); + break; + + case THREAD_BLOCK_TYPE_RW_LOCK: + kprintf("rwlock %p ", thread->wait.object); break; case THREAD_BLOCK_TYPE_OTHER: - kprintf("other "); + kprintf("other "); break; default: - kprintf("??? %p ", thread->wait.object); + kprintf("??? %p ", thread->wait.object); break; } } else - kprintf(" - "); + kprintf(" - "); // on which CPU does it run? if (thread->cpu)