mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
Core: Thread::Priority now implemented for POSIX (thanks tojocky)
git-svn-id: svn://ultimatepp.org/upp/trunk@5045 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
c492aaed26
commit
3c2194aadd
3 changed files with 76 additions and 6 deletions
|
|
@ -227,7 +227,7 @@ int Thread::Wait()
|
|||
return out;
|
||||
}
|
||||
|
||||
void Thread::Priority(int percent)
|
||||
bool Thread::Priority(int percent)
|
||||
{
|
||||
ASSERT(IsOpen());
|
||||
#ifdef PLATFORM_WIN32
|
||||
|
|
@ -242,10 +242,80 @@ void Thread::Priority(int percent)
|
|||
prior = THREAD_PRIORITY_ABOVE_NORMAL;
|
||||
else
|
||||
prior = THREAD_PRIORITY_HIGHEST;
|
||||
SetThreadPriority(handle, prior);
|
||||
return SetThreadPriority(handle, prior);
|
||||
#endif
|
||||
#ifdef PLATFORM_POSIX
|
||||
// ToDo
|
||||
int policy;
|
||||
struct sched_param param;
|
||||
|
||||
if(pthread_getschedparam(handle, &policy, ¶m))
|
||||
return false;
|
||||
int percen_min, percen_max;
|
||||
if(percent <= 25) {
|
||||
#if defined(SCHED_IDLE)
|
||||
policy = SCHED_IDLE;
|
||||
percen_min = 0;
|
||||
percen_max = 25;
|
||||
#elif defined(SCHED_BATCH)
|
||||
policy = SCHED_BATCH;
|
||||
percen_min = 0;
|
||||
percen_max = 75;
|
||||
#else
|
||||
policy = SCHED_OTHER;
|
||||
percen_min = 0;
|
||||
percen_max = 125;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
if(percent <= 75){
|
||||
#if defined(SCHED_IDLE)
|
||||
policy = SCHED_BATCH;
|
||||
percen_min = 25;
|
||||
percen_max = 75;
|
||||
#elif defined(SCHED_BATCH)
|
||||
policy = SCHED_BATCH;
|
||||
percen_min = 0;
|
||||
percen_max = 75;
|
||||
#else
|
||||
policy = SCHED_OTHER;
|
||||
percen_min = 0;
|
||||
percen_max = 125;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
if(percent <= 125){
|
||||
policy = SCHED_OTHER;
|
||||
#if defined(SCHED_IDLE)
|
||||
percen_min = 75;
|
||||
percen_max = 125;
|
||||
#elif defined(SCHED_BATCH)
|
||||
percen_min = 25;
|
||||
percen_max = 125;
|
||||
#else
|
||||
percen_min = 0;
|
||||
percen_max = 125;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
if(percent <= 175){ // should be the root
|
||||
policy = SCHED_FIFO;
|
||||
percen_min = 125;
|
||||
percen_max = 175;
|
||||
}
|
||||
else
|
||||
policy = SCHED_RR;
|
||||
param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))*(minmax(percent, percen_min, percen_max)-percen_min)/(percen_max - percen_min);
|
||||
|
||||
if (pthread_setschedparam(handle, policy, ¶m)) {
|
||||
// No privileges? Try maximum possible! Do not use EPERM as not all os support this one
|
||||
policy = SCHED_OTHER;
|
||||
percen_max = 125;
|
||||
percen_min = minmax(percen_min, 0, percen_max);
|
||||
param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))*(minmax(percent, percen_min, percen_max)-percen_min)/(percen_max - percen_min);
|
||||
if (pthread_setschedparam(handle, policy, ¶m))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue