Class MPMCConcurrentQueue<E>
java.lang.Object
com.conversantmedia.util.concurrent.MPMCConcurrentQueue<E>
- All Implemented Interfaces:
ConcurrentQueue<E>
- Direct Known Subclasses:
MPMCBlockingQueue
Dmitry Vyukov, Bounded MPMC queue - http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
Added for benchmarking and comparison. MultithreadConcurrentQueue performs better in the regimes I have tested.
Created by jcairns on 5/29/14.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final MPMCConcurrentQueue.Cell<E>[]
(package private) final ContendedAtomicLong
(package private) final long
protected final int
(package private) final ContendedAtomicLong
-
Constructor Summary
ConstructorsConstructorDescriptionMPMCConcurrentQueue
(int capacity) Construct a blocking queue of the given fixed capacity. -
Method Summary
Modifier and TypeMethodDescriptionint
capacity()
void
clear()
clear the queue of all elementsfinal boolean
final boolean
isEmpty()
boolean
Add element t to the ringfinal E
peek()
return the first element in the queuepoll()
remove the first element from the queue and return itint
return all elements in the queue to the provided array, up to the size of the provided array.final int
size()
-
Field Details
-
size
protected final int size -
mask
final long mask -
buffer
-
head
-
tail
-
-
Constructor Details
-
MPMCConcurrentQueue
public MPMCConcurrentQueue(int capacity) Construct a blocking queue of the given fixed capacity. Note: actual capacity will be the next power of two larger than capacity.- Parameters:
capacity
- maximum capacity of this queue
-
-
Method Details
-
offer
Description copied from interface:ConcurrentQueue
Add element t to the ring- Specified by:
offer
in interfaceConcurrentQueue<E>
- Parameters:
e
- - element to offer- Returns:
- boolean - true if the operation succeeded
-
poll
Description copied from interface:ConcurrentQueue
remove the first element from the queue and return it- Specified by:
poll
in interfaceConcurrentQueue<E>
- Returns:
- T
-
peek
Description copied from interface:ConcurrentQueue
return the first element in the queue- Specified by:
peek
in interfaceConcurrentQueue<E>
- Returns:
- E - The element
-
remove
Description copied from interface:ConcurrentQueue
return all elements in the queue to the provided array, up to the size of the provided array.- Specified by:
remove
in interfaceConcurrentQueue<E>
- Parameters:
e
- - The element array- Returns:
- int - the number of elements added to t
-
size
public final int size()- Specified by:
size
in interfaceConcurrentQueue<E>
- Returns:
- int - the number of elements in the queue
-
capacity
public int capacity()- Specified by:
capacity
in interfaceConcurrentQueue<E>
- Returns:
- int - the capacity of the queue
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmpty
in interfaceConcurrentQueue<E>
- Returns:
- boolean - true if the queue is currently empty
-
clear
public void clear()Description copied from interface:ConcurrentQueue
clear the queue of all elements- Specified by:
clear
in interfaceConcurrentQueue<E>
-
contains
- Specified by:
contains
in interfaceConcurrentQueue<E>
- Parameters:
o
- - the object to test- Returns:
- boolean - true if specified object is contained in the queue
-