예제 #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));
 }