コード例 #1
0
ファイル: Promise.cs プロジェクト: kolektiv/Hopac
 public Promise(Job <T> tJ)
 {
     this.State   = Delayed;
     this.Readers = new Fulfill(tJ);
 }
コード例 #2
0
 internal abstract void TryAlt(ref Worker wr, int i, Cont <T> xK, Else xE);
コード例 #3
0
ファイル: Promise.cs プロジェクト: kolektiv/Hopac
        internal override void TryAlt(ref Worker wr, int i, Cont <T> aK, Else aE)
        {
            var pkSelf = aE.pk;

Spin:
            var state = this.State;

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

            if (Delayed == state)
            {
                goto Delayed;
            }

            WaitQueue.AddTaker(ref this.Readers, i, pkSelf, aK);
            this.State = Running;
            aE.TryElse(ref wr, i + 1);
            return;

Delayed:
            var taker = new Taker <T>();

            taker.Cont = aK;
            taker.Me   = i;
            taker.Pick = pkSelf;
            taker.Next = taker;

            var readers = this.Readers;

            this.Readers = taker;
            this.State   = Running;

            var fulfill = readers as Fulfill;
            var tJ      = fulfill.tP;

            fulfill.tP = this;
            Worker.PushNew(ref wr, new JobWork <T>(tJ, fulfill));
            aE.TryElse(ref wr, i + i);
            return;

Completed:
            var stSelf = Pick.TryPick(pkSelf);

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

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

            if (state == HasValue)
            {
                Cont.Do(aK, ref wr, this.Value);
            }
            else
            {
                aK.DoHandle(ref wr, (this.Readers as Fail <T>).exn);
            }
AlreadyPicked:
            return;
        }
コード例 #4
0
ファイル: Alt.cs プロジェクト: silky/Hopac
 /// Internal implementation detail.
 internal abstract void TryAlt(ref Worker wr, int i, Pick pk, Cont <T> tK);
コード例 #5
0
ファイル: Job.cs プロジェクト: wallymathieu/Hopac
 internal abstract void DoJob(ref Worker wr, Cont <T> aK);
コード例 #6
0
 public Promise(Exception e)
 {
     this.Readers = new Fail <T>(e); // We assume failures are infrequent.
     this.State   = HasExn;
 }
コード例 #7
0
 internal void UnsafeAddReader(Cont <T> tK)
 {
     WaitQueue.AddTaker(ref this.Readers, tK);
 }
コード例 #8
0
 public Promise(Job <T> tJ)
 {
     this.Readers = new Fulfill(this, tJ);
 }
コード例 #9
0
        internal override void TryAlt(ref Worker wr, int i, Cont <T> aK, Else aE)
        {
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, i, aE.pk, aK);
            this.State = Running;
            aE.TryElse(ref wr, i + 1);
            return;

Delayed:
            var readers = this.Readers;

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

            var fulfill = readers as Fulfill;

            fulfill.reader = aK;
            fulfill.me     = i;
            fulfill.pk     = aE.pk;

            Worker.PushNew(ref wr, fulfill);
            aE.TryElse(ref wr, i + i);
            return;

Completed:
            var pkSelf = aE.pk;

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

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

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

            if (state == HasValue)
            {
                Cont.Do(aK, ref wr, this.Value);
            }
            else
            {
                aK.DoHandle(ref wr, (this.Readers as Fail <T>).exn);
            }
AlreadyPicked:
            return;
        }
コード例 #10
0
ファイル: Promise.cs プロジェクト: silky/Hopac
 public Promise(Exception e)
 {
     this.State   = Failed;
     this.Readers = new Fail(e); // We assume failures are infrequent.
 }
コード例 #11
0
ファイル: Promise.cs プロジェクト: silky/Hopac
 public Promise(Job <T> tJ)
 {
     this.State   = Delayed;
     this.Readers = new Cont(tJ, this);
 }
コード例 #12
0
ファイル: Promise.cs プロジェクト: silky/Hopac
        /// Internal implementation detail.
        internal override void TryAlt(ref Worker wr, int i, Pick pkSelf, Cont <T> aK)
        {
Spin:
            var state = this.State;

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

            if (state == Running)
            {
                goto Running;
            }

            var job = this.Readers as Cont;

            var taker = new Taker <T>();

            taker.Me     = i;
            taker.Pick   = pkSelf;
            taker.Cont   = aK;
            taker.Next   = taker;
            this.Readers = taker;

            this.State = Running;

            Worker.Push(ref wr, job);
            aK.TryNext(ref wr, i + 1, pkSelf);
            return;

Running:
            WaitQueue.AddTaker(ref this.Readers, i, pkSelf, aK);
            this.State = Running;
            aK.TryNext(ref wr, i + 1, pkSelf);
            return;

Completed:
            var stSelf = Pick.TryPick(pkSelf);

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

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

            if (state == Completed)
            {
                aK.DoCont(ref wr, this.Value);
            }
            else
            {
                aK.DoHandle(ref wr, (this.Readers as Fail).exn);
            }
AlreadyPicked:
            return;
        }