fixed sched. priority code: wouldn't work for all values.
This was SVN commit r1468.
This commit is contained in:
parent
77196dbe06
commit
0f18178fda
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user