galois.runtime.wl
Class BoundedFIFO<T>

java.lang.Object
  extended by galois.runtime.wl.BoundedFIFO<T>
Type Parameters:
T - the type of elements of the worklist
All Implemented Interfaces:
Worklist<T>

@OnlyLeaf
public class BoundedFIFO<T>
extends Object
implements Worklist<T>

Order elements in first-in-first-order order, i.e., queue order. This order may only contain up to N elements.

See Also:
FIFO

Field Summary
static int DEFAULT_MAX_ELEMENTS
           
 
Constructor Summary
BoundedFIFO(int maxElements, Maker<T> maker, boolean needSize)
          Creates a bounded FIFO order with the given maximum number of elements
BoundedFIFO(Maker<T> maker, boolean needSize)
          Creates a bounded FIFO order with the default maximum number of elements (32)
 
Method Summary
 void add(T item, ForeachContext<T> ctx)
          Adds an element to this worklist.
 void addInitial(T item, ForeachContext<T> ctx)
          Adds an element to this worklist.
 void finishAddInitial()
          Marks when no more elements will be added from the initial elements passed to an executor.
 boolean isEmpty()
          Checks for emptiness.
 Worklist<T> newInstance()
           
 T poll(ForeachContext<T> ctx)
          Removes an element from this worklist.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_ELEMENTS

public static final int DEFAULT_MAX_ELEMENTS
See Also:
Constant Field Values
Constructor Detail

BoundedFIFO

public BoundedFIFO(Maker<T> maker,
                   boolean needSize)
Creates a bounded FIFO order with the default maximum number of elements (32)


BoundedFIFO

public BoundedFIFO(int maxElements,
                   Maker<T> maker,
                   boolean needSize)
Creates a bounded FIFO order with the given maximum number of elements

Parameters:
maxElements - the maximum number of elements
Method Detail

newInstance

public Worklist<T> newInstance()
Specified by:
newInstance in interface Worklist<T>
Returns:
a new, empty instance of this worklist

isEmpty

public boolean isEmpty()
Description copied from interface: Worklist
Checks for emptiness. Only called by one thread at a time so does not have to be thread-safe. Also, can assume that all threads have had Worklist.poll(ForeachContext) return null.

Specified by:
isEmpty in interface Worklist<T>
Returns:
true if there are no more elements in this worklist

size

public int size()
Specified by:
size in interface Worklist<T>
Returns:
the number of elements in this worklist, during concurrent execution this may be a lower bound on the number of elements

add

public void add(T item,
                ForeachContext<T> ctx)
Description copied from interface: Worklist
Adds an element to this worklist. This method is used for newly generated elements or elements added during Galois execution. Thread-safe.

Specified by:
add in interface Worklist<T>
Parameters:
item - the item to add
ctx - an executor context

addInitial

public void addInitial(T item,
                       ForeachContext<T> ctx)
Description copied from interface: Worklist
Adds an element to this worklist. This method is used when adding elements from the initial elements passed to an executor. Thread-safe.

Specified by:
addInitial in interface Worklist<T>
Parameters:
item - the item to add
ctx - an executor context

poll

public T poll(ForeachContext<T> ctx)
Description copied from interface: Worklist
Removes an element from this worklist. Thread-safe.

Specified by:
poll in interface Worklist<T>
Parameters:
ctx - an executor context
Returns:
an element or null if there are no more elements in this worklist

finishAddInitial

public void finishAddInitial()
Description copied from interface: Worklist
Marks when no more elements will be added from the initial elements passed to an executor.

Specified by:
finishAddInitial in interface Worklist<T>