From d2be82285a9f01ced29b6b75a28a6fb8dfe3cf7e Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 23 Mar 2020 22:33:28 +0100 Subject: [PATCH] Make sure messages can't get out of order --- src/common/events.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/events.h b/src/common/events.h index 928ffcd5..ba9a203b 100644 --- a/src/common/events.h +++ b/src/common/events.h @@ -146,15 +146,14 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket, const Event event{opcode, index, value, option, payload.value()}; - // Prevent two threads from writing over the socket at the same time. This - // should not be needed, but for instance Bitwig's plugin bridge will - // sometimes repeatedly send events from an off thread that may overlap with - // other `dispatch()` calls. + // Prevent two threads from writing over the socket at the same time and + // messages getting out of order. This is needed because we can't prevent + // the plugin or the host from calling `dispatch()` or `audioMaster()` from + // multiple threads. write_semaphore.lock(); write_object(socket, event); - write_semaphore.unlock(); - const auto response = read_object(socket); + write_semaphore.unlock(); if (logging.has_value()) { auto [logger, is_dispatch] = logging.value();