// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 Robbert van der Helm
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
#include "utils.h"
#include
#include
namespace bp = boost::process;
namespace fs = boost::filesystem;
fs::path get_temporary_directory() {
bp::environment env = boost::this_process::environment();
if (!env["XDG_RUNTIME_DIR"].empty()) {
return env["XDG_RUNTIME_DIR"].to_string();
} else {
return fs::temp_directory_path();
}
}
std::optional get_realtime_priority() {
sched_param current_params{};
if (sched_getparam(0, ¤t_params) == 0 &&
current_params.sched_priority > 0) {
return current_params.sched_priority;
} else {
return std::nullopt;
}
}
bool set_realtime_priority(bool sched_fifo, int priority) {
sched_param params{.sched_priority = (sched_fifo ? priority : 0)};
return sched_setscheduler(0, sched_fifo ? SCHED_FIFO : SCHED_OTHER,
¶ms) == 0;
}