internal static void AddGiver <T>(ref Giver <T> queue, T x, int me, Pick pk, Cont <Unit> uK) { var last = queue; Giver <T> elem; if (null != last) { goto MaybeReuse; } elem = new Giver <T>(); queue = elem; elem.Next = elem; goto Init; MaybeReuse: elem = last;// as Giver<T>; var pkGiver = elem.Pick; if (null != pkGiver && pkGiver.State > 0) { goto Init; } elem = new Giver <T>(); queue = elem; elem.Next = last.Next; last.Next = elem; Init: elem.Value = x; elem.Me = me; elem.Pick = pk; elem.Cont = uK; }
internal static void ReplaceRangeInclusive <T>(Giver <T> tail, Giver <T> next, Giver <T> cache) { if (null == cache) { tail.Next = next; } else { tail.Next = cache.Next; cache.Next = next; } }
internal static void ReplaceRange <T>(ref Giver <T> queue, Giver <T> last, Giver <T> cache) { var tail = queue; if (tail == last) { queue = cache; } else { ReplaceRangeInclusive(tail, last.Next, cache); } }
internal static void Enqueue <T>(ref Giver <T> queue, Giver <T> elem) { var tail = queue; if (null == tail) { elem.Next = elem; queue = elem; } else { elem.Next = tail.Next; tail.Next = elem; } }
internal static void AddGiver <T>(ref Send <T> queue, T x, int me, Pick pk, Cont <Unit> uK) { var last = queue; Giver <T> elem; if (null != last) { goto MaybeReuse; } elem = new Giver <T>(); queue = elem; elem.Next = elem; elem.Value = x; elem.Me = me; elem.Pick = pk; elem.Cont = uK; return; MaybeReuse: elem = last as Giver <T>; if (null == elem) { goto New; } var pkGiver = elem.Pick; if (null != pkGiver && pkGiver.State > 0) { goto Init; } New: elem = new Giver <T>(); queue = elem; elem.Next = last.Next; last.Next = elem; Init: elem.Value = x; elem.Me = me; elem.Pick = pk; elem.Cont = uK; CleanGivers(elem); }
internal static void AddGiver <T>(ref Giver <T> queue, T x, Cont <Unit> uK) { var last = queue; Giver <T> elem; if (null != last) { goto MaybeReuse; } elem = new Giver <T>(); queue = elem; elem.Next = elem; elem.Value = x; elem.Cont = uK; return; MaybeReuse: elem = last;// as Giver<T>; var pkGiver = elem.Pick; if (null != pkGiver && pkGiver.State > 0) { goto Reuse; } elem = new Giver <T>(); queue = elem; elem.Next = last.Next; last.Next = elem; elem.Value = x; elem.Cont = uK; return; Reuse: elem.Pick = null; elem.Value = x; elem.Cont = uK; }