From 3b3e3805f8e693bbb48ab203379efd47fb7e73dc Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 31 Aug 2008 00:37:02 +0000 Subject: [PATCH] Added thread::io_priority field and functions to get/set it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27247 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/thread.h | 3 +++ headers/private/kernel/thread_types.h | 1 + src/system/kernel/thread.cpp | 32 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/headers/private/kernel/thread.h b/headers/private/kernel/thread.h index 58cc86e164..9a3bdd83ef 100644 --- a/headers/private/kernel/thread.h +++ b/headers/private/kernel/thread.h @@ -48,6 +48,9 @@ int32 thread_used_threads(void); const char* thread_state_to_text(struct thread* thread, int32 state); +int32 thread_get_io_priority(thread_id id); +void thread_set_io_priority(int32 priority); + #define thread_get_current_thread arch_thread_get_current_thread struct thread *thread_get_thread_struct(thread_id id); diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h index 6fe6181f94..68921d5ede 100644 --- a/headers/private/kernel/thread_types.h +++ b/headers/private/kernel/thread_types.h @@ -240,6 +240,7 @@ struct thread { char name[B_OS_NAME_LENGTH]; int32 priority; int32 next_priority; + int32 io_priority; int32 state; int32 next_state; struct cpu_ent *cpu; diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 51a9019f84..4c274aedea 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -234,6 +234,7 @@ create_thread_struct(struct thread *inthread, const char *name, thread->team_next = NULL; thread->queue_next = NULL; thread->priority = thread->next_priority = -1; + thread->io_priority = -1; thread->args1 = NULL; thread->args2 = NULL; thread->alarm.period = 0; reset_signals(thread); @@ -1991,6 +1992,37 @@ thread_state_to_text(struct thread* thread, int32 state) } +int32 +thread_get_io_priority(thread_id id) +{ + // take a shortcut, if it is the current thread + struct thread* thread = thread_get_current_thread(); + int32 priority; + if (id == thread->id) { + int32 priority = thread->io_priority; + return priority < 0 ? thread->priority : priority; + } + + // not the current thread -- get it + InterruptsSpinLocker locker(gThreadSpinlock); + + thread = thread_get_thread_struct_locked(id); + if (thread == NULL) + return B_BAD_THREAD_ID; + + priority = thread->io_priority; + return priority < 0 ? thread->priority : priority; +} + + +void +thread_set_io_priority(int32 priority) +{ + struct thread* thread = thread_get_current_thread(); + thread->io_priority = priority; +} + + status_t thread_init(kernel_args *args) {