From d018f3568faddb7e3c882874df0ffe2cabd18beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 6 Apr 2004 21:38:45 +0000 Subject: [PATCH] Implemented rename_thread() and _user_rename_thread() (as pointed out by Jack Burton). The syscall is not yet connected, and the code has not yet been tested. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7179 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/thread.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index 1a0d7329a6..7f6bb751e3 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -1380,6 +1380,38 @@ find_thread(const char *name) } +status_t +rename_thread(thread_id id, const char *name) +{ + status_t status = B_OK; + struct thread *thread; + + 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(); + + 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); + } + + return status; +} + + status_t set_thread_priority(thread_id id, int32 priority) { @@ -1599,6 +1631,20 @@ _user_suspend_thread(thread_id thread) } +status_t +_user_rename_thread(thread_id thread, const char *userName) +{ + char name[B_OS_NAME_LENGTH]; + + if (!IS_USER_ADDRESS(userName) + || userName == NULL + || user_strlcpy(name, userName, B_OS_NAME_LENGTH) < B_OK) + return B_BAD_ADDRESS; + + return rename_thread(thread, name); +} + + int32 _user_set_thread_priority(thread_id thread, int32 newPriority) {