mirror of
https://github.com/clearlinux/folly.git
synced 2026-09-01 11:15:52 +00:00
Ensure the loop callback is scheduled when the ready queue is not empty
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
This commit is contained in:
committed by
Alecs King
parent
30d8a3d688
commit
d8cd7bc7a0
@@ -97,6 +97,9 @@ inline void FiberManager::runReadyFiber(Fiber* fiber) {
|
||||
inline bool FiberManager::loopUntilNoReady() {
|
||||
SCOPE_EXIT {
|
||||
isLoopScheduled_ = false;
|
||||
if (!readyFibers_.empty()) {
|
||||
ensureLoopScheduled();
|
||||
}
|
||||
currentFiberManager_ = nullptr;
|
||||
};
|
||||
|
||||
@@ -135,10 +138,7 @@ inline bool FiberManager::loopUntilNoReady() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!yieldedFibers_.empty()) {
|
||||
readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
|
||||
ensureLoopScheduled();
|
||||
}
|
||||
readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
|
||||
|
||||
return fibersActive_ > 0;
|
||||
}
|
||||
|
||||
@@ -1281,6 +1281,31 @@ TEST(FiberManager, fiberLocalHeap) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user