Fix SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL also applying to HIGH priorities As the name suggests, the hint should only apply to SDL_THREAD_PRIORITY_TIME_CRITICAL The resulting priorities for my current distro result in these values: | High | Time Critical Hint |--------------|----------------- 0 | P=10 N=-10 | P=5 N=-15 1 | P=10 N=-10 | P=-21 N=0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 24b9022..b73b06e 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -801,7 +801,7 @@ extern "C" {
* Currently no other platform hint values are defined but may be in the future.
*
* \note On Linux, the kernel may send SIGKILL to realtime tasks which exceed the distro
-* configured execution budget for rtkit. This budget is queriably through RLIMIT_RTTIME
+* configured execution budget for rtkit. This budget can be queried through RLIMIT_RTTIME
* after calling SDL_SetThreadPriority().
*/
#define SDL_HINT_THREAD_PRIORITY_POLICY "SDL_THREAD_PRIORITY_POLICY"
diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c
index b6cd04a..e4795a6 100644
--- a/src/thread/pthread/SDL_systhread.c
+++ b/src/thread/pthread/SDL_systhread.c
@@ -208,7 +208,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
int pri_policy;
pthread_t thread = pthread_self();
const char *policyhint = SDL_GetHint(SDL_HINT_THREAD_PRIORITY_POLICY);
- const SDL_bool allow_realtime_hint = SDL_GetHintBoolean(SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL, SDL_FALSE);
+ const SDL_bool timecritical_realtime_hint = SDL_GetHintBoolean(SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL, SDL_FALSE);
if (pthread_getschedparam(thread, &policy, &sched) != 0) {
return SDL_SetError("pthread_getschedparam() failed");
@@ -229,7 +229,7 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
pri_policy = SCHED_RR;
break;
#else
- pri_policy = allow_realtime_hint ? SCHED_RR : SCHED_OTHER;
+ pri_policy = SCHED_OTHER;
break;
#endif
default:
@@ -237,6 +237,10 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
break;
}
+ if (timecritical_realtime_hint && priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
+ pri_policy = SCHED_RR;
+ }
+
if (policyhint) {
if (SDL_strcmp(policyhint, "current") == 0) {
/* Leave current thread scheduler policy unchanged */