Ejemplo n.º 1
0
        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, ~state, state))
            {
                goto Spin;
            }

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

Signaled:
            Work.Do(uK, ref wr);
        }
Ejemplo n.º 2
0
        internal override void TryAlt(ref Worker wr, int i, Cont <Unit> uK, Else uE)
        {
            var pkSelf = uE.pk;

Spin:
            var state = this.State;

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

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

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

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

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

            Work.Do(uK, ref wr);
AlreadyPicked:
            return;
        }
Ejemplo n.º 3
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;
        }