From: Casey Bodley Date: Tue, 25 Mar 2025 22:06:36 +0000 (-0400) Subject: common/async: yield_waiter can return the associated executor X-Git-Tag: v21.0.1~14^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=165f2ec18188c8a6e81a2a1960a6d27e57a77dd3;p=ceph.git common/async: yield_waiter can return the associated executor also adds an empty() function so it's easier to specify its precondition Signed-off-by: Casey Bodley --- diff --git a/src/common/async/yield_waiter.h b/src/common/async/yield_waiter.h index 6ace1f2efc4..60c2e613aee 100644 --- a/src/common/async/yield_waiter.h +++ b/src/common/async/yield_waiter.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,18 @@ class yield_waiter { /// Returns true if there's a handler awaiting completion. operator bool() const { return state.has_value(); } + /// Returns false if there's a handler awaiting completion. + bool empty() const { return !state.has_value(); } + + /// Returns the captured completion handler's executor. + /// Precondition: !empty() + using executor_type = boost::asio::any_io_executor; + executor_type get_executor() const + { + return boost::asio::get_associated_executor( + state->handler, state->work.get_executor()); + } + /// Suspends the given yield_context until the captured handler is invoked /// via complete() or cancel(). template @@ -167,6 +180,18 @@ class yield_waiter { /// Returns true if there's a handler awaiting completion. operator bool() const { return state.has_value(); } + /// Returns false if there's a handler awaiting completion. + bool empty() const { return !state.has_value(); } + + /// Returns the captured completion handler's executor. + /// Precondition: !empty() + using executor_type = boost::asio::any_io_executor; + executor_type get_executor() const + { + return boost::asio::get_associated_executor( + state->handler, state->work.get_executor()); + } + /// Suspends the given yield_context until the captured handler is invoked /// via complete() or cancel(). template