mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-17 00:43:56 +02:00
Use std::jthread
This commit is contained in:
@@ -102,12 +102,11 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
|
||||
async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] ");
|
||||
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
|
||||
|
||||
stdio_handler = std::thread([&]() { stdio_context.run(); });
|
||||
stdio_handler = std::jthread([&]() { stdio_context.run(); });
|
||||
}
|
||||
|
||||
GroupBridge::~GroupBridge() {
|
||||
stdio_context.stop();
|
||||
stdio_handler.join();
|
||||
}
|
||||
|
||||
void GroupBridge::handle_plugin_dispatch(const GroupRequest request) {
|
||||
@@ -129,8 +128,7 @@ void GroupBridge::handle_plugin_dispatch(const GroupRequest request) {
|
||||
boost::asio::post(plugin_context, [&, request]() {
|
||||
std::lock_guard lock(active_plugins_mutex);
|
||||
|
||||
auto& [thread, bridge] = active_plugins.at(request);
|
||||
thread.join();
|
||||
// The join is implicit because we're using std::jthread
|
||||
active_plugins.erase(request);
|
||||
});
|
||||
|
||||
@@ -220,7 +218,7 @@ void GroupBridge::accept_requests() {
|
||||
// socket on another thread. The actual event handling will
|
||||
// still occur within this IO context.
|
||||
active_plugins[request] =
|
||||
std::pair(std::thread([&, request]() {
|
||||
std::pair(std::jthread([&, request]() {
|
||||
handle_plugin_dispatch(request);
|
||||
}),
|
||||
std::move(bridge));
|
||||
|
||||
@@ -240,7 +240,7 @@ class GroupBridge {
|
||||
/**
|
||||
* A thread that runs the `stdio_context` loop.
|
||||
*/
|
||||
std::thread stdio_handler;
|
||||
std::jthread stdio_handler;
|
||||
|
||||
boost::asio::local::stream_protocol::endpoint group_socket_endpoint;
|
||||
/**
|
||||
@@ -255,14 +255,9 @@ class GroupBridge {
|
||||
* 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.
|
||||
*
|
||||
* TODO: Check again if we can just use std::thread here instead, that would
|
||||
* make everything much simpler. `std::thread` was a problem with
|
||||
* gdiplus in the past as Serum would randomly crash because calling
|
||||
* conventions were nto being respected.
|
||||
*/
|
||||
std::unordered_map<GroupRequest,
|
||||
std::pair<std::thread, std::unique_ptr<Vst2Bridge>>>
|
||||
std::pair<std::jthread, std::unique_ptr<Vst2Bridge>>>
|
||||
active_plugins;
|
||||
/**
|
||||
* A mutex to prevent two threads from simultaneously accessing the plugins
|
||||
|
||||
@@ -94,7 +94,7 @@ int __cdecl main(int argc, char* argv[]) {
|
||||
|
||||
// We'll listen for `dispatcher()` calls on a different thread, but the
|
||||
// actual events will still be executed within the IO context
|
||||
std::thread dispatch_handler([&]() { bridge->handle_dispatch(); });
|
||||
std::jthread dispatch_handler([&]() { bridge->handle_dispatch(); });
|
||||
|
||||
// Handle Win32 messages and X11 events on a timer, just like in
|
||||
// `GroupBridge::async_handle_events()``
|
||||
@@ -102,7 +102,6 @@ int __cdecl main(int argc, char* argv[]) {
|
||||
async_handle_events(events_timer, *bridge);
|
||||
|
||||
io_context.run();
|
||||
dispatch_handler.join();
|
||||
}
|
||||
|
||||
void async_handle_events(boost::asio::steady_timer& timer, Vst2Bridge& bridge) {
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
* converting stateless lambdas to this format, but clang (as used for IDE
|
||||
* tooling) does not.
|
||||
*
|
||||
* @note This should be used instead of `std::thread` whenever the thread
|
||||
* directly calls third party library code, i.e. `LoadLibrary()`,
|
||||
* @note This should be used instead of `std::thread` or `std::jthread` whenever
|
||||
* the thread directly calls third party library code, i.e. `LoadLibrary()`,
|
||||
* `FreeLibrary()`, the plugin's entry point, or any of the `AEffect::*()`
|
||||
* functions.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user