From 378a5cfb61307b2ab70db8c6d850b506cf80d0d2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 1 Apr 2020 16:39:05 -0700 Subject: [PATCH] Updated thread priorities for Apple operating systems --- src/thread/pthread/SDL_systhread.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index 148c47406a954..e072889e85c01 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -220,9 +220,22 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) } else { int min_priority = sched_get_priority_min(policy); int max_priority = sched_get_priority_max(policy); - sched.sched_priority = (min_priority + (max_priority - min_priority) / 2); - if (priority == SDL_THREAD_PRIORITY_HIGH) { - sched.sched_priority += ((max_priority - min_priority) / 4); + +#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); + if (priority == SDL_THREAD_PRIORITY_HIGH) { + sched.sched_priority += ((max_priority - min_priority) / 4); + } } } if (pthread_setschedparam(thread, policy, &sched) != 0) {