From: Rémi Bernon rbernon@codeweavers.com
--- server/thread.c | 39 ++++++++++++++++++++++++++------------- server/thread.h | 1 + 2 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/server/thread.c b/server/thread.c index f3880eebedb..21b3b130a9a 100644 --- a/server/thread.c +++ b/server/thread.c @@ -608,25 +608,35 @@ affinity_t get_thread_affinity( struct thread *thread ) #define THREAD_PRIORITY_REALTIME_HIGHEST 6 #define THREAD_PRIORITY_REALTIME_LOWEST -7
+int set_thread_priority( struct thread *thread, int priority_class, int priority ) +{ + int max = THREAD_PRIORITY_HIGHEST; + int min = THREAD_PRIORITY_LOWEST; + if (priority_class == PROCESS_PRIOCLASS_REALTIME) + { + max = THREAD_PRIORITY_REALTIME_HIGHEST; + min = THREAD_PRIORITY_REALTIME_LOWEST; + } + if ((priority < min || priority > max) && + priority != THREAD_PRIORITY_IDLE && + priority != THREAD_PRIORITY_TIME_CRITICAL) + return STATUS_INVALID_PARAMETER; + + if (thread->state == TERMINATED) + return STATUS_THREAD_IS_TERMINATING; + + thread->priority = priority; + return STATUS_SUCCESS; +} + /* set all information about a thread */ static void set_thread_info( struct thread *thread, const struct set_thread_info_request *req ) { if (req->mask & SET_THREAD_INFO_PRIORITY) { - int max = THREAD_PRIORITY_HIGHEST; - int min = THREAD_PRIORITY_LOWEST; - if (thread->process->priority == PROCESS_PRIOCLASS_REALTIME) - { - max = THREAD_PRIORITY_REALTIME_HIGHEST; - min = THREAD_PRIORITY_REALTIME_LOWEST; - } - if ((req->priority >= min && req->priority <= max) || - req->priority == THREAD_PRIORITY_IDLE || - req->priority == THREAD_PRIORITY_TIME_CRITICAL) - thread->priority = req->priority; - else - set_error( STATUS_INVALID_PARAMETER ); + int status = set_thread_priority( thread, thread->process->priority, req->priority ); + if (status) set_error( status ); } if (req->mask & SET_THREAD_INFO_AFFINITY) { @@ -1422,6 +1432,8 @@ DECL_HANDLER(init_first_thread) else set_thread_affinity( current, current->affinity );
+ set_thread_priority( current, process->priority, current->priority ); + debug_level = max( debug_level, req->debug_level );
reply->pid = get_process_id( process ); @@ -1451,6 +1463,7 @@ DECL_HANDLER(init_thread)
init_thread_context( current ); generate_debug_event( current, DbgCreateThreadStateChange, &req->entry ); + set_thread_priority( current, current->process->priority, current->priority ); set_thread_affinity( current, current->affinity );
reply->suspend = (current->suspend || current->process->suspend || current->context != NULL); diff --git a/server/thread.h b/server/thread.h index 3448f332b0b..dd5dc864373 100644 --- a/server/thread.h +++ b/server/thread.h @@ -122,6 +122,7 @@ extern void thread_cancel_apc( struct thread *thread, struct object *owner, enum extern int thread_add_inflight_fd( struct thread *thread, int client, int server ); extern int thread_get_inflight_fd( struct thread *thread, int client ); extern struct token *thread_get_impersonation_token( struct thread *thread ); +extern int set_thread_priority( struct thread *thread, int priority_class, int priority ); extern int set_thread_affinity( struct thread *thread, affinity_t affinity ); extern int suspend_thread( struct thread *thread ); extern int resume_thread( struct thread *thread );