Class MPMCConcurrentQueue<E>
- java.lang.Object
-
- com.conversantmedia.util.concurrent.MPMCConcurrentQueue<E>
-
- All Implemented Interfaces:
ConcurrentQueue<E>
- Direct Known Subclasses:
MPMCBlockingQueue
class MPMCConcurrentQueue<E> extends java.lang.Object implements ConcurrentQueue<E>
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 Modifier and Type Class Description protected static classMPMCConcurrentQueue.Cell<R>
-
Field Summary
Fields Modifier and Type Field Description (package private) MPMCConcurrentQueue.Cell<E>[]buffer(package private) ContendedAtomicLonghead(package private) longmaskprotected intsize(package private) ContendedAtomicLongtail
-
Constructor Summary
Constructors Constructor Description MPMCConcurrentQueue(int capacity)Construct a blocking queue of the given fixed capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacity()voidclear()clear the queue of all elementsbooleancontains(java.lang.Object o)booleanisEmpty()booleanoffer(E e)Add element t to the ringEpeek()return the first element in the queueEpoll()remove the first element from the queue and return itintremove(E[] e)return all elements in the queue to the provided array, up to the size of the provided array.intsize()
-
-
-
Field Detail
-
size
protected final int size
-
mask
final long mask
-
buffer
final MPMCConcurrentQueue.Cell<E>[] buffer
-
head
final ContendedAtomicLong head
-
tail
final ContendedAtomicLong tail
-
-
Method Detail
-
offer
public boolean offer(E e)
Description copied from interface:ConcurrentQueueAdd element t to the ring- Specified by:
offerin interfaceConcurrentQueue<E>- Parameters:
e- - element to offer- Returns:
- boolean - true if the operation succeeded
-
poll
public E poll()
Description copied from interface:ConcurrentQueueremove the first element from the queue and return it- Specified by:
pollin interfaceConcurrentQueue<E>- Returns:
- T
-
peek
public final E peek()
Description copied from interface:ConcurrentQueuereturn the first element in the queue- Specified by:
peekin interfaceConcurrentQueue<E>- Returns:
- E - The element
-
remove
public int remove(E[] e)
Description copied from interface:ConcurrentQueuereturn all elements in the queue to the provided array, up to the size of the provided array.- Specified by:
removein interfaceConcurrentQueue<E>- Parameters:
e- - The element array- Returns:
- int - the number of elements added to t
-
size
public final int size()
- Specified by:
sizein interfaceConcurrentQueue<E>- Returns:
- int - the number of elements in the queue
-
capacity
public int capacity()
- Specified by:
capacityin interfaceConcurrentQueue<E>- Returns:
- int - the capacity of the queue
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmptyin interfaceConcurrentQueue<E>- Returns:
- boolean - true if the queue is currently empty
-
clear
public void clear()
Description copied from interface:ConcurrentQueueclear the queue of all elements- Specified by:
clearin interfaceConcurrentQueue<E>
-
contains
public final boolean contains(java.lang.Object o)
- Specified by:
containsin interfaceConcurrentQueue<E>- Parameters:
o- - the object to test- Returns:
- boolean - true if specified object is contained in the queue
-
-