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
This commit is contained in:
Axel Dörfler
2004-03-17 15:08:36 +00:00
parent 1592b084a9
commit 15edae152e
+26 -1
View File
@@ -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;
}