mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-16 08:23:55 +02:00
Also use rwlocks on the VST3 plugin side
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "../../common/communication/vst3.h"
|
||||
@@ -73,6 +74,15 @@ class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
||||
*/
|
||||
Steinberg::IPluginFactory* get_plugin_factory();
|
||||
|
||||
/**
|
||||
* Fetch the plugin proxy instance along with a lock valid for the
|
||||
* instance's lifetime. This is mostly just to save some boilerplate
|
||||
* everywhere. Use C++17's structured binding as syntactic sugar to not have
|
||||
* to deal with the lock handle.
|
||||
*/
|
||||
std::pair<Vst3PluginProxyImpl&, std::shared_lock<std::shared_mutex>>
|
||||
get_proxy(size_t instance_id) noexcept;
|
||||
|
||||
/**
|
||||
* Add a `Vst3PluginProxyImpl` to the list of registered proxy objects so we
|
||||
* can handle host callbacks. This function is called in
|
||||
@@ -194,21 +204,26 @@ class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
||||
*/
|
||||
Steinberg::IPtr<Vst3PluginFactoryProxyImpl> plugin_factory = nullptr;
|
||||
|
||||
public:
|
||||
/**
|
||||
* All VST3 plugin objects we created from this plugin. We keep track of
|
||||
* these in case the plugin does a host callback, so we can associate that
|
||||
* call with the exact host context object passed to it during a call to
|
||||
* `initialize()`. The IDs here are the same IDs as generated by the Wine
|
||||
* plugin host. An instance is added here through a call by
|
||||
* `register_plugin_proxy()` in the constractor, and an instance is then
|
||||
* removed through a call to `unregister_plugin_proxy()` in the destructor.
|
||||
* `register_plugin_proxy()` in `Vst3PluginProxyImpl`'s constructor, and an
|
||||
* instance is then removed through a call to `unregister_plugin_proxy()` in
|
||||
* the destructor.
|
||||
*/
|
||||
std::unordered_map<size_t, std::reference_wrapper<Vst3PluginProxyImpl>>
|
||||
plugin_proxies;
|
||||
|
||||
private:
|
||||
std::mutex plugin_proxies_mutex;
|
||||
/**
|
||||
* In theory all object handling is safe iff the host also doesn't do
|
||||
* anything weird even without locks, but we'll still prevent adding or
|
||||
* removing instances while accessing other instances at the same time
|
||||
* anyways. See `Vst3Bridge::object_instances_mutex` for more details.
|
||||
*/
|
||||
std::shared_mutex plugin_proxies_mutex;
|
||||
|
||||
/**
|
||||
* Used in `Vst3Bridge::send_mutually_recursive_message()` to be able to
|
||||
|
||||
Reference in New Issue
Block a user