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:
@@ -1353,10 +1353,35 @@ err:
|
|||||||
thread_id
|
thread_id
|
||||||
find_thread(const char *name)
|
find_thread(const char *name)
|
||||||
{
|
{
|
||||||
|
struct hash_iterator iterator;
|
||||||
|
struct thread *thread;
|
||||||
|
cpu_status state;
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return thread_get_current_thread_id();
|
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;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user