Add a function for getting the current priority

This commit is contained in:
Robbert van der Helm
2021-01-22 00:44:43 +01:00
parent 58c687f9d7
commit 4812757f1a
2 changed files with 17 additions and 0 deletions
+10
View File
@@ -31,6 +31,16 @@ fs::path get_temporary_directory() {
}
}
std::optional<int> get_scheduling_priority() {
sched_param current_params{};
if (sched_getparam(0, &current_params) == 0 &&
current_params.sched_priority > 0) {
return current_params.sched_priority;
} else {
return std::nullopt;
}
}
bool set_realtime_priority(bool sched_fifo) {
sched_param params{.sched_priority = 5};
return sched_setscheduler(0, sched_fifo ? SCHED_FIFO : SCHED_OTHER,