Beispiel #1
0
        internal override void DoJob(ref Worker wr, Cont <T> aK)
        {
Spin:
            var state = this.State;

Reconsider:
            if (state > Running)
            {
                goto Completed;
            }
            if (state < Delayed)
            {
                goto Spin;
            }
            var check = state;

            state = Interlocked.CompareExchange(ref this.State, state - MakeLocked, state);
            if (Delayed == state)
            {
                goto Delayed;
            }
            if (state != check)
            {
                goto Reconsider;
            }

            WaitQueue.AddTaker(ref this.Readers, aK);
            this.State = Running;
            return;

Delayed:
            var readers = this.Readers;

            this.Readers = null;
            this.State   = Running;

            var fulfill = readers as Fulfill;

            fulfill.tP     = this;
            fulfill.reader = aK;
            var tJ = fulfill.tJ;

            fulfill.tJ = null;
            Job.Do(tJ, ref wr, fulfill);
            return;

Completed:
            if (state == HasValue)
            {
                Cont.Do(aK, ref wr, this.Value);
            }
            else
            {
                aK.DoHandle(ref wr, (this.Readers as Fail <T>).exn);
            }
        }