コード例 #1
0
        internal override void TryAlt(ref Worker wr, int i, Cont <X> xK, Else xE)
        {
            var pk = xE.pk;
            var nk = Pick.ClaimAndAddNack(pk, i);

            if (null != nk)
            {
                var      cts = new CancellationTokenSource();
                Task <X> xT;
                try {
                    xT = this.Start(cts.Token);
                } catch (Exception e) {
                    Pick.PickClaimedAndSetNacks(ref wr, i, pk);
                    cts.Dispose();
                    Handler.DoHandle(xK, ref wr, e);
                    return;
                }
                if (TaskStatus.RanToCompletion == xT.Status)
                {
                    Pick.PickClaimedAndSetNacks(ref wr, i, pk);
                    cts.Dispose();
                    Cont.Do(xK, ref wr, xT.Result);
                }
                else
                {
                    var state = new TaskToAltAwaiter <X>(cts, pk, i, xT, xK, wr.Scheduler);
                    nk.UnsafeAddReader(state);
                    Pick.Unclaim(pk);
                    var j = i + 1;
                    nk.I1 = j;
                    xT.ConfigureAwait(false).GetAwaiter().UnsafeOnCompleted(state.Ready);
                    xE.TryElse(ref wr, j);
                }
            }
        }
コード例 #2
0
ファイル: Async.cs プロジェクト: wallymathieu/Hopac
        internal override void DoJob(ref Worker wr, Cont <X> xK)
        {
#if !NO_ISTHREADPOOLTHREAD
            if (Thread.CurrentThread.IsThreadPoolThread)
            {
                var work = wr.WorkStack;
                wr.WorkStack = null;
                Scheduler.PushAll(wr.Scheduler, work);
                Cont.Do(xK, ref wr, this.Run());
            }
            else
#endif
            {
                var fac = new FromAsyncCont <X>(xK);
                this.Start(fac);
                if (0 != fac.state)
                {
                    goto Continue;
                }
                fac.sr = wr.Scheduler;
                if (0 == Interlocked.CompareExchange(ref fac.state, 1, 0))
                {
                    return;
                }
Continue:
                Work.Do(fac.xK, ref wr);
            }
        }
コード例 #3
0
        internal override void TryAlt(ref Worker wr, int i, Cont <X> xK, Else xE)
        {
            var pk = xE.pk;
            var cb = new AltCallback <X>(wr.Scheduler, this, xK, pk, -1);
            var nk = Pick.ClaimAndAddNack(pk, i);

            if (null != nk)
            {
                try {
                    cb.iar = DoBegin(StaticData.workAsyncCallback, cb);
                } catch (Exception e) {
                    Pick.PickClaimedAndSetNacks(ref wr, i, pk);
                    Handler.DoHandle(xK, ref wr, e);
                    return;
                }
                var m = cb.me;
                if (0 <= m || m != Interlocked.CompareExchange(ref cb.me, i, m))
                {
                    Pick.PickClaimedAndSetNacks(ref wr, i, pk);
                    Cont.Do(xK, ref wr, DoEnd(cb.iar));
                }
                else
                {
                    nk.UnsafeAddReader(cb);
                    Pick.Unclaim(pk);
                    var j = i + 1;
                    nk.I1 = j;
                    xE.TryElse(ref wr, j);
                }
            }
        }
コード例 #4
0
        internal override void DoJob(ref Worker wr, Cont <X> xK)
        {
            var xT = Start(new CancellationToken(false));

            if (TaskStatus.RanToCompletion == xT.Status)
            {
                Cont.Do(xK, ref wr, xT.Result);
            }
            else
            {
                xT.ConfigureAwait(false).GetAwaiter().UnsafeOnCompleted(new TaskToJobAwaiter <X>(xT, xK, wr.Scheduler).Ready);
            }
        }
コード例 #5
0
        internal override void DoJob(ref Worker wr, Cont <X> xK)
        {
            var xT = this.xT;

            if (TaskStatus.RanToCompletion == xT.Status)
            {
                Cont.Do(xK, ref wr, xT.Result);
            }
            else
            {
                xT.ConfigureAwait(false).GetAwaiter().UnsafeOnCompleted(new State(xT, xK, wr.Scheduler).Ready);
            }
        }
コード例 #6
0
        internal override void DoWork(ref Worker wr)
        {
            var me = this.me;

            if (me < 0 && me == Interlocked.CompareExchange(ref this.me, 0, me))
            {
                return;
            }
            if (0 != Pick.PickAndSetNacks(pk, ref wr, me))
            {
                xJ.DoCancel(iar);
            }
            else
            {
                Cont.Do(xK, ref wr, xJ.DoEnd(iar));
            }
        }
コード例 #7
0
ファイル: Always.cs プロジェクト: sjkdev21/Hopac
        internal override void TryAlt(ref Worker wr, int i, Cont <T> xK, Else xE)
        {
            var pkSelf = xE.pk;

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

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

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

            Cont.Do(xK, ref wr, this.value);

AlreadyPicked:
            return;
        }
コード例 #8
0
 internal override void DoJob(ref Worker wr, Cont <Scheduler> sK)
 {
     Cont.Do(sK, ref wr, wr.Scheduler);
 }
コード例 #9
0
 internal override void DoJob(ref Worker wr, Cont <Proc> pK)
 {
     Cont.Do(pK, ref wr, pK.GetProc(ref wr));
 }
コード例 #10
0
ファイル: Always.cs プロジェクト: sjkdev21/Hopac
 internal override void DoJob(ref Worker wr, Cont <T> xK)
 {
     Cont.Do(xK, ref wr, this.value);
 }
コード例 #11
0
 internal override void DoWork(ref Worker wr)
 {
     Cont.Do(xK, ref wr, xJ.DoEnd(iar));
 }