summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/CLEventList.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-04-12 22:18:39 +0200
committerMichael Bien <[email protected]>2010-04-12 22:18:39 +0200
commitbf07b44ed6a8958dd321cc4c08fd2bdd08299611 (patch)
treee24b7c4e4197a80e0ecaad75b9b3667299fd8323 /src/com/jogamp/opencl/CLEventList.java
parent7680472b21ec1e2deacb49addae65c820a2e2a4d (diff)
renamed package com.mbien.* in com.jogamp.* JOCL is now officially a JogAmp team player ;).
Diffstat (limited to 'src/com/jogamp/opencl/CLEventList.java')
-rw-r--r--src/com/jogamp/opencl/CLEventList.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/CLEventList.java b/src/com/jogamp/opencl/CLEventList.java
new file mode 100644
index 00000000..b9b4cd4b
--- /dev/null
+++ b/src/com/jogamp/opencl/CLEventList.java
@@ -0,0 +1,99 @@
+package com.jogamp.opencl;
+
+import com.jogamp.common.nio.PointerBuffer;
+import java.util.Iterator;
+
+/**
+ * Fixed size list for storing CLEvents.
+ * @author Michael Bien
+ */
+public final class CLEventList implements CLResource, Iterable<CLEvent> {
+
+ private final CLEvent[] events;
+
+ final PointerBuffer IDs;
+ int size;
+
+ public CLEventList(int capacity) {
+ this.events = new CLEvent[capacity];
+ this.IDs = PointerBuffer.allocateDirect(capacity);
+ }
+
+ void createEvent(CLContext context) {
+
+ if(events[size] != null)
+ events[size].release();
+
+ events[size] = new CLEvent(context, IDs.get());
+ size++;
+ }
+
+ /**
+ * Releases all CLEvents in this list.
+ */
+ public void release() {
+ for (int i = 0; i < size; i++) {
+ events[i].release();
+ events[i] = null;
+ }
+ size = 0;
+ IDs.rewind();
+ }
+
+ public void close() {
+ release();
+ }
+
+ public CLEvent getEvent(int index) {
+ if(index >= size)
+ throw new IndexOutOfBoundsException("list contains "+size+" events, can not return event with index "+index);
+ return events[index];
+ }
+
+ /**
+ * Returns the current size of this list.
+ */
+ public int size() {
+ return size;
+ }
+
+ /**
+ * Returns the maximum size of this list.
+ */
+ public int capacity() {
+ return events.length;
+ }
+
+ public Iterator<CLEvent> iterator() {
+ return new EventIterator(events, size);
+ }
+
+ private static class EventIterator implements Iterator<CLEvent> {
+
+ private final CLEvent[] events;
+ private final int size;
+ private int index;
+
+ private EventIterator(CLEvent[] events, int size) {
+ this.events = events;
+ this.size = size;
+ }
+
+ public boolean hasNext() {
+ return index < size;
+ }
+
+ public CLEvent next() {
+ if(hasNext())
+ return events[index++];
+ else
+ return null;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("remove() not supported.");
+ }
+
+ }
+
+}