C# Class SpicyPixel.Threading.Tasks.FiberTaskScheduler

TaskScheduler that can execute fibers (yieldable coroutines). Regular non-blocking tasks can also be scheduled on a FiberTaskScheduler, but YieldableTask have the distinct ability to yield execution.
Inheritance: System.Threading.Tasks.TaskScheduler, IDisposable
Datei anzeigen Open project: spicypixel/concurrency-kit-cs Class Usage Examples

Public Methods

Method Description
Dispose ( ) : void

Releases all resource used by the SpicyPixel.Threading.Tasks.FiberTaskScheduler object.

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

FiberTaskScheduler ( ) : System

Initializes a new instance of the SpicyPixel.Threading.Tasks.FiberTaskScheduler class.

Derived classes should invoke EnableQueueTask() in their constructor when ready to begin executing tasks.

FiberTaskScheduler ( FiberScheduler scheduler ) : System

Initializes a new instance of the SpicyPixel.Threading.Tasks.FiberTaskScheduler class.

Derived classes should invoke EnableQueueTask() in their constructor when ready to begin executing tasks.

Protected Methods

Method Description
GetScheduledTasks ( ) : IEnumerable

For debugger support only, generates an enumerable of Task instances currently queued to the scheduler waiting to be executed.

This is not supported and will always return null.

QueueTask ( Task task ) : void

Queues a non-blocking task.

If the task is queued from the scheduler thread it will begin executing to its first yield immediately.

TryDequeue ( Task task ) : bool

Tries to dequeue a task.

Only delay start tasks can be dequeued. Although the Fiber scheduler does delay start tasks queued from a non-scheduler thread, de-queuing is not supported right now and so this method always returns false.

TryExecuteTaskInline ( Task task, bool taskWasPreviouslyQueued ) : bool

Tries to execute the task inline.

Tasks executed on a fiber scheduler have thread affinity and must run on the thread the scheduler was created online. Inline execution will therefore fail if attempted from another thread besides the scheduler thread.

A YieldableTask cannot run inline because yieldable tasks can only be processed by a FiberTaskScheduler when queued.

Because of these restrictions, only standard non-blocking actions invoked on the scheduler thread are eligible for inlining.

Private Methods

Method Description
Dispose ( bool disposing ) : void

Dispose the scheduler.

When the scheduler is disposed, the CancellationToken is set.

ExecuteTask ( Task task ) : IEnumerator

Execute the specified task as a coroutine.

ExecuteYieldableTask ( YieldableTask task ) : IEnumerator

Execute the specified coroutine associated with a yieldable task.

Any exceptions that occur while executing the fiber will be associated with the specified task and rethrown by the framework.

Method Details

Dispose() public method

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

FiberTaskScheduler() public method

Initializes a new instance of the SpicyPixel.Threading.Tasks.FiberTaskScheduler class.
Derived classes should invoke EnableQueueTask() in their constructor when ready to begin executing tasks.
public FiberTaskScheduler ( ) : System
return System

FiberTaskScheduler() public method

Initializes a new instance of the SpicyPixel.Threading.Tasks.FiberTaskScheduler class.
Derived classes should invoke EnableQueueTask() in their constructor when ready to begin executing tasks.
public FiberTaskScheduler ( FiberScheduler scheduler ) : System
scheduler FiberScheduler
return System

GetScheduledTasks() protected method

For debugger support only, generates an enumerable of Task instances currently queued to the scheduler waiting to be executed.
This is not supported and will always return null.
protected GetScheduledTasks ( ) : IEnumerable
return IEnumerable

QueueTask() protected method

Queues a non-blocking task.
If the task is queued from the scheduler thread it will begin executing to its first yield immediately.
protected QueueTask ( Task task ) : void
task Task /// The non-blocking task to queue. ///
return void

TryDequeue() protected method

Tries to dequeue a task.
Only delay start tasks can be dequeued. Although the Fiber scheduler does delay start tasks queued from a non-scheduler thread, de-queuing is not supported right now and so this method always returns false.
protected TryDequeue ( Task task ) : bool
task Task /// The task to dequeue. ///
return bool

TryExecuteTaskInline() protected method

Tries to execute the task inline.

Tasks executed on a fiber scheduler have thread affinity and must run on the thread the scheduler was created online. Inline execution will therefore fail if attempted from another thread besides the scheduler thread.

A YieldableTask cannot run inline because yieldable tasks can only be processed by a FiberTaskScheduler when queued.

Because of these restrictions, only standard non-blocking actions invoked on the scheduler thread are eligible for inlining.

protected TryExecuteTaskInline ( Task task, bool taskWasPreviouslyQueued ) : bool
task Task /// The task to execute. ///
taskWasPreviouslyQueued bool /// Set to true if the task was previously queued, false otherwise. ///
return bool