From: Rémi Bernon rbernon@codeweavers.com
--- server/thread.c | 26 ++++++++++++++++++++++++++ server/thread.h | 1 + 2 files changed, 27 insertions(+)
diff --git a/server/thread.c b/server/thread.c index 5c039828912..5f07663bf23 100644 --- a/server/thread.c +++ b/server/thread.c @@ -240,6 +240,7 @@ static inline void init_thread_structure( struct thread *thread ) thread->state = RUNNING; thread->exit_code = 0; thread->priority = 0; + thread->delay_priority = NULL; thread->suspend = 0; thread->dbg_hidden = 0; thread->desktop_users = 0; @@ -402,6 +403,9 @@ static void cleanup_thread( struct thread *thread ) { int i;
+ if (thread->delay_priority) remove_timeout_user( thread->delay_priority ); + thread->delay_priority = NULL; + if (thread->context) { thread->context->status = STATUS_ACCESS_DENIED; @@ -606,6 +610,27 @@ affinity_t get_thread_affinity( struct thread *thread ) #define THREAD_PRIORITY_REALTIME_HIGHEST 6 #define THREAD_PRIORITY_REALTIME_LOWEST -7
+static void apply_thread_priority( struct thread *thread, int priority_class, int priority, int delayed ); + +static void delayed_set_thread_priority( void *private ) +{ + struct thread *thread = private; + int priority_class = thread->process->priority, priority = thread->priority; + apply_thread_priority( thread, priority_class, priority, TRUE ); +} + +static void apply_thread_priority( struct thread *thread, int priority_class, int priority, int delayed ) +{ + if (!delayed && thread->delay_priority) remove_timeout_user( thread->delay_priority ); + thread->delay_priority = NULL; + + if (thread->unix_tid == -1) + { + thread->delay_priority = add_timeout_user( -TICKS_PER_SEC, delayed_set_thread_priority, thread ); + return; + } +} + int set_thread_priority( struct thread *thread, int priority_class, int priority ) { int max = THREAD_PRIORITY_HIGHEST; @@ -628,6 +653,7 @@ int set_thread_priority( struct thread *thread, int priority_class, int priority return 0; thread->priority = priority;
+ apply_thread_priority( thread, priority_class, priority, FALSE ); return 0; }
diff --git a/server/thread.h b/server/thread.h index b0237c3a80e..ca601aa9bb9 100644 --- a/server/thread.h +++ b/server/thread.h @@ -80,6 +80,7 @@ struct thread client_ptr_t entry_point; /* entry point (in client address space) */ affinity_t affinity; /* affinity mask */ int priority; /* priority level */ + struct timeout_user *delay_priority;/* delayed set_thread_priority */ int suspend; /* suspend count */ int dbg_hidden; /* hidden from debugger */ obj_handle_t desktop; /* desktop handle */