From 15edae152e5dc38cb6a8a3092e3ca993b26e52fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 17 Mar 2004 15:08:36 +0000 Subject: [PATCH] Completed find_thread() implementation, courtesy of Starr Kline. Added some comments. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7007 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/thread.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 53ffce63f6..795161a7c2 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -1353,10 +1353,35 @@ err: thread_id find_thread(const char *name) { + struct hash_iterator iterator; + struct thread *thread; + cpu_status state; + if (name == NULL) return thread_get_current_thread_id(); - // ToDo: implement me! + state = disable_interrupts(); + GRAB_THREAD_LOCK(); + + // ToDo: this might not be in the same order as find_thread() in BeOS + // which could be theoreticly problematic. + // ToDo: scanning the whole list with the thread lock held isn't exactly + // cheap either - although this function is probably used very rarely. + + hash_open(thread_hash, &iterator); + while ((thread = hash_next(thread_hash, &iterator)) != NULL) { + // Search through hash + if (thread->name != NULL && !strcmp(thread->name, name)) { + thread_id id = thread->id; + + RELEASE_THREAD_LOCK(); + restore_interrupts(state); + return id; + } + } + + RELEASE_THREAD_LOCK(); + restore_interrupts(state); return B_ENTRY_NOT_FOUND; }