Updated thread priorities for Apple operating systems

This commit is contained in:
Sam Lantinga 2020-04-01 16:39:05 -07:00
parent 377f2d35d5
commit 378a5cfb61
1 changed files with 16 additions and 3 deletions

View File

@ -220,11 +220,24 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
} else { } else {
int min_priority = sched_get_priority_min(policy); int min_priority = sched_get_priority_min(policy);
int max_priority = sched_get_priority_max(policy); int max_priority = sched_get_priority_max(policy);
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
if (min_priority == 15 && max_priority == 47) {
/* Apple has a specific set of thread priorities */
if (priority == SDL_THREAD_PRIORITY_HIGH) {
sched.sched_priority = 45;
} else {
sched.sched_priority = 37;
}
} else
#endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */
{
sched.sched_priority = (min_priority + (max_priority - min_priority) / 2); sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
if (priority == SDL_THREAD_PRIORITY_HIGH) { if (priority == SDL_THREAD_PRIORITY_HIGH) {
sched.sched_priority += ((max_priority - min_priority) / 4); sched.sched_priority += ((max_priority - min_priority) / 4);
} }
} }
}
if (pthread_setschedparam(thread, policy, &sched) != 0) { if (pthread_setschedparam(thread, policy, &sched) != 0) {
return SDL_SetError("pthread_setschedparam() failed"); return SDL_SetError("pthread_setschedparam() failed");
} }