More Linux fixes.

This commit is contained in:
Sam Lantinga 2020-05-26 13:19:44 -07:00
parent c7d1dab1fe
commit 0713c5790d
2 changed files with 40 additions and 38 deletions

View file

@ -223,9 +223,33 @@ SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedP
#if SDL_THREADS_DISABLED #if SDL_THREADS_DISABLED
return SDL_Unsupported(); return SDL_Unsupported();
#else #else
if (schedPolicy != SCHED_RR && schedPolicy != SCHED_FIFO && setpriority(PRIO_PROCESS, (id_t)threadID, priority) == 0) { int osPriority;
if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
osPriority = 1;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
osPriority = rtkit_max_realtime_priority * 3 / 4;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
osPriority = rtkit_max_realtime_priority;
} else {
osPriority = rtkit_max_realtime_priority / 2;
}
} else {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
osPriority = 19;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
osPriority = -10;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
osPriority = -20;
} else {
osPriority = 0;
}
if (setpriority(PRIO_PROCESS, (id_t)threadID, osPriority) == 0) {
return 0; return 0;
} }
}
#if SDL_USE_LIBDBUS #if SDL_USE_LIBDBUS
/* Note that this fails you most likely: /* Note that this fails you most likely:
@ -241,35 +265,11 @@ SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedP
README and sample code at: http://git.0pointer.net/rtkit.git README and sample code at: http://git.0pointer.net/rtkit.git
*/ */
if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) { if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) {
int rtPriority; if (rtkit_setpriority_realtime((pid_t)threadID, osPriority)) {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
rtPriority = 1;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
rtPriority = rtkit_max_realtime_priority * 3 / 4;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
rtPriority = rtkit_max_realtime_priority;
} else {
rtPriority = rtkit_max_realtime_priority / 2;
}
if (rtkit_setpriority_realtime((pid_t)threadID, rtPriority)) {
return 0; return 0;
} }
} else { } else {
int niceLevel; if (rtkit_setpriority_nice((pid_t)threadID, osPriority)) {
if (sdlPriority == SDL_THREAD_PRIORITY_LOW) {
niceLevel = 19;
} else if (sdlPriority == SDL_THREAD_PRIORITY_HIGH) {
niceLevel = -10;
} else if (sdlPriority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
niceLevel = -20;
} else {
niceLevel = 0;
}
if (rtkit_setpriority_nice((pid_t)threadID, niceLevel)) {
return 0; return 0;
} }
} }

View file

@ -247,8 +247,10 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
} }
#if __LINUX__ #if __LINUX__
{
pid_t linuxTid = syscall(SYS_gettid); pid_t linuxTid = syscall(SYS_gettid);
return SDL_LinuxSetThreadPriorityAndPolicy(linuxTid, priority, policy); return SDL_LinuxSetThreadPriorityAndPolicy(linuxTid, priority, policy);
}
#else #else
if (priority == SDL_THREAD_PRIORITY_LOW) { if (priority == SDL_THREAD_PRIORITY_LOW) {
sched.sched_priority = sched_get_priority_min(policy); sched.sched_priority = sched_get_priority_min(policy);