Ejemplo n.º 1
0
        internal override void DoWork(ref Worker wr)
        {
            var pk  = this.pk;
            var cts = this.cts;

            if (null == cts)
            {
                goto Done;
            }
            this.cts = null;
            var picked = Pick.PickAndSetNacks(pk, ref wr, this.me);

            if (0 != picked)
            {
                cts.Cancel();
            }
            cts.Dispose();
            if (0 != picked)
            {
                goto Done;
            }
            xK.DoCont(ref wr, xT.Result);
Done:
            return;
        }
Ejemplo n.º 2
0
Archivo: Nack.cs Proyecto: silky/Hopac
        /// <summary>Internal implementation detail.</summary>
        internal override void DoJob(ref Worker wr, Cont <Unit> uK)
        {
Spin:
            var state = this.State;

            if (state > Initial)
            {
                goto Signaled;
            }
            if (state < Initial)
            {
                goto Spin;
            }
            if (Initial != Interlocked.CompareExchange(ref this.State, Locked, Initial))
            {
                goto Spin;
            }

            WaitQueue.AddTaker(ref this.Takers, uK);
            this.State = Initial;
            return;

Signaled:
            uK.DoCont(ref wr, null);
        }
Ejemplo n.º 3
0
        internal override void DoWork(ref Worker wr)
        {
            var pk  = this.pk;
            var cts = this.cts;

            if (null == cts)
            {
                goto Done;
            }
            this.cts = null;
            var picked = Pick.PickAndSetNacks(pk, ref wr, this.me);

            if (0 != picked)
            {
                cts.Cancel();
            }
            cts.Dispose();
            if (0 != picked)
            {
                goto Done;
            }
            var xT = this.xT;

            if (TaskStatus.Faulted == xT.Status)
            {
                xK.DoHandle(ref wr, xT.Exception);
            }
            else
            {
                xK.DoCont(ref wr, xT.Result);
            }
Done:
            return;
        }
Ejemplo n.º 4
0
        internal override void DoWork(ref Worker wr)
        {
            var xT = this.xT;

            if (TaskStatus.Faulted == xT.Status)
            {
                xK.DoHandle(ref wr, xT.Exception);
            }
            else
            {
                xK.DoCont(ref wr, xT.Result);
            }
        }
Ejemplo n.º 5
0
Archivo: Nack.cs Proyecto: silky/Hopac
        /// <summary>Internal implementation detail.</summary>
        internal override void TryAlt(ref Worker wr, int i, Pick pkSelf, Cont <Unit> uK)
        {
Spin:
            var state = this.State;

            if (state > Initial)
            {
                goto TryPick;
            }
            if (state < Initial)
            {
                goto Spin;
            }
            if (Initial != Interlocked.CompareExchange(ref this.State, Locked, Initial))
            {
                goto Spin;
            }

            WaitQueue.AddTaker(ref this.Takers, i, pkSelf, uK);
            this.State = Initial;
            uK.TryNext(ref wr, i + 1, pkSelf);
            return;

TryPick:
            var st = Pick.TryPick(pkSelf);

            if (st > 0)
            {
                goto AlreadyPicked;
            }
            if (st < 0)
            {
                goto TryPick;
            }

            Pick.SetNacks(ref wr, i, pkSelf);

            uK.DoCont(ref wr, null);
AlreadyPicked:
            return;
        }
Ejemplo n.º 6
0
        /// Internal implementation detail.
        internal override void TryAlt(ref Worker wr, int i, Pick pkSelf, Cont <T> aK)
        {
TryPick:
            var stSelf = Pick.TryPick(pkSelf);

            if (stSelf > 0)
            {
                goto AlreadyPicked;
            }
            if (stSelf < 0)
            {
                goto TryPick;
            }

            Pick.SetNacks(ref wr, i, pkSelf);

            aK.DoCont(ref wr, this.value);

AlreadyPicked:
            return;
        }
Ejemplo n.º 7
0
        internal override void DoJob(ref Worker wr, Cont <int> iK)
        {
TryNextTimed:
            var waitTicks = Timeout.Infinite;
            var tt = this.TopTimed;

            if (null == tt)
            {
                goto Return;
            }

            var tickCount = Environment.TickCount;

            waitTicks = tt.Ticks - tickCount;
            if (waitTicks > 0)
            {
                goto Return;
            }

            this.Lock.Enter();
            tt = this.TopTimed;
            if (null == tt)
            {
                goto ExitAndReturnWithInfinite;
            }

            waitTicks = tt.Ticks - tickCount;
            if (waitTicks > 0)
            {
                goto ExitAndReturn;
            }

            DropTimed();
            this.Lock.Exit();

            var pk = tt.Pick;

            if (null == pk)
            {
                goto GotIt;
            }

TryPick:
            var st = Pick.TryPick(pk);

            if (st > 0)
            {
                goto TryNextTimed;
            }
            if (st < 0)
            {
                goto TryPick;
            }

            Pick.SetNacks(ref wr, tt.Me, pk);

GotIt:
            Worker.Push(ref wr, tt);
            iK.DoCont(ref wr, 0);
            return;

ExitAndReturnWithInfinite:
            waitTicks = Timeout.Infinite;
ExitAndReturn:
            this.Lock.Exit();
Return:
            iK.DoCont(ref wr, waitTicks);
        }
Ejemplo n.º 8
0
 internal override void DoWork(ref Worker wr)
 {
     xK.DoCont(ref wr, xJ.DoEnd(iar));
 }
Ejemplo n.º 9
0
 internal override void DoWork(ref Worker wr)
 {
     xK.DoCont(ref wr, xT.Result);
 }
Ejemplo n.º 10
0
 /// Internal implementation detail.
 internal override void DoJob(ref Worker wr, Cont <T> xK)
 {
     xK.DoCont(ref wr, this.value);
 }