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 @@
*/
#include <folly/Memory.h>
#include <folly/fibers/EventBaseLoopController.h>
#include <folly/fibers/FiberManager.h>
namespace folly {
namespace fibers {
......@@ -63,7 +62,11 @@ inline void EventBaseLoopController::cancel() {
}
inline void EventBaseLoopController::runLoop() {
fm_->loopUntilNoReady();
if (loopRunner_) {
loopRunner_->run([&] { fm_->loopUntilNoReady(); });
} else {
fm_->loopUntilNoReady();
}
}
inline void EventBaseLoopController::scheduleThreadSafe(
......
......@@ -15,6 +15,7 @@
*/
#pragma once
#include <folly/fibers/FiberManager.h>
#include <folly/fibers/LoopController.h>
#include <folly/io/async/EventBase.h>
#include <atomic>
......@@ -27,8 +28,6 @@ class EventBase;
namespace folly {
namespace fibers {
class FiberManager;
class EventBaseLoopController : public LoopController {
public:
explicit EventBaseLoopController();
......@@ -43,6 +42,10 @@ class EventBaseLoopController : public LoopController {
return eventBase_;
}
void setLoopRunner(InlineFunctionRunner* loopRunner) {
loopRunner_ = loopRunner;
}
private:
class ControllerCallback : public folly::EventBase::LoopCallback {
public:
......@@ -93,6 +96,7 @@ class EventBaseLoopController : public LoopController {
FiberManager* fm_{nullptr};
std::atomic<bool> eventBaseAttached_{false};
std::weak_ptr<void> aliveWeak_;
InlineFunctionRunner* loopRunner_{nullptr};
/* 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