mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 20:10:13 +02:00
f03b9b1497
We'll periodically copy the scheduling priorities from the host's audio threads to the Wine plugin host's audio threads. The overhead of doing this is about 1 microsecond on my system, so doing this every cycle really adds up. But getting the Unix epoch time and comparing some timestamps has a neglegible overhead, so this should give you the best of both worlds. Next we'll do the same thing for VST3 plugins. As suggested by @jhernberg
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
#include "utils.h"
|
|
|
|
#include <sched.h>
|
|
#include <boost/process/environment.hpp>
|
|
|
|
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<int> 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;
|
|
}
|