Skip to content

Commit

Permalink
#2091: rework runLambda
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Mar 15, 2023
1 parent 1146554 commit ba98f55
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/vt/runnable/runnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_result_t<Callable, Args...>>) {
std::invoke(std::forward<Callable>(c), std::forward<Args>(args)...);
auto finish_time = timing::getCurrentTime();
finish(finish_time);
return;
} else {
decltype(auto) r{std::invoke(std::forward<Callable>(c), std::forward<Args>(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<Callable>(c), std::forward<Args>(args)...);
}

#if vt_check_enabled(fcontext)
Expand Down

0 comments on commit ba98f55

Please sign in to comment.