From e3ea1dd2fe3909a0b7aa9e7489a22aeb1c37b1d5 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 11 Jan 2021 14:04:54 +0100 Subject: [PATCH] Allow an option set_realtime_priority() to revert --- src/common/utils.cpp | 5 +++-- src/common/utils.h | 5 ++++- src/plugin/bridges/common.h | 2 +- src/wine-host/group-host.cpp | 2 +- src/wine-host/individual-host.cpp | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/common/utils.cpp b/src/common/utils.cpp index 19ced3bf..79c35178 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -31,7 +31,8 @@ fs::path get_temporary_directory() { } } -bool set_realtime_priority() { +bool set_realtime_priority(bool sched_fifo) { sched_param params{.sched_priority = 5}; - return sched_setscheduler(0, SCHED_FIFO, ¶ms) == 0; + return sched_setscheduler(0, sched_fifo ? SCHED_FIFO : SCHED_OTHER, + ¶ms) == 0; } diff --git a/src/common/utils.h b/src/common/utils.h index 075eeb5f..239e30b0 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -41,7 +41,10 @@ boost::filesystem::path get_temporary_directory(); * We explicitly don't do this for wineserver itself since from my testing that * can actually increase latencies. * + * @param sched_fifo If true, set the current process/thread's scheudling policy + * to `SCHED_FIFO`. Otherwise reset it back to `SCHWED_OTHER`. + * * @return Whether the operation was successful or not. This will fail if the * user does not have the privileges to set realtime priorities. */ -bool set_realtime_priority(); +bool set_realtime_priority(bool sched_fifo); diff --git a/src/plugin/bridges/common.h b/src/plugin/bridges/common.h index 153c0ffd..0cfcf0e3 100644 --- a/src/plugin/bridges/common.h +++ b/src/plugin/bridges/common.h @@ -86,7 +86,7 @@ class PluginBridge { info.windows_plugin_path.string(), .endpoint_base_dir = sockets.base_dir.string()}))), - has_realtime_priority(set_realtime_priority()), + has_realtime_priority(set_realtime_priority(true)), wine_io_handler([&]() { io_context.run(); }) {} virtual ~PluginBridge(){}; diff --git a/src/wine-host/group-host.cpp b/src/wine-host/group-host.cpp index 9b681c92..9b214ff2 100644 --- a/src/wine-host/group-host.cpp +++ b/src/wine-host/group-host.cpp @@ -41,7 +41,7 @@ int __attribute__((visibility("default"))) __cdecl #endif main(int argc, char* argv[]) { - set_realtime_priority(); + set_realtime_priority(true); // Instead of directly hosting a plugin, this process will receive a UNIX // domain socket endpoint path that it should listen on to allow yabridge diff --git a/src/wine-host/individual-host.cpp b/src/wine-host/individual-host.cpp index 297a4744..569af64c 100644 --- a/src/wine-host/individual-host.cpp +++ b/src/wine-host/individual-host.cpp @@ -37,7 +37,7 @@ int __attribute__((visibility("default"))) __cdecl #endif main(int argc, char* argv[]) { - set_realtime_priority(); + set_realtime_priority(true); // We pass plugin format, the name of the VST2 plugin .dll file or VST3 // bundle to load, and the base directory for the Unix domain socket