public class SharedDeque extends Deque
Modifier and Type | Field and Description |
---|---|
private int |
arity
Number of words per entry
|
private int |
bufsenqueued |
private int |
completionFlag
Completion flag - set when all consumers have arrived at the barrier
|
private static boolean |
DISABLE_WAITING |
protected Address |
head
Head of the shared deque
|
private Lock |
lock |
private String |
name
The name of this shared deque - for diagnostics
|
private static Offset |
NEXT_OFFSET |
private int |
numConsumers
# active threads - processing is complete when # waiting == this
|
private int |
numConsumersWaiting
# threads waiting
|
private static Offset |
PREV_OFFSET |
private RawPageSpace |
rps
Raw page space from which to allocate
|
protected Address |
tail
Tail of the shared deque
|
private static long |
TIMEOUT_PERIOD |
private static boolean |
TRACE |
private static boolean |
TRACE_BLOCKERS |
private static boolean |
TRACE_DETAIL |
private static long |
WARN_PERIOD |
BUFFER_MASK, BUFFER_SIZE, HEAD_INITIAL_VALUE, LOG_PAGES_PER_BUFFER, META_DATA_SIZE, NEXT_FIELD_OFFSET, PAGES_PER_BUFFER, TAIL_INITIAL_VALUE, USABLE_BUFFER_BYTES
Constructor and Description |
---|
SharedDeque(String name,
RawPageSpace rps,
int arity) |
Modifier and Type | Method and Description |
---|---|
(package private) Address |
alloc() |
void |
assertExhausted() |
private boolean |
checkDequeLength(int length)
Check the number of buffers in the work queue (for debugging
purposes).
|
private void |
clearCompletionFlag()
Clear the completion flag.
|
void |
clearDeque(int arity) |
private boolean |
complete() |
private Address |
dequeue(boolean waiting,
boolean fromTail)
Dequeue a block from the shared pool.
|
(package private) Address |
dequeue(int arity) |
(package private) Address |
dequeue(int arity,
boolean fromTail) |
(package private) Address |
dequeueAndWait(int arity) |
(package private) Address |
dequeueAndWait(int arity,
boolean fromTail) |
(package private) void |
enqueue(Address buf,
int arity,
boolean toTail)
Enqueue a block on the head or tail of the shared queue
|
int |
enqueuedPages() |
(package private) void |
free(Address buf) |
(package private) int |
getArity() |
protected Address |
getNext(Address buf)
Get the "next" pointer in a buffer forming the linked buffer chain.
|
protected Address |
getPrev(Address buf)
Get the "next" pointer in a buffer forming the linked buffer chain.
|
private void |
lock()
Lock this shared queue.
|
void |
prepare()
Prepare for parallel processing.
|
private void |
prepare(int consumers)
Prepare for parallel processing where a specific number
of threads take part.
|
void |
prepareNonBlocking()
Prepare for processing where pop operations on the deques
will never block.
|
void |
reset() |
private void |
setCompletionFlag()
Set the completion flag.
|
private void |
setHead(Address newHead) |
private static void |
setNext(Address buf,
Address next)
Set the "next" pointer in a buffer forming the linked buffer chain.
|
private void |
setNumConsumers(int newNumConsumers) |
private void |
setNumConsumersWaiting(int newNCW) |
private void |
setPrev(Address buf,
Address prev)
Set the "prev" pointer in a buffer forming the linked buffer chain.
|
private void |
setTail(Address newTail) |
private void |
spinWait(boolean fromTail)
Spinwait for GC work to arrive
|
private void |
unlock()
Release the lock.
|
bufferEnd, bufferFirst, bufferLast, bufferLast, bufferLastOffset, bufferOffset, bufferStart
private static final boolean DISABLE_WAITING
private static final Offset NEXT_OFFSET
private static final Offset PREV_OFFSET
private static final boolean TRACE
private static final boolean TRACE_DETAIL
private static final boolean TRACE_BLOCKERS
private final RawPageSpace rps
private final int arity
private volatile int completionFlag
private volatile int numConsumers
private volatile int numConsumersWaiting
private volatile int bufsenqueued
private static final long WARN_PERIOD
private static final long TIMEOUT_PERIOD
public SharedDeque(String name, RawPageSpace rps, int arity)
name
- the queue's human-readable namerps
- the space to get pages fromarity
- the arity (number of words per entry) of this queuefinal int getArity()
final void enqueue(Address buf, int arity, boolean toTail)
buf
- the block to enqueuearity
- the arity of this queuetoTail
- whether to enqueue to the tail of the shared queuepublic final void clearDeque(int arity)
final Address dequeueAndWait(int arity)
final Address dequeueAndWait(int arity, boolean fromTail)
public final void prepare()
public final void prepareNonBlocking()
private void prepare(int consumers)
consumers
- # threads taking part.public final void reset()
public final void assertExhausted()
public final int enqueuedPages()
private Address dequeue(boolean waiting, boolean fromTail)
waiting
- whether to wait to dequeue a block if none is presentfromTail
- whether to dequeue from the tailprivate void spinWait(boolean fromTail)
fromTail
- Check the head or the tail ?private static void setNext(Address buf, Address next)
buf
- The buffer whose next field is to be set.next
- The reference to which next should point.protected final Address getNext(Address buf)
buf
- The buffer whose next field is to be returned.private void setPrev(Address buf, Address prev)
buf
- The buffer whose next field is to be set.prev
- The reference to which prev should point.protected final Address getPrev(Address buf)
buf
- The buffer whose next field is to be returned.private boolean checkDequeLength(int length)
length
- The number of buffers believed to be in the queue.private void lock()
private void unlock()
private boolean complete()
private void setCompletionFlag()
private void clearCompletionFlag()
private void setNumConsumers(int newNumConsumers)
private void setNumConsumersWaiting(int newNCW)