Skip to content

Commit

Permalink
Extend FuncRunner to include ExecutionObserver list callbacks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Giorgi Papakerashvili authored and facebook-github-bot committed Feb 29, 2024
1 parent dbd1856 commit 7c77eef
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions folly/io/async/EventBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -947,8 +954,8 @@ bool EventBase::runLoopCallbacks() {

void EventBase::initNotificationQueue() {
// Infinite size queue
queue_ =
std::make_unique<EventBaseAtomicNotificationQueue<Func, FuncRunner>>();
queue_ = std::make_unique<EventBaseAtomicNotificationQueue<Func, FuncRunner>>(
FuncRunner{*this});

// Mark this as an internal event, so event_base_loop() will return if
// there are no other events besides this one installed.
Expand Down

0 comments on commit 7c77eef

Please sign in to comment.