Replace std::jthread with Win32Thread everywhere

This commit is contained in:
Robbert van der Helm
2020-10-27 17:38:13 +01:00
parent 59b57f48da
commit a6b5951d81
3 changed files with 13 additions and 13 deletions
+4 -3
View File
@@ -98,7 +98,7 @@ GroupBridge::GroupBridge(boost::filesystem::path group_socket_path)
async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] "); async_log_pipe_lines(stdout_redirect.pipe, stdout_buffer, "[STDOUT] ");
async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] "); async_log_pipe_lines(stderr_redirect.pipe, stderr_buffer, "[STDERR] ");
stdio_handler = std::jthread([&]() { stdio_context.run(); }); stdio_handler = Win32Thread([&]() { stdio_context.run(); });
} }
GroupBridge::~GroupBridge() { GroupBridge::~GroupBridge() {
@@ -128,7 +128,8 @@ void GroupBridge::handle_plugin_dispatch(size_t plugin_id) {
boost::asio::post(plugin_context.context, [this, plugin_id]() { boost::asio::post(plugin_context.context, [this, plugin_id]() {
std::lock_guard lock(active_plugins_mutex); std::lock_guard lock(active_plugins_mutex);
// The join is implicit because we're using std::jthread // The join is implicit because we're using Win32Thread (which mimics
// std::jthread)
active_plugins.erase(plugin_id); active_plugins.erase(plugin_id);
}); });
@@ -219,7 +220,7 @@ void GroupBridge::accept_requests() {
// is only used within this context we don't need any locks. // is only used within this context we don't need any locks.
const size_t plugin_id = next_plugin_id.fetch_add(1); const size_t plugin_id = next_plugin_id.fetch_add(1);
active_plugins[plugin_id] = active_plugins[plugin_id] =
std::pair(std::jthread([this, plugin_id]() { std::pair(Win32Thread([this, plugin_id]() {
handle_plugin_dispatch(plugin_id); handle_plugin_dispatch(plugin_id);
}), }),
std::move(bridge)); std::move(bridge));
+2 -2
View File
@@ -244,7 +244,7 @@ class GroupBridge {
/** /**
* A thread that runs the `stdio_context` loop. * A thread that runs the `stdio_context` loop.
*/ */
std::jthread stdio_handler; Win32Thread stdio_handler;
boost::asio::local::stream_protocol::endpoint group_socket_endpoint; boost::asio::local::stream_protocol::endpoint group_socket_endpoint;
/** /**
@@ -263,7 +263,7 @@ class GroupBridge {
* on `next_plugin_id`. * on `next_plugin_id`.
*/ */
std::unordered_map<size_t, std::unordered_map<size_t,
std::pair<std::jthread, std::unique_ptr<Vst2Bridge>>> std::pair<Win32Thread, std::unique_ptr<Vst2Bridge>>>
active_plugins; active_plugins;
/** /**
* A counter for the next unique plugin ID. When hosting a new plugin we'll * A counter for the next unique plugin ID. When hosting a new plugin we'll
+7 -8
View File
@@ -60,13 +60,12 @@ int __cdecl main(int argc, char* argv[]) {
<< std::endl; << std::endl;
// As explained in `Vst2Bridge`, the plugin has to be initialized in the // As explained in `Vst2Bridge`, the plugin has to be initialized in the
// same thread as the one that calls `io_context.run()`. And for some // same thread as the one that calls `io_context.run()`. This setup is
// reason, a lot of plugins have memory corruption issues when executing // slightly more convoluted than it has to be, but doing it this way we
// `LoadLibrary()` or some of their functions from within a `std::thread` // don't need to differentiate between individually hosted plugins and
// (although the WinAPI `CreateThread()` does not have these issues). This // plugin groups when it comes to event handling.
// setup is slightly more convoluted than it has to be, but doing it this // TODO: Update documentation once we figure out if we can safely replace
// way we don't need to differentiate between individually hosted plugins // PluginContext again with a normal `io_context`.
// and plugin groups when it comes to event handling.
PluginContext plugin_context{}; PluginContext plugin_context{};
std::unique_ptr<Vst2Bridge> bridge; std::unique_ptr<Vst2Bridge> bridge;
try { try {
@@ -84,7 +83,7 @@ int __cdecl main(int argc, char* argv[]) {
// We'll listen for `dispatcher()` calls on a different thread, but the // We'll listen for `dispatcher()` calls on a different thread, but the
// actual events will still be executed within the IO context // actual events will still be executed within the IO context
std::jthread dispatch_handler([&]() { bridge->handle_dispatch(); }); Win32Thread dispatch_handler([&]() { bridge->handle_dispatch(); });
// Handle Win32 messages and X11 events on a timer, just like in // Handle Win32 messages and X11 events on a timer, just like in
// `GroupBridge::async_handle_events()`` // `GroupBridge::async_handle_events()``