From 0382b0a475480779a968b81f713af3c58ac80884 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 18 Oct 2021 15:39:06 +0200 Subject: [PATCH] Stop the watchdog context with the main context Since this was never stopped, the `watchdog_handler` thread would also keep running. Since after e3f0926aefcc708a8bcc1a79a7751594c3af631e 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. --- src/wine-host/utils.cpp | 43 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/wine-host/utils.cpp b/src/wine-host/utils.cpp index 5967b2c3..047591c1 100644 --- a/src/wine-host/utils.cpp +++ b/src/wine-host/utils.cpp @@ -82,7 +82,15 @@ MainContext::MainContext() : context(), events_timer(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 // be run from a separate namespace. This is not something you'd // normally want to enable. @@ -90,25 +98,26 @@ MainContext::MainContext() std::cerr << "WARNING: Watchdog timer disabled. Not protecting" << std::endl; std::cerr << " against dangling processes." << std::endl; - return; + } else { + // To account for hosts terminating before the bridged plugin has + // initialized, we'll do the first watchdog check five seconds. After + // this we'll run the timer on a 30 second interval. + async_handle_watchdog_timer(5s); + + watchdog_handler = Win32Thread([&]() { + pthread_setname_np(pthread_self(), "watchdog"); + + watchdog_context.run(); + }); } - // To account for hosts terminating before the bridged plugin has - // initialized, we'll do the first watchdog check five seconds. After - // this we'll run the timer on a 30 second interval. - async_handle_watchdog_timer(5s); - - watchdog_handler = Win32Thread([&]() { - pthread_setname_np(pthread_self(), "watchdog"); - - watchdog_context.run(); - }); -} - -void MainContext::run() { - gui_thread_id = GetCurrentThreadId(); - 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 {