|
cortex 0.0.1
|
Manages cooperative execution of fibers. More...
#include <scheduler.hpp>
Classes | |
| struct | Config |
| Configuration options for the scheduler. More... | |
Public Member Functions | |
| Scheduler (const Scheduler &)=delete | |
| Scheduler & | operator= (const Scheduler &)=delete |
| Scheduler (Scheduler &&)=delete | |
| Scheduler & | operator= (Scheduler &&)=delete |
| ~Scheduler () | |
| bool | Step () |
| Run one step of the scheduler. | |
| bool | IsDone () const noexcept |
| Check if all fibers have completed. | |
| std::size_t | GetDefaultStackSize () const noexcept |
| Get the default stack size for new fibers. | |
| MemoryResourceSharedPtr | GetMemoryResource () const noexcept |
| Get the memory resource used by this scheduler. | |
| bool | IsRunning () const noexcept |
| Check if the scheduler is currently running. | |
| bool | IsStopping () const noexcept |
| Check if the scheduler is stopping (being destroyed). | |
| void | Stop () |
| Signal all fibers to stop and wake suspended ones. | |
Static Public Member Functions | |
| template<typename F > | |
| static void | Run (F &&entry) |
| Run the scheduler with an initial fiber. | |
| template<typename F > | |
| static void | Run (F &&entry, Config config) |
| Run the scheduler with an initial fiber and custom config. | |
| template<typename F > | |
| static std::unique_ptr< Scheduler > | Create (F &&entry) |
| Create a scheduler for manual stepping (WASM/async integration). | |
| template<typename F > | |
| static std::unique_ptr< Scheduler > | Create (F &&entry, Config config) |
| Create a scheduler for manual stepping with custom config. | |
| static Scheduler & | Current () |
| Get the current scheduler. | |
Friends | |
| class | detail::Fiber |
| template<typename T > | |
| class | Future |
| class | Mutex |
| class | ConditionVariable |
| void | Yield () |
| Yield control to other ready fibers. | |
| bool | YieldIfOthersReady () |
| Yield only if there are other ready fibers. | |
Manages cooperative execution of fibers.
The scheduler maintains a ready queue of fibers and runs them one at a time until all fibers complete.
Two modes of operation:
|
delete |
| cortex::tiny_fiber::Scheduler::~Scheduler | ( | ) |
|
static |
Create a scheduler for manual stepping with custom config.
Get the current scheduler.
Must be called from within a fiber.
| std::logic_error | if called outside of a fiber. |
|
inlinenoexcept |
Get the default stack size for new fibers.
|
inlinenoexcept |
Get the memory resource used by this scheduler.
|
inlinenoexcept |
Check if all fibers have completed.
|
inlinenoexcept |
Check if the scheduler is currently running.
|
inlinenoexcept |
Check if the scheduler is stopping (being destroyed).
Fibers can check this to exit gracefully during shutdown.
|
delete |
|
delete |
Run the scheduler with an initial fiber.
Blocks until all fibers complete.
| entry | The function to run in the initial fiber. |
Run the scheduler with an initial fiber and custom config.
| entry | The function to run in the initial fiber. |
| config | Configuration options. |
| bool cortex::tiny_fiber::Scheduler::Step | ( | ) |
Run one step of the scheduler.
Picks one ready fiber and runs it until it yields or completes. Use this for WASM integration with JS event loop.
| void cortex::tiny_fiber::Scheduler::Stop | ( | ) |
Signal all fibers to stop and wake suspended ones.
Called automatically during destruction, but can be called manually to initiate graceful shutdown.
|
friend |
|
friend |
|
friend |
Yield control to other ready fibers.
The current fiber is placed at the back of the ready queue. Must be called from within a fiber.
| std::logic_error | if called outside of a fiber. |
| SchedulerStoppingError | if the scheduler is stopping. |
|
friend |
Yield only if there are other ready fibers.
| std::logic_error | if called outside of a fiber. |
| SchedulerStoppingError | if the scheduler is stopping. |