mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-16 00:13:55 +02:00
Use simple numerical IDs for plugins in groups
We'll be using a similar approach to identify threads for event handlers.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#include "vst2.h"
|
||||
@@ -132,21 +133,21 @@ class GroupBridge {
|
||||
* `accept_requests` since it has to be initiated inside of the IO context's
|
||||
* thread.
|
||||
*
|
||||
* Once the plugin has exited, this thread will then remove itself from the
|
||||
* `active_plugins` map. If this causes the vector to become empty, we will
|
||||
* terminate this process. This check will be delayed by a few seconds to
|
||||
* prevent having to constantly restart the group process during plugin
|
||||
* scanning.
|
||||
* Once the plugin has exited, this thread will then be joined to the main
|
||||
* thread and removed from the `active_plugins` from the main IO context. If
|
||||
* this causes the vector to become empty, we will terminate this process.
|
||||
* This check is delayed by a few seconds to prevent having to constantly
|
||||
* restart the group process during plugin scanning.
|
||||
*
|
||||
* @param request Information about the plugin to launch, i.e. the path to
|
||||
* the plugin and the path of the socket endpoint that will be used for
|
||||
* communication.
|
||||
* @param plugin_id The ID of this plugin in the `active_plugins` map. The
|
||||
* thread can fetch the plugin's `Vst2Bridge` instance from that map using
|
||||
* this identifier.
|
||||
*
|
||||
* @note In the case that the process starts but no plugin gets initiated,
|
||||
* then the process will never exit on its own. This should not happen
|
||||
* though.
|
||||
*/
|
||||
void handle_plugin_dispatch(const GroupRequest request);
|
||||
void handle_plugin_dispatch(size_t plugin_id);
|
||||
|
||||
/**
|
||||
* Listen for new requests to spawn plugins within this process and handle
|
||||
@@ -257,11 +258,19 @@ class GroupBridge {
|
||||
* along with their plugin instance. After a plugin has exited or its
|
||||
* initialization has failed, the thread handling it will remove itself from
|
||||
* this map. This is to keep track of the amount of plugins currently
|
||||
* running with their associated thread handles.
|
||||
* running with their associated thread handles. The key that identifies the
|
||||
* thread and plugin is a unique plugin ID obtained by doing a fetch-and-add
|
||||
* on `next_plugin_id`.
|
||||
*/
|
||||
std::unordered_map<GroupRequest,
|
||||
std::unordered_map<size_t,
|
||||
std::pair<std::jthread, std::unique_ptr<Vst2Bridge>>>
|
||||
active_plugins;
|
||||
/**
|
||||
* A counter for the next unique plugin ID. When hosting a new plugin we'll
|
||||
* do a fetch-and-add to ensure that every thread gets its own unique
|
||||
* identifier.
|
||||
*/
|
||||
std::atomic_size_t next_plugin_id;
|
||||
/**
|
||||
* A mutex to prevent two threads from simultaneously accessing the plugins
|
||||
* map, and also to prevent `handle_plugin_dispatch()` from terminating the
|
||||
|
||||
Reference in New Issue
Block a user