8#include <unordered_map>
106 return ready_queue_.empty() && !current_fiber_;
153 template <
typename T>
169 return current_fiber_;
176 void SuspendCurrent();
182 bool HasOtherReadyFibers()
const;
185 void ProcessPendingCleanup();
189 bool running_ {
false};
190 bool stopping_ {
false};
191 detail::Fiber* current_fiber_ {
nullptr};
192 std::deque<detail::Fiber*> ready_queue_;
193 std::unordered_map<detail::Fiber::Id, std::unique_ptr<detail::Fiber>> fibers_;
194 std::vector<detail::Fiber::Id> pending_cleanup_;
static constexpr std::size_t kDefaultStackSizeBytes
Definition coroutine.hpp:30
A cooperative condition variable.
Definition condition_variable.hpp:21
Handle to a spawned fiber that returns a value.
Definition future.hpp:46
A cooperative mutex that yields instead of blocking.
Definition mutex.hpp:21
Manages cooperative execution of fibers.
Definition scheduler.hpp:28
static std::unique_ptr< Scheduler > Create(F &&entry)
Create a scheduler for manual stepping (WASM/async integration).
Definition scheduler.hpp:211
MemoryResourceSharedPtr GetMemoryResource() const noexcept
Get the memory resource used by this scheduler.
Definition scheduler.hpp:119
Scheduler(Scheduler &&)=delete
void Stop()
Signal all fibers to stop and wake suspended ones.
Scheduler & operator=(Scheduler &&)=delete
bool IsDone() const noexcept
Check if all fibers have completed.
Definition scheduler.hpp:105
friend bool YieldIfOthersReady()
Yield only if there are other ready fibers.
static Scheduler & Current()
Get the current scheduler.
bool Step()
Run one step of the scheduler.
static void Run(F &&entry)
Run the scheduler with an initial fiber.
Definition scheduler.hpp:199
bool IsStopping() const noexcept
Check if the scheduler is stopping (being destroyed).
Definition scheduler.hpp:135
bool IsRunning() const noexcept
Check if the scheduler is currently running.
Definition scheduler.hpp:126
friend class Future
Definition scheduler.hpp:154
std::size_t GetDefaultStackSize() const noexcept
Get the default stack size for new fibers.
Definition scheduler.hpp:112
Scheduler(const Scheduler &)=delete
Scheduler & operator=(const Scheduler &)=delete
friend void Yield()
Yield control to other ready fibers.
fu2::unique_function< void()> Body
Definition fiber.hpp:35
std::uint64_t Id
Definition fiber.hpp:34
Cooperative multitasking primitives built on cortex::Coroutine.
Definition condition_variable.hpp:13
MemoryResourceSharedPtr GetDefaultMemoryResource()
std::shared_ptr< MemoryResource > MemoryResourceSharedPtr
Definition memory_resource.hpp:30
Configuration options for the scheduler.
Definition scheduler.hpp:34
std::size_t default_stack_size
Definition scheduler.hpp:35
MemoryResourceSharedPtr memory_resource
Definition scheduler.hpp:36