/** * Returns the number of elements in this collection, 0 if empty. */ @Override public int size() { // lv means load volatile, like a volatile field read. // Producer is at the producer index (ahead of the consumer), a long // Consumer is at the consumer index, also a long // -> size is the delta. return (int) (lvProducerIndex() - lvConsumerIndex()); }