Commit 5981f1bb authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Rename AsyncioLoopController to ExecutorLoopController (and move to fibers/)

Summary:
AsyncioLoopController is totally generic.
We were able, after all, to put all the python specifics in the Executor, and keep it simple.
I'm using it with ManualExecutor succesfully in my project.

Reviewed By: andriigrynenko

Differential Revision: D8085689

fbshipit-source-id: 007f65a72e41aa98113b7ee4e188719d9bc20340
parent d7c9486d
......@@ -17,18 +17,18 @@
#pragma once
namespace folly {
namespace python {
namespace fibers {
inline AsyncioLoopController::AsyncioLoopController(AsyncioExecutor* executor)
inline ExecutorLoopController::ExecutorLoopController(folly::Executor* executor)
: executor_(executor) {}
inline AsyncioLoopController::~AsyncioLoopController() {}
inline ExecutorLoopController::~ExecutorLoopController() {}
inline void AsyncioLoopController::setFiberManager(fibers::FiberManager* fm) {
inline void ExecutorLoopController::setFiberManager(fibers::FiberManager* fm) {
fm_ = fm;
}
inline void AsyncioLoopController::schedule() {
inline void ExecutorLoopController::schedule() {
// add() is thread-safe, so this isn't properly optimized for addTask()
if (!executorKeepAlive_) {
executorKeepAlive_ = getKeepAliveToken(executor_);
......@@ -36,7 +36,7 @@ inline void AsyncioLoopController::schedule() {
executor_->add([this]() { return runLoop(); });
}
inline void AsyncioLoopController::runLoop() {
inline void ExecutorLoopController::runLoop() {
if (!executorKeepAlive_) {
if (!fm_->hasTasks()) {
return;
......@@ -49,7 +49,7 @@ inline void AsyncioLoopController::runLoop() {
}
}
inline void AsyncioLoopController::scheduleThreadSafe() {
inline void ExecutorLoopController::scheduleThreadSafe() {
executor_->add(
[this, executorKeepAlive = getKeepAliveToken(executor_)]() mutable {
if (fm_->shouldRunLoopRemote()) {
......@@ -58,11 +58,11 @@ inline void AsyncioLoopController::scheduleThreadSafe() {
});
}
inline void AsyncioLoopController::timedSchedule(
inline void ExecutorLoopController::timedSchedule(
std::function<void()>,
TimePoint) {
throw std::logic_error("Time schedule isn't supported by asyncio executor");
}
} // namespace python
} // namespace fibers
} // namespace folly
......@@ -18,21 +18,24 @@
#include <memory>
#include <folly/Executor.h>
#include <folly/fibers/FiberManagerInternal.h>
#include <folly/fibers/LoopController.h>
#include <folly/python/AsyncioExecutor.h>
namespace folly {
namespace python {
namespace fibers {
class AsyncioLoopController : public fibers::LoopController {
/**
* A fiber loop controller that works for arbitrary folly::Executor
*/
class ExecutorLoopController : public fibers::LoopController {
public:
explicit AsyncioLoopController(AsyncioExecutor* executor);
~AsyncioLoopController() override;
explicit ExecutorLoopController(folly::Executor* executor);
~ExecutorLoopController() override;
private:
AsyncioExecutor* executor_;
Executor::KeepAlive<AsyncioExecutor> executorKeepAlive_;
folly::Executor* executor_;
Executor::KeepAlive<> executorKeepAlive_;
fibers::FiberManager* fm_{nullptr};
void setFiberManager(fibers::FiberManager* fm) override;
......@@ -44,7 +47,7 @@ class AsyncioLoopController : public fibers::LoopController {
friend class fibers::FiberManager;
};
} // namespace python
} // namespace fibers
} // namespace folly
#include <folly/python/AsyncioLoopController-inl.h>
#include <folly/fibers/ExecutorLoopController-inl.h>
......@@ -11,8 +11,8 @@ cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers"
cdef cppclass cFiberManager "folly::fibers::FiberManager":
cFiberManager(unique_ptr[cLoopController], const cFiberManagerOptions&)
cdef extern from "folly/python/AsyncioLoopController.h" namespace "folly::python":
cdef cppclass cAsyncioLoopController "folly::python::AsyncioLoopController"(cLoopController):
cdef extern from "folly/fibers/ExecutorLoopController.h" namespace "folly::fibers":
cdef cppclass cAsyncioLoopController "folly::fibers::ExecutorLoopController"(cLoopController):
cAsyncioLoopController(cAsyncioExecutor*)
cdef api cFiberManager* get_fiber_manager(const cFiberManagerOptions&)
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