Summary: Previously we'd call ensureLoopScheduled() but it'd be a no-op since the loop was already scheduled. Delaying the call to ensureLoopScheduled() fixes the issue
Test Plan: unit tests (FiberManager.yieldTest fails without the changes to FiberManager-inl.h)
Reviewed By: andrii@fb.com
Subscribers: folly-diffs@, yfeldblum, chalfant
FB internal diff:
D1993686
Signature: t1:
1993686:
1429070253:
af933abbbbb33868a402f1d643e4e6f5fef1be83
inline bool FiberManager::loopUntilNoReady() {
SCOPE_EXIT {
isLoopScheduled_ = false;
+ if (!readyFibers_.empty()) {
+ ensureLoopScheduled();
+ }
currentFiberManager_ = nullptr;
};
);
}
- if (!yieldedFibers_.empty()) {
- readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
- ensureLoopScheduled();
- }
+ readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
return fibersActive_ > 0;
}
testFiberLocal<LargeData>();
}
+TEST(FiberManager, yieldTest) {
+ FiberManager manager(folly::make_unique<SimpleLoopController>());
+ auto& loopController =
+ dynamic_cast<SimpleLoopController&>(manager.loopController());
+
+ bool checkRan = false;
+
+ manager.addTask(
+ [&]() {
+ manager.yield();
+ checkRan = true;
+ }
+ );
+
+ loopController.loop(
+ [&]() {
+ if (checkRan) {
+ loopController.stop();
+ }
+ }
+ );
+
+ EXPECT_TRUE(checkRan);
+}
+
static size_t sNumAwaits;
void runBenchmark(size_t numAwaits, size_t toSend) {