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