Handle dispatch() directly during event handling

When the message loop is active and we get an incoming dispatch() event,
we'll just handle it directly. In practice this would only be needed
when the event is a response to an `audioMaster()` call made during the
event loop, but we can't know that. This allows the `getProgram()`
during `audioMasterUpdateDisplay()` in REAPER and Renoise to work
correctly. Hopefully this doesn't cause random rare breakage.
This commit is contained in:
Robbert van der Helm
2020-10-26 20:00:26 +01:00
parent c95e8aa63c
commit ca2b95e7aa
8 changed files with 122 additions and 78 deletions
+5 -22
View File
@@ -29,11 +29,6 @@ namespace fs = boost::filesystem;
using namespace std::literals::chrono_literals;
/**
* The delay between calls to the event loop at a more than cinematic 30 fps.
*/
constexpr std::chrono::duration event_loop_interval = 1000ms / 30;
/**
* Listen on the specified endpoint if no process is already listening there,
* otherwise throw. This is needed to handle these three situations:
@@ -94,10 +89,9 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
stdout_redirect(stdio_context, STDOUT_FILENO),
stderr_redirect(stdio_context, STDERR_FILENO),
group_socket_endpoint(group_socket_path.string()),
group_socket_acceptor(
create_acceptor_if_inactive(plugin_context, group_socket_endpoint)),
events_timer(plugin_context),
shutdown_timer(plugin_context) {
group_socket_acceptor(create_acceptor_if_inactive(plugin_context.context,
group_socket_endpoint)),
shutdown_timer(plugin_context.context) {
// Write this process's original STDOUT and STDERR streams to the logger
// TODO: This works for output generated by plugins, but not for debug
// messages generated by wineserver. Is it possible to catch those?
@@ -131,7 +125,7 @@ void GroupBridge::handle_plugin_dispatch(size_t plugin_id) {
// potentially corrupt our heap. This way we can also properly join the
// thread again. If no active plugins remain, then we'll terminate the
// process.
boost::asio::post(plugin_context, [this, plugin_id]() {
boost::asio::post(plugin_context.context, [this, plugin_id]() {
std::lock_guard lock(active_plugins_mutex);
// The join is implicit because we're using std::jthread
@@ -240,16 +234,7 @@ void GroupBridge::accept_requests() {
}
void GroupBridge::async_handle_events() {
// Try to keep a steady framerate, but add in delays to let other events get
// handled if the GUI message handling somehow takes very long.
events_timer.expires_at(
std::max(events_timer.expiry() + event_loop_interval,
std::chrono::steady_clock::now() + 5ms));
events_timer.async_wait([&](const boost::system::error_code& error) {
if (error.failed()) {
return;
}
plugin_context.async_handle_events([&]() {
{
// Always handle X11 events
std::lock_guard lock(active_plugins_mutex);
@@ -279,8 +264,6 @@ void GroupBridge::async_handle_events() {
DispatchMessage(&msg);
}
}
async_handle_events();
});
}