From db6ea6df2d938494be6528af155503c236b16727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Tue, 14 Mar 2023 18:18:58 +0100 Subject: [PATCH 1/2] #2091: add missing return statement --- src/vt/runnable/runnable.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vt/runnable/runnable.h b/src/vt/runnable/runnable.h index 2bfe5425a1..161d598e69 100644 --- a/src/vt/runnable/runnable.h +++ b/src/vt/runnable/runnable.h @@ -239,6 +239,7 @@ struct RunnableNew { std::invoke(std::forward(c), std::forward(args)...); auto finish_time = timing::getCurrentTime(); finish(finish_time); + return; } else { decltype(auto) r{std::invoke(std::forward(c), std::forward(args)...)}; auto finish_time = timing::getCurrentTime(); From f3d2f04a4968ab80bec5c9cfb6cebc98a86c51f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Wed, 15 Mar 2023 21:25:02 +0100 Subject: [PATCH 2/2] #2091: rework runLambda --- src/vt/runnable/runnable.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/vt/runnable/runnable.h b/src/vt/runnable/runnable.h index 161d598e69..3151a4fe43 100644 --- a/src/vt/runnable/runnable.h +++ b/src/vt/runnable/runnable.h @@ -235,17 +235,19 @@ struct RunnableNew { decltype(auto) runLambda(Callable&& c, Args&&... args) { auto start_time = timing::getCurrentTime(); start(start_time); - if constexpr(std::is_void_v>) { - std::invoke(std::forward(c), std::forward(args)...); - auto finish_time = timing::getCurrentTime(); - finish(finish_time); - return; - } else { - decltype(auto) r{std::invoke(std::forward(c), std::forward(args)...)}; - auto finish_time = timing::getCurrentTime(); - finish(finish_time); - return r; - } + + // Arrange a scope guard to call finish() without any sort of dynamic allocation + struct finisher { + RunnableNew* r; + finisher(RunnableNew* in_r) : r(in_r){}; + ~finisher() { + auto finish_time = timing::getCurrentTime(); + r->finish(finish_time); + } + }; + finisher f(this); + + return std::invoke(std::forward(c), std::forward(args)...); } #if vt_check_enabled(fcontext)