C# Class SpicyPixel.Threading.FiberScheduler

Schedules fibers for execution.
Schedulers are bound to the thread they are created on and they install a SynchronizationContext which is active during execution. Schedulers have an implementation specific update method or run loop. The interface is otherwise thin since schedulers are generally not intended to be used directly. Scheduling work is accomplished by invoking methods on Fiber or SynchronizationContext.
Inheritance: IFiberScheduler, IDisposable
Show file Open project: spicypixel/concurrency-kit-cs Class Usage Examples

Private Properties

Property Type Description
IFiberScheduler void
SetCurrentScheduler void

Public Methods

Method Description
Dispose ( ) : void

Releases all resource used by the SpicyPixel.Threading.FiberScheduler object.

Call the method when you are finished using the SpicyPixel.Threading.FiberScheduler. The method leaves the SpicyPixel.Threading.FiberScheduler in an unusable state. After calling the method, you must release all references to the SpicyPixel.Threading.FiberScheduler so the garbage collector can reclaim the memory that the SpicyPixel.Threading.FiberScheduler was occupying.

Run ( ) : void

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.

Run ( CancellationToken token, float updatesPerSecond = 0f ) : void

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.

Run ( Fiber fiber ) : void

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.

Run ( Fiber fiber, CancellationToken token, float updatesPerSecond = 0f ) : void

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.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Dispose the scheduler.

When the scheduler is disposed, the CancellationToken is set.

ExecuteFiber ( Fiber fiber ) : FiberInstruction

Executes the fiber until it ends or yields.

Custom schedulers will need to invoke this method in order to actually perform the work of the fiber and cause the correct state transitions to occur.

FiberScheduler ( ) : System

Initializes a new instance of the SpicyPixel.Threading.FiberScheduler class.

QueueFiber ( Fiber fiber ) : void

Queues the fiber for execution on the scheduler.

Fibers queued from the scheduler thread will generally be executed inline whenever possible on most schedulers.

Private Methods

Method Description
IFiberScheduler ( Fiber fiber ) : void
SetCurrentScheduler ( FiberScheduler scheduler, bool internalInvoke ) : void

Method Details

Dispose() public method

Releases all resource used by the SpicyPixel.Threading.FiberScheduler object.
Call the method when you are finished using the SpicyPixel.Threading.FiberScheduler. The method leaves the SpicyPixel.Threading.FiberScheduler in an unusable state. After calling the method, you must release all references to the SpicyPixel.Threading.FiberScheduler so the garbage collector can reclaim the memory that the SpicyPixel.Threading.FiberScheduler was occupying.
public Dispose ( ) : void
return void

Dispose() protected method

Dispose the scheduler.
When the scheduler is disposed, the CancellationToken is set.
protected Dispose ( bool disposing ) : void
disposing bool /// Disposing is true when called manually, /// false when called by the finalizer. ///
return void

ExecuteFiber() protected method

Executes the fiber until it ends or yields.
Custom schedulers will need to invoke this method in order to actually perform the work of the fiber and cause the correct state transitions to occur.
protected ExecuteFiber ( Fiber fiber ) : FiberInstruction
fiber Fiber /// The fiber to execute. ///
return FiberInstruction

FiberScheduler() protected method

Initializes a new instance of the SpicyPixel.Threading.FiberScheduler class.
protected FiberScheduler ( ) : System
return System

QueueFiber() protected abstract method

Queues the fiber for execution on the scheduler.
Fibers queued from the scheduler thread will generally be executed inline whenever possible on most schedulers.
protected abstract QueueFiber ( Fiber fiber ) : void
fiber Fiber /// The fiber to queue. ///
return void

Run() public method

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.
public Run ( ) : void
return void

Run() public method

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.
public Run ( CancellationToken token, float updatesPerSecond = 0f ) : void
token System.Threading.CancellationToken /// A cancellation token that can be used to stop execution. ///
updatesPerSecond float /// 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. ///
return void

Run() public method

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.
public Run ( Fiber fiber ) : void
fiber Fiber /// The initial fiber to start on the scheduler. ///
return void

Run() public method

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.
public Run ( Fiber fiber, CancellationToken token, float updatesPerSecond = 0f ) : void
fiber 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. ///
token System.Threading.CancellationToken /// A cancellation token that can be used to stop execution. ///
updatesPerSecond float /// 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. ///
return void