From 05e4a7677ed965509451c86fb77c77aa8b300455 Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Mon, 23 Aug 2021 13:59:13 +0800 Subject: [PATCH] crimson/common: all interruptible future invocations should have already had interrupt condition in place Signed-off-by: Xuehan Xu --- src/crimson/common/interruptible_future.h | 64 +++++++++++------------ 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 81cadb98d6dcd..c098a451499f1 100644 --- a/src/crimson/common/interruptible_future.h +++ b/src/crimson/common/interruptible_future.h @@ -154,30 +154,29 @@ auto call_with_interruption_impl( // need to be interrupted, return an interruption; otherwise, restore the // global "interrupt_cond" with the interruption condition, and go ahead // executing the Func. - if (interrupt_condition) { - auto [interrupt, fut] = interrupt_condition->template may_interrupt< - typename futurator_t::type>(); - INTR_FUT_DEBUG( - "call_with_interruption_impl: may_interrupt: {}, " - "local interrupt_condintion: {}, " - "global interrupt_cond: {},{}", - interrupt, - (void*)interrupt_condition.get(), - (void*)interrupt_cond.interrupt_cond.get(), - typeid(InterruptCond).name()); - if (interrupt) { - return std::move(*fut); - } - interrupt_cond.set(interrupt_condition); - } - - auto fut = seastar::futurize_invoke( + assert(interrupt_condition); + auto [interrupt, fut] = interrupt_condition->template may_interrupt< + typename futurator_t::type>(); + INTR_FUT_DEBUG( + "call_with_interruption_impl: may_interrupt: {}, " + "local interrupt_condintion: {}, " + "global interrupt_cond: {},{}", + interrupt, + (void*)interrupt_condition.get(), + (void*)interrupt_cond.interrupt_cond.get(), + typeid(InterruptCond).name()); + if (interrupt) { + return std::move(*fut); + } + interrupt_cond.set(interrupt_condition); + + auto fut2 = seastar::futurize_invoke( std::forward(func), std::forward(args)...); // Clear the global "interrupt_cond" to prevent it from interfering other // continuation chains. interrupt_cond.reset(); - return fut; + return fut2; } } @@ -256,20 +255,19 @@ Result non_futurized_call_with_interruption( InterruptCondRef interrupt_condition, Func&& func, T&&... args) { - if (interrupt_condition) { - auto [interrupt, fut] = interrupt_condition->template may_interrupt>(); - INTR_FUT_DEBUG( - "non_futurized_call_with_interruption may_interrupt: {}, " - "interrupt_condition: {}, interrupt_cond: {},{}", - interrupt, - (void*)interrupt_condition.get(), - (void*)interrupt_cond.interrupt_cond.get(), - typeid(InterruptCond).name()); - if (interrupt) { - std::rethrow_exception(fut->get_exception()); - } - interrupt_cond.set(interrupt_condition); - } + assert(interrupt_condition); + auto [interrupt, fut] = interrupt_condition->template may_interrupt>(); + INTR_FUT_DEBUG( + "non_futurized_call_with_interruption may_interrupt: {}, " + "interrupt_condition: {}, interrupt_cond: {},{}", + interrupt, + (void*)interrupt_condition.get(), + (void*)interrupt_cond.interrupt_cond.get(), + typeid(InterruptCond).name()); + if (interrupt) { + std::rethrow_exception(fut->get_exception()); + } + interrupt_cond.set(interrupt_condition); try { if constexpr (std::is_void_v) { std::invoke(std::forward(func), std::forward(args)...); -- 2.39.5