22 #include <type_traits> 24 #include <unordered_set> 53 class TimeoutController;
80 static constexpr
size_t kDefaultStackSize{16 * 1024};
86 size_t stackSize{kDefaultStackSize};
104 size_t recordStackEvery{0};
111 size_t maxFibersPoolSize{1000};
116 bool useGuardPages{
true};
141 std::unique_ptr<LoopController> loopController,
152 template <
typename LocalT>
155 std::unique_ptr<LoopController> loopController,
169 void loopUntilNoReady();
174 void loopUntilNoReadyImpl();
179 bool shouldRunLoopRemote();
184 bool hasTasks()
const;
189 bool hasReadyTasks()
const;
205 template <
typename F>
215 template <
typename F>
216 auto addTaskFuture(F&& func)
224 template <
typename F>
225 void addTaskRemote(F&& func);
234 template <
typename F>
235 auto addTaskRemoteFuture(F&& func)
252 template <
typename F,
typename G>
262 template <
typename F>
272 template <
typename T>
275 template <
typename T>
281 size_t fibersAllocated()
const;
287 size_t fibersPoolSize()
const;
292 bool hasActiveFiber()
const;
298 return currentFiber_;
304 size_t stackHighWatermark()
const;
338 return readyFibers_.size() + yieldedFibers_.size();
347 template <
typename F>
349 template <
typename F,
typename G>
353 template <
typename F>
356 template <
typename F>
358 : func(
std::forward<F>(
f)),
367 void activateFiber(
Fiber* fiber);
368 void deactivateFiber(
Fiber* fiber);
388 size_t fibersAllocated_{0};
389 size_t fibersPoolSize_{0};
390 size_t fibersActive_{0};
397 size_t maxFibersActiveLastPeriod_{0};
400 bool isLoopScheduled_{
false};
419 size_t stackHighWatermark_{0};
424 void ensureLoopScheduled();
434 void initLocalData(
Fiber& fiber);
464 ssize_t remoteCount_{0};
477 bool fibersPoolResizerScheduled_{
false};
479 void doFibersPoolResizing();
486 void runReadyFiber(
Fiber* fiber);
487 void remoteReadyInsert(
Fiber* fiber);
489 #ifdef FOLLY_SANITIZE_ADDRESS 494 void registerStartSwitchStackWithAsan(
495 void** saveFakeStack,
496 const void* stackBase,
498 void registerFinishSwitchStackWithAsan(
500 const void** saveStackBase,
501 size_t* saveStackSize);
502 void freeFakeStack(
void* fakeStack);
503 void unpoisonFiberStack(
const Fiber* fiber);
505 #endif // FOLLY_SANITIZE_ADDRESS 508 bool alternateSignalStackRegistered_{
false};
510 void registerAlternateSignalStack();
519 return fm ? fm->hasActiveFiber() :
false;
528 template <
typename F>
544 template <
typename F,
typename G>
547 std::forward<F>(func), std::forward<G>(
finally));
557 template <
typename F>
567 template <
typename F>
573 return fm->runInMainContext(std::forward<F>(func));
583 template <
typename T>
587 return fm->local<
T>();
589 return FiberManager::localThread<T>();
RemoteTask(F &&f, const Fiber::LocalData &localData_)
folly::IntrusiveList< Fiber,&Fiber::listHook_ > FiberTailQueue
folly::Function< void(Fiber &)> awaitFunc_
AtomicIntrusiveLinkedListHook< RemoteTask > nextRemoteTask
typename invoke_result< F, Args... >::type invoke_result_t
FiberTailQueue readyFibers_
constexpr detail::Map< Move > move
static FOLLY_TLS FiberManager * currentFiberManager_
void addTaskFinally(F &&func, G &&finally)
—— Concurrent Priority Queue Implementation ——
void add(folly::Func f) override
folly::IntrusiveList< Fiber,&Fiber::globalListHook_ > GlobalFiberTailQueue
void addTaskFinally(F &&func, G &&finally)
static FiberManager & getFiberManager()
std::unique_ptr< LoopController > loopController_
Single-threaded task execution engine.
folly::Function< void()> func
Fiber * currentFiber() const
Fiber object used by FiberManager to execute tasks.
FiberManager & fiberManager_
static void run(EventBaseManager *ebm, EventBase *eb, folly::Baton<> *stop, const StringPiece &name)
constexpr bool kIsSanitize
virtual ~InlineFunctionRunner()
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
FiberTailQueue fibersPool_
std::shared_ptr< TimeoutController > timeoutManager_
folly::AtomicIntrusiveLinkedList< Fiber,&Fiber::nextRemoteReady_ > remoteReadyQueue_
invoke_result_t< F > runInMainContext(F &&func)
boost::intrusive::list< T, boost::intrusive::member_hook< T, IntrusiveListHook, PtrToMember >, boost::intrusive::constant_time_size< false >> IntrusiveList
FibersPoolResizer fibersPoolResizer_
static FiberManager * getFiberManagerUnsafe()
ExceptionCallback exceptionCallback_
GlobalFiberTailQueue allFibers_
folly::AtomicIntrusiveLinkedList< RemoteTask,&RemoteTask::nextRemoteTask > remoteTaskQueue_
GuardPageAllocator stackAllocator_
size_t runQueueSize() const
folly::Function< void()> immediateFunc_
std::type_index localType_
FibersPoolResizer(FiberManager &fm)
std::shared_ptr< RequestContext > rcontext
std::unique_ptr< Fiber::LocalData > localData
FiberTailQueue yieldedFibers_
FirstArgOf< F >::type::value_type await(F &&func)
FiberManager & getFiberManager(EventBase &evb, const FiberManager::Options &opts)