From 0f18178fda64f7958a7c909a37406ee691555a88 Mon Sep 17 00:00:00 2001 From: janwas Date: Tue, 7 Dec 2004 03:01:12 +0000 Subject: [PATCH] fixed sched. priority code: wouldn't work for all values. This was SVN commit r1468. --- source/lib/sysdep/ia32.cpp | 4 ++-- source/lib/sysdep/win/wposix.cpp | 16 +++++++++++++--- source/lib/sysdep/win/wposix.h | 5 +++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/lib/sysdep/ia32.cpp b/source/lib/sysdep/ia32.cpp index b4fd985e2a..2e65d202ff 100755 --- a/source/lib/sysdep/ia32.cpp +++ b/source/lib/sysdep/ia32.cpp @@ -344,8 +344,8 @@ static void measure_cpu_freq() int old_policy; static sched_param old_param; // (static => 0-init) pthread_getschedparam(pthread_self(), &old_policy, &old_param); static sched_param max_param; - max_param.sched_priority = sched_get_priority_max(SCHED_RR); - pthread_setschedparam(pthread_self(), SCHED_RR, &max_param); + max_param.sched_priority = sched_get_priority_max(SCHED_FIFO); + pthread_setschedparam(pthread_self(), SCHED_FIFO, &max_param); if(ia32_cap(TSC)) // make sure the TSC is available, because we're going to diff --git a/source/lib/sysdep/win/wposix.cpp b/source/lib/sysdep/win/wposix.cpp index 1037e2631a..6077b0d99e 100755 --- a/source/lib/sysdep/win/wposix.cpp +++ b/source/lib/sysdep/win/wposix.cpp @@ -342,11 +342,21 @@ int pthread_getschedparam(pthread_t thread, int* policy, struct sched_param* par int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param* param) { - if(policy == SCHED_FIFO) - SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); + const int pri = param->sched_priority; + // additional boost for policy == SCHED_FIFO + DWORD pri_class = NORMAL_PRIORITY_CLASS; + if(policy == SCHED_FIFO) + { + pri_class = HIGH_PRIORITY_CLASS; + if(pri == 2) + pri_class = REALTIME_PRIORITY_CLASS; + } + SetPriorityClass(GetCurrentProcess(), pri_class); + + // choose fixed Windows values from pri const HANDLE hThread = cast_to_HANDLE((intptr_t)thread); - SetThreadPriority(hThread, param->sched_priority); + SetThreadPriority(hThread, pri); return 0; } diff --git a/source/lib/sysdep/win/wposix.h b/source/lib/sysdep/win/wposix.h index 82be717a92..207ad0cac6 100755 --- a/source/lib/sysdep/win/wposix.h +++ b/source/lib/sysdep/win/wposix.h @@ -358,8 +358,9 @@ enum SCHED_OTHER }; -#define sched_get_priority_max(policy) 15 // TIME_CRITICAL -#define sched_get_priority_min(policy) -15 // IDLE +#define sched_get_priority_max(policy) +2 +#define sched_get_priority_min(policy) -2 + // changing will break pthread_setschedparam //