From 9620c1d716a87cb8631190dc231518ea95795936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 29 May 2005 00:29:45 +0000 Subject: [PATCH] rename_thread() was broken for the current thread: updating the name is hardly atomic, so we need to grab the thread lock after all. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12877 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/thread.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/system/kernel/thread.c b/src/system/kernel/thread.c index 7e96630fb5..cfaee85d64 100644 --- a/src/system/kernel/thread.c +++ b/src/system/kernel/thread.c @@ -1615,31 +1615,27 @@ find_thread(const char *name) status_t rename_thread(thread_id id, const char *name) { - status_t status = B_OK; - struct thread *thread; + struct thread *thread = thread_get_current_thread(); + status_t status = B_BAD_THREAD_ID; + cpu_status state; if (name == NULL) return B_BAD_VALUE; - thread = thread_get_current_thread(); - if (thread->id == id) { - // it's ourself, so we know we aren't in the run queue, and we can manipulate - // our structure directly - strlcpy(thread->name, name, B_OS_NAME_LENGTH); - } else { - cpu_status state = disable_interrupts(); - GRAB_THREAD_LOCK(); + state = disable_interrupts(); + GRAB_THREAD_LOCK(); + if (thread->id != id) thread = thread_get_thread_struct_locked(id); - if (thread) { - strlcpy(thread->name, name, B_OS_NAME_LENGTH); - } else - status = B_BAD_THREAD_ID; - RELEASE_THREAD_LOCK(); - restore_interrupts(state); + if (thread != NULL) { + strlcpy(thread->name, name, B_OS_NAME_LENGTH); + status = B_OK; } + RELEASE_THREAD_LOCK(); + restore_interrupts(state); + return status; }