internal override void DoJob(ref Worker wr, Cont <Unit> uK) { var tI = this.tI; Spin: var state = tI.State; if (state < Delayed) { goto Spin; } if (state > Running) { goto Done; } if (state != Interlocked.CompareExchange(ref tI.State, ~state, state)) { goto Spin; } tI.Value = this.t; tI.State = HasValue; WaitQueue.PickReaders(ref tI.Readers, tI.Value, ref wr); Done: Work.Do(uK, ref wr); }
internal override void DoJob(ref Worker wr, Cont <Unit> uK) { var tI = this.tI; tI.Value = this.t; // This assumes correct usage of IVar. Spin: var state = tI.State; if (state < Delayed) { goto Spin; } if (state != Interlocked.CompareExchange(ref tI.State, HasValue, state)) { goto Spin; } if (state > Running) { uK.DoHandle(ref wr, new Exception("IVar full")); } else { WaitQueue.PickReaders(ref tI.Readers, tI.Value, ref wr); Work.Do(uK, ref wr); } }
internal override void DoJob(ref Worker wr, Cont <Unit> uK) { var tI = this.tI; Spin: var state = tI.State; if (state < Delayed) { goto Spin; } if (state != Interlocked.CompareExchange(ref tI.State, ~state, state)) { goto Spin; } if (state > Running) { goto IVarFull; } tI.Value = this.t; tI.State = HasValue; WaitQueue.PickReaders(ref tI.Readers, tI.Value, ref wr); Work.Do(uK, ref wr); return; IVarFull: tI.State = state; uK.DoHandle(ref wr, new Exception("IVar full")); }
internal override void DoJob(ref Worker wr, Cont<Unit> uK) { var latch = this.latch; var n = Interlocked.Decrement(ref latch.Count); if (0 == n) { latch.Lock(); WaitQueue.PickReaders(ref latch.Awaiters, null, ref wr); } Work.Do(uK, ref wr); }
internal void Do(ref Worker wr, T t) { var tP = this.tP; tP.Value = t; Spin: var state = tP.State; if (state != Running) { goto Spin; } if (Running != Interlocked.CompareExchange(ref tP.State, HasValue, state)) { goto Spin; } WaitQueue.PickReaders(ref tP.Readers, tP.Value, ref wr); var pk = this.pk; if (null == pk) { goto MaybeGotReader; } TryPick: var st = Pick.TryPick(pk); if (st > 0) { goto Done; } if (st < 0) { goto TryPick; } Pick.SetNacks(ref wr, me, pk); MaybeGotReader: var reader = this.reader; if (null == reader) { goto Done; } wr.Handler = reader; reader.DoCont(ref wr, tP.Value); Done: return; }
internal void Do(ref Worker wr, T t) { var tP = this.tP as Promise <T>; tP.Value = t; Spin: var state = tP.State; if (state != Running) { goto Spin; } if (Running != Interlocked.CompareExchange(ref tP.State, HasValue, state)) { goto Spin; } WaitQueue.PickReaders(ref tP.Readers, tP.Value, ref wr); }