From 16324775161ad34672a1506fd707107ac04b4437 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 15 Aug 2013 14:33:41 +0200 Subject: SyncedRingbuffer: Add 'reset(boolean full)', simplify 'clear(..)'. 'reset(boolean full)' enables user to reset ringbuffer pointer and assume it's empty or full, while 'clear()' shall only remove all references .. etc. --- .../jogamp/opengl/util/av/SyncedRingbuffer.java | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl') diff --git a/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java b/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java index 9e1ec48f1..dff470eda 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java @@ -62,16 +62,14 @@ public class SyncedRingbuffer { *

* The array may either be clear, or preset w/ elements! *

- * @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; } @@ -81,18 +79,28 @@ public class SyncedRingbuffer { } /** - * Resets all ring buffer pointer to zero. + * Clears all ring buffer pointer to zero and set all ring buffer slots to null. *

* {@link #isEmpty()} will return true after calling this method. *

- *

- * If clearRefs is true, all ring buffer slots will be set to null. - *

- * @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; } } -- cgit v1.2.3