From c1b44f3f26a8e44d34dc79850716174a8b36ad91 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 22 Aug 2013 23:42:13 +0200 Subject: SyncedRingbuffer moved to GlueGen, commit 30475c6bbeb9a5d48899b281ead8bb305679028d --- .../jogamp/opengl/util/av/SyncedRingbuffer.java | 296 --------------------- 1 file changed, 296 deletions(-) delete mode 100644 src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java (limited to 'src/jogl/classes/jogamp/opengl/util') diff --git a/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java b/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java deleted file mode 100644 index 968a0cd1b..000000000 --- a/src/jogl/classes/jogamp/opengl/util/av/SyncedRingbuffer.java +++ /dev/null @@ -1,296 +0,0 @@ -/** - * Copyright 2013 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - -package jogamp.opengl.util.av; - -/** - * Simple synchronized ring buffer implementation. - *

- * Caller can chose whether to block until get / put is able to proceed or not. - *

- *

- * Caller can chose whether to pass an empty array and clear references at get, - * or using a preset array for circular access of same objects. - *

- *

- * Circular write position is equal to the read position if buffer is full or if buffer is empty. - *

- */ -public class SyncedRingbuffer { - - private final Object sync = new Object(); - private final T[] array; - private final int capacity; - private int readPos; - private int writePos; - private int size; - - public final String toString() { - return "SyncedRingbuffer[filled "+size+" / "+capacity+", writePos "+writePos+", readPos "+readPos+"]"; - } - - /** - * Create instance w/ the given array and it's capacity, e.g.: - *
-     *      SyncedRingbuffer r = new SyncedRingbuffer(new Integer[10]);
-     * 
- *

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

- * @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; - reset(full); - } - - public final T[] getArray() { return array; } - - public final int capacity() { return capacity; } - - /** - * Clears all ring buffer pointer to zero and set all ring buffer slots to null. - *

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

- */ - public final void clear() { - synchronized ( sync ) { - clearImpl(true); - } - } - - /** - * Sets the read and write position to zero and marks this ring buffer full or empty - * 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 ) { - readPos = 0; - writePos = 0; - size = full ? capacity : 0; - } - } - - private final void clearImpl(boolean clearRefs) { - readPos = 0; - writePos = 0; - size = 0; - if( clearRefs ) { - for(int i=0; i - * Impl. returns the element at the current read position - * and advances the read position - if available. - *

- *

- * If clearRef is true, the returned ring buffer slot will be set to null. - *

- *

- * Method is non blocking and returns immediately;. - *

- * @param clearRef if true, the returned ring buffer slot will be flushed, otherwise it remains intact. - * @return the oldest put element if available, otherwise null. - */ - public final T get(boolean clearRef) { - try { - return getImpl(clearRef, false, false); - } catch (InterruptedException ie) { throw new RuntimeException(ie); } - } - - /** - * Returns the oldest put element. - *

- * Impl. returns the element at the current read position - * and advances the read position. - *

- *

- * If clearRef is true, the returned ring buffer slot will be set to null. - *

- *

- * Methods blocks until an element becomes available via put. - *

- * @param clearRef if true, the returned ring buffer slot will be flushed, otherwise it remains intact. - * @return the oldest put element - * @throws InterruptedException - */ - public final T getBlocking(boolean clearRef) throws InterruptedException { - return getImpl(clearRef, true, false); - } - - public final T peek() { - try { - return getImpl(false, false, true); - } catch (InterruptedException ie) { throw new RuntimeException(ie); } - } - public final T peekBlocking() throws InterruptedException { - return getImpl(false, true, true); - } - - private final T getImpl(boolean clearRef, boolean blocking, boolean peek) throws InterruptedException { - synchronized ( sync ) { - if( 0 == size ) { - if( blocking ) { - while( 0 == size ) { - sync.wait(); - } - } else { - return null; - } - } - final T r = array[readPos]; - if( !peek ) { - if( clearRef ) { - array[readPos] = null; - } - readPos = (readPos + 1) % capacity; - size--; - sync.notifyAll(); // notify waiting putter - } - return r; - } - } - - /** - * Puts the element e at the current write position - * and advances the write position. - *

- * Returns true if successful, otherwise false in case buffer is full. - *

- *

- * Method is non blocking and returns immediately;. - *

- */ - public final boolean put(T e) { - try { - return putImpl(e, false, false); - } catch (InterruptedException ie) { throw new RuntimeException(ie); } - } - - /** - * Puts the element e at the current write position - * and advances the write position. - *

- * Method blocks until a free slot becomes available via get. - *

- * @throws InterruptedException - */ - public final void putBlocking(T e) throws InterruptedException { - if( !putImpl(e, false, true) ) { - throw new InternalError("Blocking put failed: "+this); - } - } - - /** - * Keeps the element at the current write position intact - * and advances the write position. - *

- * Returns true if successful, otherwise false in case buffer is full. - *

- *

- * If blocking is true, method blocks until a free slot becomes available via get. - *

- * @param blocking if true, wait until a free slot becomes available via get. - * @throws InterruptedException - */ - public final boolean putSame(boolean blocking) throws InterruptedException { - return putImpl(null, true, blocking); - } - - private final boolean putImpl(T e, boolean sameRef, boolean blocking) throws InterruptedException { - synchronized ( sync ) { - if( capacity <= size ) { - if( blocking ) { - while( capacity <= size ) { - sync.wait(); - } - } else { - return false; - } - } - if( !sameRef ) { - array[ writePos ] = e; - } - writePos = (writePos + 1) % capacity; - size++; - sync.notifyAll(); // notify waiting getter - return true; - } - } - - public final void waitForFreeSlots(int count) throws InterruptedException { - synchronized ( sync ) { - if( capacity - size < count ) { - while( capacity - size < count ) { - System.err.println("XXXX AAA XXX"); - sync.wait(); - } - } - } - } - -} -- cgit v1.2.3