Skip to content

Commit

Permalink
SyncedRingbuffer: Add 'reset(boolean full)', simplify 'clear(..)'.
Browse files Browse the repository at this point in the history
'reset(boolean full)' enables user to reset ringbuffer pointer and assume it's empty or full,
while 'clear()' shall only remove all references .. etc.
  • Loading branch information
sgothel committed Aug 15, 2013
1 parent 6c72b1f commit 1632477
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java
Expand Up @@ -62,16 +62,14 @@ public final String toString() {
* <p>
* The array may either be clear, or preset w/ elements!
* </p>
* @param full if true, given array is assumed to be full, i.e. {@link #isFull()} will return true.
* @param full if true, this ring buffer is assumed to be full, i.e. {@link #isFull()} will return true.
* Otherwise {@link #isEmpty()} will return true.
* @param array
*/
public SyncedRingbuffer(T[] array, boolean full) {
this.array = array;
this.capacity = array.length;
clearImpl(false);
if(full) {
size = capacity;
}
reset(full);
}

public final T[] getArray() { return array; }
Expand All @@ -81,18 +79,28 @@ public final int capacity() {
}

/**
* Resets all ring buffer pointer to zero.
* Clears all ring buffer pointer to zero and set all ring buffer slots to <code>null</code>.
* <p>
* {@link #isEmpty()} will return <code>true</code> after calling this method.
* </p>
* <p>
* If <code>clearRefs</code> is true, all ring buffer slots will be set to <code>null</code>.
* </p>
* @param clearRefs if true, all ring buffer slots will be flushed, otherwise they remain intact.
*/
public final void clear(boolean clearRefs) {
public final void clear() {
synchronized ( sync ) {
clearImpl(true);
}
}

/**
* Resets all ring buffer pointer to zero while leaving all ring buffer slots untouched.
* @param full if true, this ring buffer is assumed to be full, i.e. {@link #isFull()} will return true.
* Otherwise {@link #isEmpty()} will return true.
*/
public final void reset(boolean full) {
synchronized ( sync ) {
clearImpl(clearRefs);
clearImpl(false);
}
if(full) {
size = capacity;
}
}

Expand Down

0 comments on commit 1632477

Please sign in to comment.