From: Marc-Aurel Zent mzent@codeweavers.com
--- server/process.c | 22 ++++++++++++++++++++++ server/process.h | 1 + server/thread.c | 7 +------ 3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/server/process.c b/server/process.c index 12218e82e3d..fc21ac70012 100644 --- a/server/process.c +++ b/server/process.c @@ -1633,6 +1633,28 @@ DECL_HANDLER(get_process_vm_counters) release_object( process ); }
+unsigned short get_process_base_priority( int priority_class ) +{ + /* offsets taken from https://learn.microsoft.com/en-us/windows/win32/procthread/scheduling-priori... */ + switch (priority_class) + { + case PROCESS_PRIOCLASS_IDLE: + return 4; + case PROCESS_PRIOCLASS_BELOW_NORMAL: + return 6; + case PROCESS_PRIOCLASS_NORMAL: + return 8; + case PROCESS_PRIOCLASS_ABOVE_NORMAL: + return 10; + case PROCESS_PRIOCLASS_HIGH: + return 13; + case PROCESS_PRIOCLASS_REALTIME: + return 24; + default: + return 8; + } +} + void set_process_priority( struct process *process, int priority ) { struct thread *thread; diff --git a/server/process.h b/server/process.h index 9238d638f15..4d62745f209 100644 --- a/server/process.h +++ b/server/process.h @@ -116,6 +116,7 @@ extern void kill_process( struct process *process, int violent_death ); extern void kill_console_processes( struct thread *renderer, int exit_code ); extern void detach_debugged_processes( struct debug_obj *debug_obj, int exit_code ); extern void enum_processes( int (*cb)(struct process*, void*), void *user); +extern unsigned short get_process_base_priority( int priority_class ); extern void set_process_priority( struct process *process, int priority );
/* console functions */ diff --git a/server/thread.c b/server/thread.c index 8e28aefe47a..88ff39676d9 100644 --- a/server/thread.c +++ b/server/thread.c @@ -793,16 +793,11 @@ unsigned int set_thread_priority( struct thread *thread, int priority )
static int thread_priority_from_class_and_level( int priority_class, int base_priority ) { - /* offsets taken from https://learn.microsoft.com/en-us/windows/win32/procthread/scheduling-priori... */ - static const int class_offsets[] = { 4, 8, 13, 24, 6, 10 }; - if (base_priority == THREAD_PRIORITY_IDLE) return (priority_class == PROCESS_PRIOCLASS_REALTIME ? LOW_REALTIME_PRIORITY : LOW_PRIORITY + 1); if (base_priority == THREAD_PRIORITY_TIME_CRITICAL) return (priority_class == PROCESS_PRIOCLASS_REALTIME ? HIGH_PRIORITY : LOW_REALTIME_PRIORITY - 1); - if (priority_class >= ARRAY_SIZE(class_offsets)) - return LOW_REALTIME_PRIORITY / 2; - return class_offsets[priority_class - 1] + base_priority; + return get_process_base_priority( priority_class ) + base_priority; }
#define THREAD_PRIORITY_REALTIME_HIGHEST 6