Commit 03b404df authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Fiber LoopController's schedule cleanup

Summary: On top of the recent/big EventBaseLoopController cleanup away from most EventBase internal, this is unecessary

Reviewed By: andriigrynenko

Differential Revision: D7734236

fbshipit-source-id: df38cc30fc52df929f096fb878bc1a4b6894850a
parent 199a5bc8
......@@ -84,8 +84,7 @@ inline void EventBaseLoopController::runLoop() {
}
}
inline void EventBaseLoopController::scheduleThreadSafe(
std::function<bool()> func) {
inline void EventBaseLoopController::scheduleThreadSafe() {
/* The only way we could end up here is if
1) Fiber thread creates a fiber that awaits (which means we must
have already attached, fiber thread wouldn't be running).
......@@ -93,17 +92,15 @@ inline void EventBaseLoopController::scheduleThreadSafe(
3) We fulfill the promise from the other thread. */
assert(eventBaseAttached_);
if (func()) {
eventBase_->runInEventBaseThread([this]() {
if (fm_->shouldRunLoopRemote()) {
return runLoop();
}
eventBase_->runInEventBaseThread([this]() {
if (fm_->shouldRunLoopRemote()) {
return runLoop();
}
if (!fm_->hasTasks()) {
eventBaseKeepAlive_.reset();
}
});
}
if (!fm_->hasTasks()) {
eventBaseKeepAlive_.reset();
}
});
}
inline void EventBaseLoopController::timedSchedule(
......
......@@ -70,7 +70,7 @@ class EventBaseLoopController : public LoopController {
void setFiberManager(FiberManager* fm) override;
void schedule() override;
void runLoop() override;
void scheduleThreadSafe(std::function<bool()> func) override;
void scheduleThreadSafe() override;
void timedSchedule(std::function<void()> func, TimePoint time) override;
friend class FiberManager;
......
......@@ -60,8 +60,8 @@ namespace fibers {
static AsanStartSwitchStackFuncPtr getStartSwitchStackFunc();
static AsanFinishSwitchStackFuncPtr getFinishSwitchStackFunc();
static AsanUnpoisonMemoryRegionFuncPtr getUnpoisonMemoryRegionFunc();
}
}
} // namespace fibers
} // namespace folly
#endif
......@@ -150,8 +150,9 @@ void FiberManager::remoteReadyInsert(Fiber* fiber) {
if (observer_) {
observer_->runnable(reinterpret_cast<uintptr_t>(fiber));
}
auto insertHead = [&]() { return remoteReadyQueue_.insertHead(fiber); };
loopController_->scheduleThreadSafe(std::ref(insertHead));
if (remoteReadyQueue_.insertHead(fiber)) {
loopController_->scheduleThreadSafe();
}
}
void FiberManager::setObserver(ExecutionObserver* observer) {
......
......@@ -335,10 +335,9 @@ void FiberManager::addTaskRemote(F&& func) {
}
return std::make_unique<RemoteTask>(std::forward<F>(func));
}();
auto insertHead = [&]() {
return remoteTaskQueue_.insertHead(task.release());
};
loopController_->scheduleThreadSafe(std::ref(insertHead));
if (remoteTaskQueue_.insertHead(task.release())) {
loopController_->scheduleThreadSafe();
}
}
template <typename X>
......
......@@ -49,9 +49,8 @@ class LoopController {
/**
* Same as schedule(), but safe to call from any thread.
* Runs func and only schedules if func returned true.
*/
virtual void scheduleThreadSafe(std::function<bool()> func) = 0;
virtual void scheduleThreadSafe() = 0;
/**
* Called by FiberManager to schedule some function to be run at some time.
......
......@@ -116,11 +116,9 @@ class SimpleLoopController : public LoopController {
fm_ = fm;
}
void scheduleThreadSafe(std::function<bool()> func) override {
if (func()) {
++remoteScheduleCalled_;
scheduled_ = true;
}
void scheduleThreadSafe() override {
++remoteScheduleCalled_;
scheduled_ = true;
}
friend class FiberManager;
......
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