Esempio n. 1
0
 private StopInstruction Stop(FiberStatus finalStatus)
 {
     // Interlocked isn't necessary because we don't need
     // the initial value (stops are final). They are also
     // only called by the scheduler thread during Execute().
     status = (int)finalStatus;
     FinishCompletion();
     return(FiberInstruction.Stop);
 }
Esempio n. 2
0
        /// <summary>
        /// Invokes the Fiber Action.
        /// </summary>
        /// <param name="fiber">the fiber computation.</param>
        private void InvokeAction(IComputation fiber)
        {
            object      result      = fiber.Execute();
            FiberStatus fiberStatus = (FiberStatus)result;

            if (fiberStatus == FiberStatus.Done)
            {
                scheduler.Remove(fiber);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the given computation.
        /// </summary>
        /// <returns></returns>
        object IComputation.Execute()
        {
            try
            {
                if (fiberContext.MoveNext() == true && status != FiberStatus.Wait)
                {
                    status = fiberContext.Current;
                    return(status);
                }
                else if (status == FiberStatus.Wait)
                {
                    status = FiberStatus.Switch;
                    return(status);
                }
                else
                {
                    status           = FiberStatus.Done;
                    Cookie.Completed = true;

                    //Internal computation doesn't need to set the event.
                    if (!isInternalComputation && wait != null)
                    {
                        wait.Set();
                    }
                }

                return(status);
            }
            catch (Exception ex)
            {
                Cookie.IsException = true;
                Cookie.Exception   = ex;

                if (wait != null)
                {
                    wait.Set();
                }

                return(FiberStatus.Done);
            }
        }
Esempio n. 4
0
 private StopInstruction Stop(FiberStatus finalStatus)
 {
     // Interlocked isn't necessary because we don't need
     // the initial value (stops are final). They are also
     // only called by the scheduler thread during Execute().
     status = (int)finalStatus;
     FinishCompletion ();
     return FiberInstruction.Stop;
 }