summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLEventList.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-12 19:53:13 +0100
committerMichael Bien <[email protected]>2010-01-12 19:53:13 +0100
commit3d01c2c74e282c19e9286d4f4509bef8302ca93e (patch)
treee9f6e0da1877776ca9851600d1f6e02ba189cfd1 /src/com/mbien/opencl/CLEventList.java
parent286f94a7b148856666d7c05853ba9b2ba799b638 (diff)
introduced CLEventList, an optimized nio collecton for storing CLEvents.
added hashCode() and equals() to CLEvent. CLEvent support in CLCommandQueue. Several NIO optimizations.
Diffstat (limited to 'src/com/mbien/opencl/CLEventList.java')
-rw-r--r--src/com/mbien/opencl/CLEventList.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLEventList.java b/src/com/mbien/opencl/CLEventList.java
new file mode 100644
index 00000000..66b07d55
--- /dev/null
+++ b/src/com/mbien/opencl/CLEventList.java
@@ -0,0 +1,95 @@
+package com.mbien.opencl;
+
+import com.sun.gluegen.runtime.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 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.");
+ }
+
+ }
+
+}