Commit 808e54f2 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot 3

Support custom loop runner for EventBaseLoopController

Summary: This allows having some logic executed before and after FiberManager loop (e.g. grabbing a Python GIL).

Reviewed By: A5he

Differential Revision: D3616752

fbshipit-source-id: 3be35d54ced458328816d583133457a44a863acd
parent 22008a54
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
#include <folly/Memory.h> #include <folly/Memory.h>
#include <folly/fibers/EventBaseLoopController.h> #include <folly/fibers/EventBaseLoopController.h>
#include <folly/fibers/FiberManager.h>
namespace folly { namespace folly {
namespace fibers { namespace fibers {
...@@ -63,7 +62,11 @@ inline void EventBaseLoopController::cancel() { ...@@ -63,7 +62,11 @@ inline void EventBaseLoopController::cancel() {
} }
inline void EventBaseLoopController::runLoop() { inline void EventBaseLoopController::runLoop() {
fm_->loopUntilNoReady(); if (loopRunner_) {
loopRunner_->run([&] { fm_->loopUntilNoReady(); });
} else {
fm_->loopUntilNoReady();
}
} }
inline void EventBaseLoopController::scheduleThreadSafe( inline void EventBaseLoopController::scheduleThreadSafe(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
#pragma once #pragma once
#include <folly/fibers/FiberManager.h>
#include <folly/fibers/LoopController.h> #include <folly/fibers/LoopController.h>
#include <folly/io/async/EventBase.h> #include <folly/io/async/EventBase.h>
#include <atomic> #include <atomic>
...@@ -27,8 +28,6 @@ class EventBase; ...@@ -27,8 +28,6 @@ class EventBase;
namespace folly { namespace folly {
namespace fibers { namespace fibers {
class FiberManager;
class EventBaseLoopController : public LoopController { class EventBaseLoopController : public LoopController {
public: public:
explicit EventBaseLoopController(); explicit EventBaseLoopController();
...@@ -43,6 +42,10 @@ class EventBaseLoopController : public LoopController { ...@@ -43,6 +42,10 @@ class EventBaseLoopController : public LoopController {
return eventBase_; return eventBase_;
} }
void setLoopRunner(InlineFunctionRunner* loopRunner) {
loopRunner_ = loopRunner;
}
private: private:
class ControllerCallback : public folly::EventBase::LoopCallback { class ControllerCallback : public folly::EventBase::LoopCallback {
public: public:
...@@ -93,6 +96,7 @@ class EventBaseLoopController : public LoopController { ...@@ -93,6 +96,7 @@ class EventBaseLoopController : public LoopController {
FiberManager* fm_{nullptr}; FiberManager* fm_{nullptr};
std::atomic<bool> eventBaseAttached_{false}; std::atomic<bool> eventBaseAttached_{false};
std::weak_ptr<void> aliveWeak_; std::weak_ptr<void> aliveWeak_;
InlineFunctionRunner* loopRunner_{nullptr};
/* LoopController interface */ /* LoopController interface */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment