Top Description Fields Constructors Methods
rx.internal.util.unsafe

public final Class SpscArrayQueue<E>

Additional top-level classes in compilation unit: SpscArrayQueueColdField, SpscArrayQueueL1Pad, SpscArrayQueueProducerFields, SpscArrayQueueL2Pad, SpscArrayQueueConsumerField, SpscArrayQueueL3Pad.

extends SpscArrayQueueL3Pad<E>
Class Inheritance
Annotations
@SuppressAnimalSniffer
Static Imports
rx.internal.util.unsafe.UnsafeAccess.UNSAFE

A Single-Producer-Single-Consumer queue backed by a pre-allocated buffer.

This implementation is a mashup of the Fast Flow algorithm with an optimization of the offer method taken from the BQueue algorithm (a variation on Fast Flow), and adjusted to comply with Queue.offer semantics with regards to capacity.
For convenience the relevant papers are available in the resources folder:
2010 - Pisa - SPSC Queues on Shared Cache Multi-Core Systems.pdf
2012 - Junchang- BQueue- Efficient and Practical Queuing.pdf
This implementation is wait free.

Author
nitsanw

Field Summary

Inherited from rx.internal.util.unsafe.SpscArrayQueueL3Pad:
p30p31p32p33p34p35p36p37p40p41p42p43p44p45p46

Constructor Summary

AccessConstructor and Description
public
SpscArrayQueue(final int capacity)

Method Summary

Modifier and TypeMethod and Description
public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements rx.internal.util.unsafe.MessagePassingQueue.isEmpty, java.util.Collection.isEmpty.

This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
private long
private long
public boolean
offer(final E
the Object to enqueue, not null
e
)

Implements rx.internal.util.unsafe.MessagePassingQueue.offer, java.util.Queue.offer.

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.
public E
peek()

Implements rx.internal.util.unsafe.MessagePassingQueue.peek, java.util.Queue.peek.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#peek() interface.
public E
poll()

Implements rx.internal.util.unsafe.MessagePassingQueue.poll, java.util.Queue.poll.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#poll() interface.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements rx.internal.util.unsafe.MessagePassingQueue.size, java.util.Collection.size.

This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a best effort rather than absolute value.
private void
private void

Constructor Detail

SpscArrayQueueback to summary
public SpscArrayQueue(final int capacity)

Method Detail

isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements rx.internal.util.unsafe.MessagePassingQueue.isEmpty, java.util.Collection.isEmpty.

Doc from rx.internal.util.unsafe.MessagePassingQueue.isEmpty.

This method's accuracy is subject to concurrent modifications happening as the observation is carried out.

Returns:boolean

true if empty, false otherwise

Annotations
@Override
lvConsumerIndexback to summary
private long lvConsumerIndex()
lvProducerIndexback to summary
private long lvProducerIndex()
offerback to summary
public boolean offer(final E e)

Implements rx.internal.util.unsafe.MessagePassingQueue.offer, java.util.Queue.offer.

Doc from rx.internal.util.unsafe.MessagePassingQueue.offer.

Called from a producer thread subject to the restrictions appropriate to the implementation and according to the Queue#offer(Object) interface.

This implementation is correct for single producer thread use only.

Parameters
e:E

the Object to enqueue, not null

Returns:boolean

true if element was inserted into the queue, false iff full

Annotations
@Override
peekback to summary
public E peek()

Implements rx.internal.util.unsafe.MessagePassingQueue.peek, java.util.Queue.peek.

Doc from rx.internal.util.unsafe.MessagePassingQueue.peek.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#peek() interface.

This implementation is correct for single consumer thread use only.

Returns:E

a message from the queue if one is available, null iff empty

Annotations
@Override
pollback to summary
public E poll()

Implements rx.internal.util.unsafe.MessagePassingQueue.poll, java.util.Queue.poll.

Doc from rx.internal.util.unsafe.MessagePassingQueue.poll.

Called from the consumer thread subject to the restrictions appropriate to the implementation and according to the Queue#poll() interface.

This implementation is correct for single consumer thread use only.

Returns:E

a message from the queue if one is available, null iff empty

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements rx.internal.util.unsafe.MessagePassingQueue.size, java.util.Collection.size.

Doc from rx.internal.util.unsafe.MessagePassingQueue.size.

This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a best effort rather than absolute value. For some implementations this method may be O(n) rather than O(1).

Returns:int

number of messages in the queue, between 0 and queue capacity or Integer#MAX_VALUE if not bounded

Annotations
@Override
soConsumerIndexback to summary
private void soConsumerIndex(long v)
soProducerIndexback to summary
private void soProducerIndex(long v)