public bool Pop(ref T element) { int currentHead = _head; //No fence required for head because only 1 thread is writing Fences.EmitAcquireFence(); //Acquire for _tail if (currentHead == _tail) { return(false); } element = _elements[currentHead]; _head = Increment(currentHead); Fences.EmitReleaseFence(); //Release for _head return(true); }
public bool Push(T element) { int currentTail = _tail; //No fence required for tail because only 1 thread is writing int nextTail = Increment(currentTail); Fences.EmitAcquireFence(); //Acquire for _head if (nextTail == _head) { return(false); } _elements[currentTail] = element; _tail = nextTail; Fences.EmitReleaseFence(); //Release for _tail return(true); }