Return an element from the head of the queue.
The element is removed from the queue.
Entry<V> first = null ;
synchronized (lock) {
first = head.next ;
if (first == head)
return null ;
else {
// assert that the following expression returns true!
first.handle().remove() ;
}
}
// Once first is removed from the queue, it is invisible to other threads,
// so we don't need to synchronize here.
first.next = null ;
first.prev = null ;
V value = first.handle().value() ;
return value ;