Stop the watchdog context with the main context

Since this was never stopped, the `watchdog_handler` thread would also
keep running. Since after e3f0926aef
everything is supposed to exit cleanly, this would cause group host
processes to hang and never exit. Tying the watchdog timer to
`MainContext::run()` is cleaner anyways.
This commit is contained in:
Robbert van der Helm
2021-10-18 15:39:06 +02:00
parent 22391b502a
commit 0382b0a475
+17 -8
View File
@@ -82,7 +82,15 @@ MainContext::MainContext()
: context(), : context(),
events_timer(context), events_timer(context),
watchdog_context(), watchdog_context(),
watchdog_timer(watchdog_context) { watchdog_timer(watchdog_context) {}
void MainContext::run() {
// We need to know which thread is the GUI thread because mutual recursion
// in VST3 plugins needs to be handled differently depending on whether the
// potentially mutually recursive function was called from an audio thread
// or a GUI thread
gui_thread_id = GetCurrentThreadId();
// NOTE: We allow disabling the watchdog timer to allow the Wine process to // NOTE: We allow disabling the watchdog timer to allow the Wine process to
// be run from a separate namespace. This is not something you'd // be run from a separate namespace. This is not something you'd
// normally want to enable. // normally want to enable.
@@ -90,9 +98,7 @@ MainContext::MainContext()
std::cerr << "WARNING: Watchdog timer disabled. Not protecting" std::cerr << "WARNING: Watchdog timer disabled. Not protecting"
<< std::endl; << std::endl;
std::cerr << " against dangling processes." << std::endl; std::cerr << " against dangling processes." << std::endl;
return; } else {
}
// To account for hosts terminating before the bridged plugin has // To account for hosts terminating before the bridged plugin has
// initialized, we'll do the first watchdog check five seconds. After // initialized, we'll do the first watchdog check five seconds. After
// this we'll run the timer on a 30 second interval. // this we'll run the timer on a 30 second interval.
@@ -103,12 +109,15 @@ MainContext::MainContext()
watchdog_context.run(); watchdog_context.run();
}); });
} }
void MainContext::run() {
gui_thread_id = GetCurrentThreadId();
context.run(); context.run();
// We only need to check if the host is still running while the main context
// is also running. If a stop was requested, the entire application is
// supposed to shut down. Otherwise `watchdog_handler` would just block on
// the join as the watchdog timer is still active.
watchdog_context.stop();
} }
void MainContext::stop() noexcept { void MainContext::stop() noexcept {