diff options
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/initHelpers.cpp | 16 | ||||
-rw-r--r-- | src/init/initHelpers.hpp | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/init/initHelpers.cpp b/src/init/initHelpers.cpp index dc51650a..2666ed0b 100644 --- a/src/init/initHelpers.cpp +++ b/src/init/initHelpers.cpp @@ -3,3 +3,19 @@ bool Init::isSudo() { return getuid() != geteuid() || !geteuid(); } + +void Init::gainRealTime() { + const int minPrio = sched_get_priority_min(SCHED_RR); + const struct sched_param param = {.sched_priority = minPrio}; + + if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) { + Debug::log(WARN, "Failed to change process scheduling strategy"); + return; + } + + pthread_atfork(NULL, NULL, []() { + const struct sched_param param = {.sched_priority = 0}; + if (pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m)) + Debug::log(WARN, "Failed to reset process scheduling strategy"); + }); +}
\ No newline at end of file diff --git a/src/init/initHelpers.hpp b/src/init/initHelpers.hpp index 3b9f7915..da9b762a 100644 --- a/src/init/initHelpers.hpp +++ b/src/init/initHelpers.hpp @@ -4,4 +4,5 @@ namespace Init { bool isSudo(); + void gainRealTime(); };
\ No newline at end of file |