From 57d7141681b85f7e5bc7b19779cd1d6de8dc5663 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 19 May 2021 22:54:05 +0200 Subject: [PATCH] Remove redundant template arguments in MainContext --- src/wine-host/bridges/vst2.cpp | 2 +- src/wine-host/bridges/vst3.cpp | 73 +++++++++++++++++----------------- src/wine-host/bridges/vst3.h | 2 +- src/wine-host/utils.h | 14 ++++--- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/wine-host/bridges/vst2.cpp b/src/wine-host/bridges/vst2.cpp index c6e69e69..3fdf061a 100644 --- a/src/wine-host/bridges/vst2.cpp +++ b/src/wine-host/bridges/vst2.cpp @@ -394,7 +394,7 @@ void Vst2Bridge::run() { // handled. if (unsafe_opcodes.contains(opcode)) { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> intptr_t { const intptr_t result = dispatch_wrapper(plugin, opcode, index, value, data, option); diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index ff0852c9..6c278915 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -148,7 +148,7 @@ void Vst3Bridge::run() { [&](const Vst3PlugViewProxy::Destruct& request) -> Vst3PlugViewProxy::Destruct::Response { main_context - .run_in_context([&]() { + .run_in_context([&]() -> void { // When the pointer gets dropped by the host, we want to // drop it here as well, along with the `IPlugFrame` // proxy object it may have received in @@ -179,29 +179,28 @@ void Vst3Bridge::run() { // shouldn't) Steinberg::IPtr object = main_context - .run_in_context>( - [&]() -> Steinberg::IPtr { - switch (request.requested_interface) { - case Vst3PluginProxy::Construct::Interface:: - IComponent: - return module->getFactory() - .createInstance< - Steinberg::Vst::IComponent>( - cid); - break; - case Vst3PluginProxy::Construct::Interface:: - IEditController: - return module->getFactory() - .createInstance< - Steinberg::Vst:: - IEditController>(cid); - break; - default: - // Unreachable - return nullptr; - break; - } - }) + .run_in_context([&]() -> Steinberg::IPtr< + Steinberg::FUnknown> { + switch (request.requested_interface) { + case Vst3PluginProxy::Construct::Interface:: + IComponent: + return module->getFactory() + .createInstance< + Steinberg::Vst::IComponent>(cid); + break; + case Vst3PluginProxy::Construct::Interface:: + IEditController: + return module->getFactory() + .createInstance< + Steinberg::Vst::IEditController>( + cid); + break; + default: + // Unreachable + return nullptr; + break; + } + }) .get(); if (!object) { @@ -466,7 +465,7 @@ void Vst3Bridge::run() { -> YaEditController::CreateView::Response { // Instantiate the object from the GUI thread main_context - .run_in_context([&]() { + .run_in_context([&]() -> void { // NOTE: Just like in the event loop, we want to run // this with lower priority to prevent whatever // operation the plugin does while it's loading @@ -527,7 +526,7 @@ void Vst3Bridge::run() { // certain channel context data, so this has to be run from the // main thread return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.instance_id] .info_listener->setChannelContextInfos( &request.list); @@ -703,7 +702,7 @@ void Vst3Bridge::run() { // Creating the window and having the plugin embed in it should // be done in the main UI thread return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { set_realtime_priority(false); Editor& editor_instance = object_instances[request.owner_instance_id] @@ -730,7 +729,7 @@ void Vst3Bridge::run() { [&](const YaPlugView::Removed& request) -> YaPlugView::Removed::Response { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { // Cleanup is handled through RAII set_realtime_priority(false); const tresult result = @@ -749,7 +748,7 @@ void Vst3Bridge::run() { // Since all of these `IPlugView::on*` functions can cause a // redraw, they all have to be called from the UI thread return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.owner_instance_id] .plug_view_instance->plug_view->onWheel( request.distance); @@ -759,7 +758,7 @@ void Vst3Bridge::run() { [&](const YaPlugView::OnKeyDown& request) -> YaPlugView::OnKeyDown::Response { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.owner_instance_id] .plug_view_instance->plug_view->onKeyDown( request.key, request.key_code, @@ -770,7 +769,7 @@ void Vst3Bridge::run() { [&](const YaPlugView::OnKeyUp& request) -> YaPlugView::OnKeyUp::Response { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.owner_instance_id] .plug_view_instance->plug_view->onKeyUp( request.key, request.key_code, @@ -810,7 +809,7 @@ void Vst3Bridge::run() { [&](const YaPlugView::OnFocus& request) -> YaPlugView::OnFocus::Response { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.owner_instance_id] .plug_view_instance->plug_view->onFocus( request.state); @@ -836,7 +835,7 @@ void Vst3Bridge::run() { // since 80% of the `IPlugView` functions have to be we'll do it // here anyways return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.owner_instance_id] .plug_view_instance->plug_view->setFrame( object_instances[request.owner_instance_id] @@ -878,7 +877,7 @@ void Vst3Bridge::run() { return Steinberg::kNotImplemented; } else { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances [request.owner_instance_id] .plug_view_instance @@ -903,7 +902,7 @@ void Vst3Bridge::run() { // `IPlugView::{initialize,terminate}`, we'll run these // functions from the main GUI thread return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { // This static cast is required to upcast to `FUnknown*` const tresult result = object_instances[request.instance_id] @@ -925,7 +924,7 @@ void Vst3Bridge::run() { [&](const YaPluginBase::Terminate& request) -> YaPluginBase::Terminate::Response { return main_context - .run_in_context([&]() { + .run_in_context([&]() -> tresult { return object_instances[request.instance_id] .plugin_base->terminate(); }) @@ -1377,7 +1376,7 @@ void Vst3Bridge::unregister_object_instance(size_t instance_id) { // executed and when the actual host application context on // the plugin side gets deallocated. main_context - .run_in_context([&, instance_id]() { + .run_in_context([&, instance_id]() -> void { std::lock_guard lock(object_instances_mutex); object_instances.erase(instance_id); }) diff --git a/src/wine-host/bridges/vst3.h b/src/wine-host/bridges/vst3.h index e0112c0c..852359c2 100644 --- a/src/wine-host/bridges/vst3.h +++ b/src/wine-host/bridges/vst3.h @@ -307,7 +307,7 @@ class Vst3Bridge : public HostBridge { mutual_recursion.maybe_handle(std::forward(fn))) { return *result; } else { - return main_context.run_in_context(std::forward(fn)).get(); + return main_context.run_in_context(std::forward(fn)).get(); } } diff --git a/src/wine-host/utils.h b/src/wine-host/utils.h index f67f2836..95ea561f 100644 --- a/src/wine-host/utils.h +++ b/src/wine-host/utils.h @@ -239,13 +239,15 @@ class MainContext { * return the results as a future. This is used to make sure that operations * that may involve the Win32 message loop are all run from the same thread. */ - template - std::future run_in_context(F fn) { - std::packaged_task call_fn(std::move(fn)); - std::future response = call_fn.get_future(); + template + std::future> run_in_context(F&& fn) { + using Result = std::invoke_result_t; + + std::packaged_task call_fn(std::forward(fn)); + std::future result = call_fn.get_future(); boost::asio::dispatch(context, std::move(call_fn)); - return response; + return result; } /** @@ -253,7 +255,7 @@ class MainContext { * is that this version does not guarantee that it's going to be executed as * soon as possible, and thus we also won't return a future. */ - template + template void schedule_task(F&& fn) { boost::asio::post(context, std::forward(fn)); }