This class is the system default implementation of a FiberScheduler and is capable of scheduling and executing fibers on the current thread. More...
Public Member Functions | |
SystemFiberScheduler () | |
Initializes a new instance of the SpicyPixel.Threading.FiberScheduler class. More... | |
override void | Run (Fiber fiber, CancellationToken token, float updatesPerSecond) |
Run the blocking scheduler loop and perform the specified number of updates per second. More... | |
Public Member Functions inherited from SpicyPixel.Threading.FiberScheduler | |
void | Run (Fiber fiber) |
Run the blocking scheduler loop and perform the specified number of updates per second. More... | |
void | Run () |
Run the blocking scheduler loop and perform the specified number of updates per second. More... | |
virtual void | Run (CancellationToken token, float updatesPerSecond=0f) |
Run the blocking scheduler loop and perform the specified number of updates per second. More... | |
void | Dispose () |
Releases all resource used by the SpicyPixel.Threading.FiberScheduler object. More... | |
Static Public Member Functions | |
static SystemFiberScheduler | StartNew () |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread. More... | |
static SystemFiberScheduler | StartNew (CancellationToken token, float updatesPerSecond=0f) |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread. More... | |
static SystemFiberScheduler | StartNew (Fiber fiber) |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread. More... | |
static SystemFiberScheduler | StartNew (Fiber fiber, CancellationToken token, float updatesPerSecond=0f) |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread. More... | |
Protected Member Functions | |
sealed override void | QueueFiber (Fiber fiber) |
Queues the fiber for execution on the scheduler. More... | |
void | Update (float time) |
Update the scheduler which causes all queued tasks to run for a cycle. More... | |
sealed override void | AbortRequested (Fiber fiber) |
Invoked when an abort has been requested. More... | |
bool | GetNextFiberWakeTime (out float fiberWakeTime) |
Gets the time of the first fiber wake up. More... | |
override void | Dispose (bool disposing) |
Dispose the scheduler. More... | |
Protected Member Functions inherited from SpicyPixel.Threading.FiberScheduler | |
FiberScheduler () | |
Initializes a new instance of the SpicyPixel.Threading.FiberScheduler class. More... | |
FiberInstruction | ExecuteFiber (Fiber fiber) |
Executes the fiber until it ends or yields. More... | |
Properties | |
ManualResetEvent | RunWaitHandle [get] |
Gets the run wait handle. More... | |
WaitHandle | DisposeWaitHandle [get] |
Gets the dispose wait handle. More... | |
WaitHandle | SchedulerEventWaitHandle [get] |
Gets a wait handle which can be used to wait for a scheduler event to occur. More... | |
int | ExecutingFiberCount [get] |
Gets the executing fiber count. More... | |
int | SleepingFiberCount [get] |
Gets the sleeping fiber count. More... | |
Properties inherited from SpicyPixel.Threading.FiberScheduler | |
CancellationToken | CancellationToken [get] |
Gets the cancellation token set when the scheduler is destroyed. More... | |
static FiberScheduler | Current [get] |
Gets the default fiber scheduler for the thread. More... | |
Thread | SchedulerThread [get] |
Gets the thread the scheduler is running on. More... | |
bool | AllowInlining [get, set] |
Gets or sets a value indicating whether this SpicyPixel.Threading.FiberScheduler allows inlining. More... | |
Detailed Description
This class is the system default implementation of a FiberScheduler and is capable of scheduling and executing fibers on the current thread.
Although no fibers execute after the scheduler is shutdown, none of the fibers are transitioned to a FiberStatus.RanToCompletion state and therefore it's not safe for a fiber to wait on a fiber outside of its own scheduler. This is currently enforced by FiberScheduler.ExecuteFiber for now although it would be possible to support fiber waits across schedulers in the future.
Definition at line 46 of file SystemFiberScheduler.cs.
Constructor & Destructor Documentation
SpicyPixel.Threading.SystemFiberScheduler.SystemFiberScheduler | ( | ) |
Initializes a new instance of the SpicyPixel.Threading.FiberScheduler class.
Definition at line 248 of file SystemFiberScheduler.cs.
Member Function Documentation
|
protectedvirtual |
Invoked when an abort has been requested.
- Parameters
-
fiber The fiber to be aborted.
Implements SpicyPixel.Threading.FiberScheduler.
Definition at line 414 of file SystemFiberScheduler.cs.
|
protectedvirtual |
Dispose the scheduler.
When the scheduler is disposed, the CancellationToken is set.
- Parameters
-
disposing Disposing is true when called manually, false when called by the finalizer.
Reimplemented from SpicyPixel.Threading.FiberScheduler.
Definition at line 796 of file SystemFiberScheduler.cs.
|
protected |
Gets the time of the first fiber wake up.
This method is primarily useful when manually calling Update() instead of Run() to know how long the thread can sleep for.
- Returns
- True if there was a sleeping fiber, false otherwise.
- Parameters
-
fiberWakeTime The time marker in seconds the first sleeping fiber needs to wake up. This is based on a previously passed time value to Update(). This value may be 0 if a sleeping fiber was aborted and therefore an update should process immediately.
Definition at line 435 of file SystemFiberScheduler.cs.
|
protectedvirtual |
Queues the fiber for execution on the scheduler.
Fibers queued from the scheduler thread will generally be executed inline whenever possible on most schedulers.
- Parameters
-
fiber The fiber to queue.
Implements SpicyPixel.Threading.FiberScheduler.
Definition at line 262 of file SystemFiberScheduler.cs.
|
virtual |
Run the blocking scheduler loop and perform the specified number of updates per second.
Not all schedulers support a blocking run loop that can be invoked by the caller. The system scheduler is designed so that a custom run loop could be implemented by a derived type. Everything used to execute Run() is available to a derived scheduler.
- Parameters
-
fiber The optional fiber to start execution from. If this is null
, the loop will continue to execute until cancelled. Otherwise, the loop will terminate when the fiber terminates.updatesPerSecond Updates to all fibers per second. A value of 0
(the default) will execute fibers any time they are ready to do work instead of waiting to execute on a specific frequency.token A cancellation token that can be used to stop execution.
Reimplemented from SpicyPixel.Threading.FiberScheduler.
Definition at line 485 of file SystemFiberScheduler.cs.
|
static |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread.
- Returns
- The scheduler from the spawned thread.
Definition at line 54 of file SystemFiberScheduler.cs.
|
static |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread.
- Returns
- The scheduler from the spawned thread.
- Parameters
-
token A token to cancel the thread. updatesPerSecond Updates to run per second.
Definition at line 71 of file SystemFiberScheduler.cs.
|
static |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread.
- Returns
- The scheduler from the spawned thread.
- Parameters
-
fiber A fiber to start execution from.
Definition at line 85 of file SystemFiberScheduler.cs.
|
static |
Starts a new thread, creates a scheduler, starts it running, and returns it to the calling thread.
- Returns
- The scheduler from the spawned thread.
- Parameters
-
fiber A fiber to start execution from. updatesPerSecond Updates to run per second. token A token to cancel the thread.
Definition at line 105 of file SystemFiberScheduler.cs.
|
protected |
Update the scheduler which causes all queued tasks to run for a cycle.
This method is useful when updating the scheduler manually with a custom run loop instead of calling Run(Fiber, CancellationToken, float).
- Parameters
-
time Time in seconds since the scheduler or application began running. This value is used to determine when to wake sleeping fibers. Using float instead of TimeSpan spares the GC.
Definition at line 348 of file SystemFiberScheduler.cs.
Property Documentation
|
getprotected |
Gets the dispose wait handle.
Run monitors this handle for a Dispose to know when to terminate.
The dispose wait handle.
Definition at line 191 of file SystemFiberScheduler.cs.
|
getprotected |
Gets the executing fiber count.
This can be used to optimize a custom run loop.
The executing fiber count.
Definition at line 227 of file SystemFiberScheduler.cs.
|
getprotected |
Gets the run wait handle.
The run wait handle is set when not running and used to coordinate Dispose and Run.
The run wait handle.
Definition at line 177 of file SystemFiberScheduler.cs.
|
getprotected |
Gets a wait handle which can be used to wait for a scheduler event to occur.
Scheduler events trigger this handle to be signaled. Events occur any time a fiber is added to an execution queue, whether because it is new or because it is moving from a wait queue to an execution queue.
This handle is used to sleep in Run() when there are no events to process, and a scheduler with a custom run loop may do the same.
The scheduler event wait handle.
Definition at line 213 of file SystemFiberScheduler.cs.
|
getprotected |
Gets the sleeping fiber count.
This can be used to optimize a custom run loop.
The sleeping fiber count.
Definition at line 241 of file SystemFiberScheduler.cs.
The documentation for this class was generated from the following file: