Commit 09446426 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Put the current fiber manager behind an accessor

Summary: [Folly] Put the current fiber manager behind an accessor function v.s. having it as a static class member.

Reviewed By: andriigrynenko

Differential Revision: D19229507

fbshipit-source-id: 7cf4eab00ee281bc6104f994a71f5e48d9553852
parent ac05b70a
main v2022.02.14.00 v2022.02.07.00 v2022.01.31.00 v2022.01.24.00 v2022.01.17.00 v2022.01.10.00 v2022.01.03.00 v2021.12.27.00 v2021.12.20.00 v2021.12.13.00 v2021.12.06.00 v2021.11.29.00 v2021.11.15.00 v2021.11.08.00 v2021.11.01.00 v2021.10.25.00 v2021.10.18.00 v2021.10.11.00 v2021.10.04.00 v2021.09.27.00 v2021.09.20.00 v2021.09.13.00 v2021.09.06.00 v2021.08.30.00 v2021.08.23.00 v2021.08.02.00 v2021.07.22.00 v2021.07.20.01 v2021.07.20.00 v2021.06.28.00 v2021.06.14.00 v2021.06.07.00 v2021.05.31.00 v2021.05.24.00 v2021.05.17.00 v2021.05.10.00 v2021.05.03.00 v2021.04.26.00 v2021.04.19.00 v2021.04.12.00 v2021.04.05.00 v2021.03.29.00 v2021.03.22.00 v2021.03.15.00 v2021.03.08.00 v2021.03.01.00 v2021.02.22.00 v2021.02.15.00 v2021.02.08.00 v2021.02.01.00 v2021.01.25.00 v2021.01.18.01 v2021.01.18.00 v2021.01.11.00 v2021.01.04.00 v2020.12.28.00 v2020.12.21.00 v2020.12.14.00 v2020.12.07.00 v2020.11.30.00 v2020.11.23.00 v2020.11.16.00 v2020.11.09.00 v2020.11.02.00 v2020.10.26.00 v2020.10.19.00 v2020.10.12.00 v2020.10.05.00 v2020.09.28.00 v2020.09.21.00 v2020.09.14.00 v2020.09.07.00 v2020.08.31.00 v2020.08.24.00 v2020.08.17.00 v2020.08.10.00 v2020.08.03.00 v2020.07.27.00 v2020.07.20.00 v2020.07.13.00 v2020.07.06.00 v2020.06.29.00 v2020.06.15.00 v2020.06.08.00 v2020.06.01.00 v2020.05.25.00 v2020.05.18.00 v2020.05.11.00 v2020.05.04.00 v2020.04.27.00 v2020.04.20.00 v2020.04.13.00 v2020.04.06.00 v2020.03.30.00 v2020.03.23.00 v2020.03.16.00 v2020.03.09.00 v2020.03.02.00 v2020.02.24.00 v2020.02.17.00 v2020.02.10.00
No related merge requests found
......@@ -78,12 +78,15 @@ struct hash<folly::fibers::FiberManager::Options> {
namespace folly {
namespace fibers {
FOLLY_TLS FiberManager* FiberManager::currentFiberManager_ = nullptr;
auto FiberManager::FrozenOptions::create(const Options& options) -> ssize_t {
return std::hash<Options>()(options);
}
/* static */ FiberManager*& FiberManager::getCurrentFiberManager() {
static FOLLY_TLS FiberManager* currentFiberManager;
return currentFiberManager;
}
FiberManager::FiberManager(
std::unique_ptr<LoopController> loopController,
Options options)
......
......@@ -202,7 +202,7 @@ void FiberManager::runFibersHelper(LoopFunc&& loopFunc) {
#endif
// Support nested FiberManagers
auto originalFiberManager = std::exchange(currentFiberManager_, this);
auto originalFiberManager = std::exchange(getCurrentFiberManager(), this);
numUncaughtExceptions_ = uncaught_exceptions();
currentException_ = std::current_exception();
......@@ -227,7 +227,7 @@ void FiberManager::runFibersHelper(LoopFunc&& loopFunc) {
if (!readyFibers_.empty()) {
ensureLoopScheduled();
}
std::swap(currentFiberManager_, originalFiberManager);
std::swap(getCurrentFiberManager(), originalFiberManager);
CHECK_EQ(this, originalFiberManager);
};
......@@ -534,12 +534,12 @@ invoke_result_t<F> FiberManager::runInMainContext(F&& func) {
}
inline FiberManager& FiberManager::getFiberManager() {
assert(currentFiberManager_ != nullptr);
return *currentFiberManager_;
assert(getCurrentFiberManager() != nullptr);
return *getCurrentFiberManager();
}
inline FiberManager* FiberManager::getFiberManagerUnsafe() {
return currentFiberManager_;
return getCurrentFiberManager();
}
inline bool FiberManager::hasActiveFiber() const {
......@@ -547,7 +547,7 @@ inline bool FiberManager::hasActiveFiber() const {
}
inline void FiberManager::yield() {
assert(currentFiberManager_ == this);
assert(getCurrentFiberManager() == this);
assert(activeFiber_ != nullptr);
assert(activeFiber_->state_ == Fiber::RUNNING);
activeFiber_->preempt(Fiber::YIELDED);
......
......@@ -490,7 +490,7 @@ class FiberManager : public ::folly::Executor {
* When we are inside FiberManager loop this points to FiberManager. Otherwise
* it's nullptr
*/
static FOLLY_TLS FiberManager* currentFiberManager_;
static FiberManager*& getCurrentFiberManager();
/**
* Allocator used to allocate stack for Fibers in the pool.
......
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