//This is only thread safe when called from the thread that owns the Deque. public void Push(T w) { if (!deque.Push(w)) { DequeFixed <T> old = deque; DequeFixed <T> other = new DequeFixed <T>(CalculateNewCapacity(deque)); deque = other; MoveElements(old, other); other.Push(w); } }
static private void MoveElements(DequeFixed <T> old, DequeFixed <T> cur) { while (true) { T move = old.Steal(); if (move == null) { break; } else { cur.Push(move); } } }