From 301b2c6b8afe1fe3771584aa15b3ebaabdff05aa Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Tue, 6 Dec 2022 12:06:39 +0000 Subject: [PATCH] crimson/common: bring green_get() to interruptor The rationale ============= Calling `get()` on an unavailable future can result in yielding the reactor, so -- from the interruptor's POV -- the interrupt condition must be handled exactly like it is done for `yield()`. Interruptor takes care about that but, at the moment, only for the interruptible futures; there is mechanism for plain `seastar::future`. This patch paves the way for handling them as well. Signed-off-by: Radoslaw Zarzynski --- src/crimson/common/interruptible_future.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 6ae8689357be1..c0e2c346c88b3 100644 --- a/src/crimson/common/interruptible_future.h +++ b/src/crimson/common/interruptible_future.h @@ -1413,6 +1413,28 @@ public: return ret; } + template + static decltype(auto) green_get(FutureT&& fut) { + if (fut.available()) { + return fut.get(); + } else { + // destined to wait! + auto interruption_condition = interrupt_cond.interrupt_cond; + INTR_FUT_DEBUG( + "green_get() waiting, interrupt_cond: {},{}", + (void*)interrupt_cond.interrupt_cond.get(), + typeid(InterruptCond).name()); + interrupt_cond.reset(); + auto&& value = fut.get(); + interrupt_cond.set(interruption_condition); + INTR_FUT_DEBUG( + "green_get() got, interrupt_cond: {},{}", + (void*)interrupt_cond.interrupt_cond.get(), + typeid(InterruptCond).name()); + return std::move(value); + } + } + static void yield() { ceph_assert(interrupt_cond.interrupt_cond); auto interruption_condition = interrupt_cond.interrupt_cond; -- 2.39.5