Commit 7c0d945b authored by Christopher Wei's avatar Christopher Wei Committed by Facebook GitHub Bot

Add virtual event base interface for getFiberManager

Summary: Adds a version of getFiberManager that takes a VirtualEventBase + FrozenOptions

Reviewed By: yfeldblum

Differential Revision: D21507009

fbshipit-source-id: 2bffd1704650b25e78fc388b3e033da4f2c16b9a
parent d33c823f
......@@ -226,5 +226,12 @@ FiberManager& getFiberManager(
opts.token, evb, opts.options);
}
FiberManager& getFiberManager(
VirtualEventBase& evb,
const FiberManager::FrozenOptions& opts) {
return detail::ThreadLocalCache<VirtualEventBase>::get<void>(
opts.token, evb, opts.options);
}
} // namespace fibers
} // namespace folly
......@@ -39,6 +39,10 @@ static inline FiberManager& getFiberManager(
static inline FiberManager& getFiberManager(
folly::EventBase& evb,
const FiberManager::FrozenOptions& opts);
static inline FiberManager& getFiberManager(
folly::VirtualEventBase& evb,
const FiberManager::FrozenOptions& opts);
} // namespace fibers
} // namespace folly
#include <folly/fibers/FiberManagerMap-inl.h>
......@@ -1675,6 +1675,31 @@ TEST(FiberManager, nestedFiberManagersSameEvb) {
.waitVia(&evb);
}
TEST(FiberManager, virtualEvbFiberManager) {
folly::EventBase evb;
auto& vevb = evb.getVirtualEventBase();
// Eventbase vs VirtualEventBase used for multiplexing
auto& fm1 = getFiberManager(evb);
auto& fm2 = getFiberManager(vevb);
EXPECT_NE(&fm1, &fm2);
FiberManager::Options opt;
opt.stackSize = 1024;
// Option is not used in multiplexing
auto& fm3 = getFiberManager(evb, opt);
auto& fm4 = getFiberManager(vevb, opt);
EXPECT_EQ(&fm1, &fm3);
EXPECT_EQ(&fm2, &fm4);
// Frozen option used in multiplexing
FiberManager::FrozenOptions fopt(opt);
auto& fm5 = getFiberManager(evb, fopt);
auto& fm6 = getFiberManager(vevb, fopt);
EXPECT_NE(&fm1, &fm5);
EXPECT_NE(&fm2, &fm6);
}
TEST(FiberManager, semaphore) {
static constexpr size_t kTasks = 10;
static constexpr size_t kIterations = 10000;
......
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