mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-17 06:00:03 +02:00
Execute all non-unsafe opcodes on calling thread
This will require more testing of course, but I think it should be safe. This would increase the potential maximal throughput in group hosts significantly.
This commit is contained in:
@@ -335,7 +335,7 @@ bool Vst2Bridge::should_skip_message_loop() const {
|
|||||||
|
|
||||||
void Vst2Bridge::handle_dispatch() {
|
void Vst2Bridge::handle_dispatch() {
|
||||||
sockets.host_vst_dispatch.receive(
|
sockets.host_vst_dispatch.receive(
|
||||||
std::nullopt, [&](Event& event, bool on_main_thread) {
|
std::nullopt, [&](Event& event, bool /*on_main_thread*/) {
|
||||||
// TODO: As per the TODO in `passthrough_event`, this can use a
|
// TODO: As per the TODO in `passthrough_event`, this can use a
|
||||||
// round of refactoring now that we never use its returned
|
// round of refactoring now that we never use its returned
|
||||||
// lambda directly anymore
|
// lambda directly anymore
|
||||||
@@ -343,17 +343,12 @@ void Vst2Bridge::handle_dispatch() {
|
|||||||
plugin,
|
plugin,
|
||||||
[&](AEffect* plugin, int opcode, int index, intptr_t value,
|
[&](AEffect* plugin, int opcode, int index, intptr_t value,
|
||||||
void* data, float option) -> intptr_t {
|
void* data, float option) -> intptr_t {
|
||||||
// On the main thread, instead of running
|
// Certain functions will most definitely involve the GUI or
|
||||||
// `plugin->dispatcher()` (or `dispatch_wrapper()`)
|
// the Win32 message loop. These functions have to be
|
||||||
// directly, we'll run the function within the IO context so
|
// performed on the thread that is running the IO context,
|
||||||
// all events will be executed on the same thread as the one
|
// since this is also where the plugins were instantiated
|
||||||
// that runs the Win32 message loop. In some scenarios we'll
|
// and where the Win32 message loop is handled.
|
||||||
// receive incoming calls from multiple threads or we'll
|
if (unsafe_opcodes.contains(opcode)) {
|
||||||
// receive calls while we're currently stuck in the Win32
|
|
||||||
// message loop. In those cases we'll assume that these
|
|
||||||
// events can be safely handled directlyfrom another thread.
|
|
||||||
if (unsafe_opcodes.contains(opcode) ||
|
|
||||||
(on_main_thread && !plugin_context.event_loop_active)) {
|
|
||||||
std::promise<intptr_t> dispatch_result;
|
std::promise<intptr_t> dispatch_result;
|
||||||
boost::asio::dispatch(plugin_context.context, [&]() {
|
boost::asio::dispatch(plugin_context.context, [&]() {
|
||||||
const intptr_t result = dispatch_wrapper(
|
const intptr_t result = dispatch_wrapper(
|
||||||
|
|||||||
@@ -137,9 +137,6 @@ win32_thread_trampoline(fu2::unique_function<void()>* entry_point);
|
|||||||
* `CreateThread()`, some thread local information does not get initialized
|
* `CreateThread()`, some thread local information does not get initialized
|
||||||
* which can lead to memory errors.
|
* which can lead to memory errors.
|
||||||
*
|
*
|
||||||
* TODO: Once these changes are complete, check if we can drop `PluginContext`
|
|
||||||
* again and execute all 'safe' opcodes on the calling thread.
|
|
||||||
*
|
|
||||||
* @note This should be used instead of `std::thread` or `std::jthread` whenever
|
* @note This should be used instead of `std::thread` or `std::jthread` whenever
|
||||||
* the thread directly calls third party library code, i.e. `LoadLibrary()`,
|
* the thread directly calls third party library code, i.e. `LoadLibrary()`,
|
||||||
* `FreeLibrary()`, the plugin's entry point, or any of the `AEffect::*()`
|
* `FreeLibrary()`, the plugin's entry point, or any of the `AEffect::*()`
|
||||||
|
|||||||
Reference in New Issue
Block a user