Make sure messages can't get out of order

This commit is contained in:
Robbert van der Helm
2020-03-23 22:33:28 +01:00
parent 5d1051a00c
commit d2be82285a
+5 -6
View File
@@ -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<EventResult>(socket);
write_semaphore.unlock();
if (logging.has_value()) {
auto [logger, is_dispatch] = logging.value();