Prevent rare race conditions with get/setParameter

I've never seen it happen, but in theory they could be called
simultaneously.
This commit is contained in:
Robbert van der Helm
2020-04-19 16:14:22 +02:00
parent 9f3ed85208
commit b13d7d554d
3 changed files with 32 additions and 16 deletions
+3 -3
View File
@@ -102,7 +102,7 @@ class DefaultDataConverter {
*
* @param socket The socket to write over, should be the same socket the other
* endpoint is using to call `passthrough_event()`.
* @param write_semaphore A mutex to ensure that only one thread can write to
* @param write_mutex A mutex to ensure that only one thread can write to
* the socket at once. Needed because VST hosts and plugins can and sometimes
* will call the `dispatch()` or `audioMaster()` functions from multiple
* threads at once.
@@ -120,7 +120,7 @@ class DefaultDataConverter {
*/
template <typename D>
intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
std::mutex& write_semaphore,
std::mutex& write_mutex,
D& data_converter,
std::optional<std::pair<Logger&, bool>> logging,
int opcode,
@@ -153,7 +153,7 @@ intptr_t send_event(boost::asio::local::stream_protocol::socket& socket,
// multiple threads.
EventResult response;
{
std::lock_guard lock(write_semaphore);
std::lock_guard lock(write_mutex);
write_object(socket, event);
response = read_object<EventResult>(socket);
}