public void PushRange(T[] items, int startIndex, int count) { RangeArgumentsCheck(items, startIndex, count); Node insert = null; Node first = null; for (int i = startIndex; i < count; i++) { Node temp = new Node(); temp.Value = items[i]; temp.Next = insert; insert = temp; if (first == null) { first = temp; } } do { first.Next = head; } while (ClientInterlocked.CompareExchange(ref head, insert, first.Next) != first.Next); ClientInterlocked.Add(ref this.count, count); }
public int TryPopRange(T[] items, int startIndex, int count) { RangeArgumentsCheck(items, startIndex, count); object temp; object end; do { temp = head; if (temp == null) { return(0); } end = temp; for (int j = 0; j < count; j++) { end = ((Node)end).Next; if (end == null) { break; } } } while (ClientInterlocked.CompareExchange(ref head, end, temp) != temp); int i; for (i = startIndex; i < startIndex + count && temp != null; i++) { items[i] = ((Node)temp).Value; end = temp; temp = ((Node)temp).Next; } ClientInterlocked.Add(ref this.count, -(i - startIndex)); return(i - startIndex); }