SpicyPixel.Threading.Tasks.FiberTaskScheduler.TryExecuteTaskInline C# (CSharp) Method

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
        protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
        {
            // 1. Tasks using fiber schedulers have thread affinity and must run on the thread the scheduler was created on.
            // 2. Fiber tasks cannot run inline here because they may yield which is only handled when queued.
            //
            // That being said, the fiber scheduler may choose to inline anyway when
            // queueing occurs on the scheduler thread, it just doesn't happen in this method.
            if(scheduler.SchedulerThread != Thread.CurrentThread || task is YieldableTask)
                return false;

            return TryExecuteTask(task);
        }