Prevent data races in host callbacks

This commit is contained in:
Robbert van der Helm
2020-03-16 13:58:49 +01:00
parent 23ad05aba1
commit 7172a42c67
6 changed files with 34 additions and 26 deletions
+2 -2
View File
@@ -268,8 +268,8 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/,
void* data,
float option) {
HostCallbackDataConverter converter(plugin, time_info);
return send_event(vst_host_callback, converter, opcode, index, value, data,
option, std::nullopt);
return send_event(vst_host_callback, host_callback_semaphore, converter,
opcode, index, value, data, option, std::nullopt);
}
intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect,
+8
View File
@@ -27,6 +27,7 @@
#include <windows.h>
#include <boost/asio/local/stream_protocol.hpp>
#include <mutex>
#include <thread>
#include "../common/logging.h"
@@ -115,6 +116,13 @@ class PluginBridge {
*/
std::thread process_replacing_handler;
/**
* A binary semaphore to prevent race conditions from the host callback
* function being called by two threads at once. See `send_event()` for more
* information.
*/
std::mutex host_callback_semaphore;
/**
* A scratch buffer for sending and receiving data during `process` and
* `processReplacing` calls.