Hyprland/src/init/initHelpers.cpp
François Conzelmann 4a42344e97
style/ci: apply clang-format and verify it in ci (#4039)
* style: apply clang-format

* ci: add new clang-format job to CI
2023-12-06 22:54:56 +00:00

29 lines
No EOL
891 B
C++

#include "initHelpers.hpp"
bool Init::isSudo() {
return getuid() != geteuid() || !geteuid();
}
void Init::gainRealTime() {
const int minPrio = sched_get_priority_min(SCHED_RR);
int old_policy;
struct sched_param param;
if (pthread_getschedparam(pthread_self(), &old_policy, &param)) {
Debug::log(WARN, "Failed to get old pthread scheduling priority");
return;
}
param.sched_priority = minPrio;
if (pthread_setschedparam(pthread_self(), SCHED_RR, &param)) {
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, &param))
Debug::log(WARN, "Failed to reset process scheduling strategy");
});
}