From 7c77eef4df2fd8ff3d37ccf190ad2a6d4b5e7e08 Mon Sep 17 00:00:00 2001 From: Giorgi Papakerashvili Date: Wed, 28 Feb 2024 22:22:12 -0800 Subject: [PATCH] Extend FuncRunner to include ExecutionObserver list callbacks Summary: I'm trying to land this again. I had to revert because 100+ tests failed in Payments side: https://www.internalfb.com/phabricator/paste/view/P1189678203 I had to revert previous diff due to T180498582. The trigger for those tests was `Func&& func` making func rvalue. # Updated: std::exchange(func, {})(); fixes the issue, Reviewed By: ot, dmm-fb Differential Revision: D54236364 fbshipit-source-id: d6051c37c433c8b323d7b96c71aa5c48482d4897 --- folly/io/async/EventBase.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 26d49812858..f162de1dc9e 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -184,7 +184,15 @@ namespace folly { class EventBase::FuncRunner { public: - void operator()(Func func) noexcept { func(); } + explicit FuncRunner(EventBase& eventBase) : eventBase_(eventBase) {} + void operator()(Func&& func) noexcept { + ExecutionObserverScopeGuard guard( + &eventBase_.getExecutionObserverList(), &func); + std::exchange(func, {})(); + } + + private: + EventBase& eventBase_; }; class EventBase::ThreadIdCollector : public WorkerProvider { @@ -592,7 +600,6 @@ EventBase::LoopStatus EventBase::loopMain(int flags, LoopOptions options) { // loop callback scheduled by execute(), so if there is an enqueue after the // empty check here the queue's event will eventually be active. if (res != 0 && !queue_->empty()) { - ExecutionObserverScopeGuard guard(&executionObserverList_, queue_.get()); queue_->execute(); } @@ -947,8 +954,8 @@ bool EventBase::runLoopCallbacks() { void EventBase::initNotificationQueue() { // Infinite size queue - queue_ = - std::make_unique>(); + queue_ = std::make_unique>( + FuncRunner{*this}); // Mark this as an internal event, so event_base_loop() will return if // there are no other events besides this one installed.