summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <mbien@fh-landshut.de>2011-06-19 22:31:05 +0200
committerMichael Bien <mbien@fh-landshut.de>2011-06-19 22:31:05 +0200
commit826dacffbae941a35a7cc74515751ddb1d5711a2 (patch)
tree5cf5d5f67ceda1cbf136a6f30295f4ffa8c6c640
parent00096ac5b2c824fc7e8d7203229c8f246caf833c (diff)
- added isReleased() to CLResource, made CLObject public.
- a CLResource will throw an Exception if released twice.
-rw-r--r--src/com/jogamp/opencl/CLCommandQueue.java4
-rw-r--r--src/com/jogamp/opencl/CLContext.java3
-rw-r--r--src/com/jogamp/opencl/CLEvent.java3
-rw-r--r--src/com/jogamp/opencl/CLEventList.java4
-rw-r--r--src/com/jogamp/opencl/CLKernel.java3
-rw-r--r--src/com/jogamp/opencl/CLMemory.java3
-rw-r--r--src/com/jogamp/opencl/CLObject.java17
-rw-r--r--src/com/jogamp/opencl/CLObjectResource.java51
-rw-r--r--src/com/jogamp/opencl/CLProgram.java3
-rw-r--r--src/com/jogamp/opencl/CLResource.java4
-rw-r--r--src/com/jogamp/opencl/CLSampler.java3
-rw-r--r--src/com/jogamp/opencl/util/CLMultiContext.java10
-rw-r--r--src/com/jogamp/opencl/util/concurrent/CLCommandQueuePool.java11
-rw-r--r--src/com/jogamp/opencl/util/concurrent/CLQueueContext.java6
14 files changed, 102 insertions, 23 deletions
diff --git a/src/com/jogamp/opencl/CLCommandQueue.java b/src/com/jogamp/opencl/CLCommandQueue.java
index 858a3a5..b1644cf 100644
--- a/src/com/jogamp/opencl/CLCommandQueue.java
+++ b/src/com/jogamp/opencl/CLCommandQueue.java
@@ -58,7 +58,7 @@ import static com.jogamp.opencl.util.CLUtil.*;
* @see CLDevice#createCommandQueue(com.jogamp.opencl.CLCommandQueue.Mode...)
* @author Michael Bien
*/
-public class CLCommandQueue extends CLObject implements CLResource {
+public class CLCommandQueue extends CLObjectResource {
private final CLCommandQueueBinding cl;
private final CLDevice device;
@@ -1795,7 +1795,9 @@ public class CLCommandQueue extends CLObject implements CLResource {
return (Mode.OUT_OF_ORDER_MODE.QUEUE_MODE & properties) != 0;
}
+ @Override
public void release() {
+ super.release();
int ret = cl.clReleaseCommandQueue(ID);
context.onCommandQueueReleased(device, this);
if(ret != CL_SUCCESS) {
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index 96478c2..a901de4 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -81,7 +81,7 @@ import static java.util.Collections.*;
*
* @author Michael Bien
*/
-public class CLContext extends CLObject implements CLResource {
+public class CLContext extends CLObjectResource {
protected CLDevice[] devices;
@@ -501,6 +501,7 @@ public class CLContext extends CLObject implements CLResource {
*/
@Override
public synchronized void release() {
+ super.release();
try{
//release all resources
diff --git a/src/com/jogamp/opencl/CLEvent.java b/src/com/jogamp/opencl/CLEvent.java
index 95b82ab..78f7d3d 100644
--- a/src/com/jogamp/opencl/CLEvent.java
+++ b/src/com/jogamp/opencl/CLEvent.java
@@ -45,7 +45,7 @@ import static com.jogamp.opencl.CLException.*;
* {@link com.jogamp.opencl.CLCommandQueue.Mode#PROFILING_MODE}.
* @author Michael Bien
*/
-public class CLEvent extends CLObject implements CLResource {
+public class CLEvent extends CLObjectResource {
private final CLEventInfoAccessor eventInfo;
private final CLEventProfilingInfoAccessor eventProfilingInfo;
@@ -76,6 +76,7 @@ public class CLEvent extends CLObject implements CLResource {
@Override
public void release() {
+ super.release();
int ret = binding.clReleaseEvent(ID);
checkForError(ret, "can not release event");
}
diff --git a/src/com/jogamp/opencl/CLEventList.java b/src/com/jogamp/opencl/CLEventList.java
index 53d59d4..e8d697b 100644
--- a/src/com/jogamp/opencl/CLEventList.java
+++ b/src/com/jogamp/opencl/CLEventList.java
@@ -176,6 +176,10 @@ public final class CLEventList implements CLResource, AutoCloseable, Iterable<CL
return events.length;
}
+ public boolean isReleased() {
+ return size == 0;
+ }
+
@Override
public Iterator<CLEvent> iterator() {
return new EventIterator(events, size);
diff --git a/src/com/jogamp/opencl/CLKernel.java b/src/com/jogamp/opencl/CLKernel.java
index 2c982f0..57ef316 100644
--- a/src/com/jogamp/opencl/CLKernel.java
+++ b/src/com/jogamp/opencl/CLKernel.java
@@ -50,7 +50,7 @@ import static com.jogamp.common.os.Platform.*;
* @see CLProgram#createCLKernels()
* @author Michael Bien
*/
-public class CLKernel extends CLObject implements CLResource, Cloneable {
+public class CLKernel extends CLObjectResource implements Cloneable {
public final String name;
public final int numArgs;
@@ -322,6 +322,7 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
*/
@Override
public void release() {
+ super.release();
int ret = binding.clReleaseKernel(ID);
program.onKernelReleased(this);
if(ret != CL_SUCCESS) {
diff --git a/src/com/jogamp/opencl/CLMemory.java b/src/com/jogamp/opencl/CLMemory.java
index d87129a..0edfb7e 100644
--- a/src/com/jogamp/opencl/CLMemory.java
+++ b/src/com/jogamp/opencl/CLMemory.java
@@ -47,7 +47,7 @@ import static com.jogamp.opencl.llb.gl.CLGL.*;
* Represents an OpenCL memory object and wraps an optional NIO buffer.
* @author Michael Bien
*/
-public abstract class CLMemory <B extends Buffer> extends CLObject implements CLResource {
+public abstract class CLMemory <B extends Buffer> extends CLObjectResource {
B buffer;
protected final int FLAGS;
@@ -222,6 +222,7 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL
@Override
public void release() {
+ super.release();
int ret = binding.clReleaseMemObject(ID);
context.onMemoryReleased(this);
if(ret != CL_SUCCESS) {
diff --git a/src/com/jogamp/opencl/CLObject.java b/src/com/jogamp/opencl/CLObject.java
index 3273c4d..58a6333 100644
--- a/src/com/jogamp/opencl/CLObject.java
+++ b/src/com/jogamp/opencl/CLObject.java
@@ -28,13 +28,12 @@
package com.jogamp.opencl;
-import com.jogamp.common.AutoCloseable;
/**
* Common superclass for all OpenCL objects.
* @author Michael Bien
*/
-abstract class CLObject implements AutoCloseable {
+public abstract class CLObject {
/**
* The OpenCL object handle.
@@ -54,20 +53,6 @@ abstract class CLObject implements AutoCloseable {
}
/**
- * Implementation detail.
- * TODO remove as soon we have extension methods.
- * @deprecated This method is not intended to be called from client code.
- * @see java.lang.AutoCloseable
- */
- @Deprecated
- @Override
- public final void close() {
- if(this instanceof CLResource) {
- ((CLResource)this).release();
- }
- }
-
- /**
* Returns the context for this OpenCL object.
*/
public CLContext getContext() {
diff --git a/src/com/jogamp/opencl/CLObjectResource.java b/src/com/jogamp/opencl/CLObjectResource.java
new file mode 100644
index 0000000..fcea22c
--- /dev/null
+++ b/src/com/jogamp/opencl/CLObjectResource.java
@@ -0,0 +1,51 @@
+/*
+ * Created on Saturday, June 18 2011 02:36
+ */
+package com.jogamp.opencl;
+
+import com.jogamp.common.AutoCloseable;
+
+/**
+ * Releasable resource with an CL object ID.
+ * @author Michael Bien
+ */
+abstract class CLObjectResource extends CLObject implements CLResource, AutoCloseable {
+
+ private boolean released;
+
+ public CLObjectResource(long ID) {
+ super(ID);
+ }
+
+ public CLObjectResource(CLContext context, long ID) {
+ super(context, ID);
+ }
+
+ public void release() {
+ if(released) {
+ throw new RuntimeException(getClass().getSimpleName()+" was already released.");
+ }else{
+ released = true;
+ }
+ }
+
+ /**
+ * Implementation detail.
+ * TODO remove as soon we have extension methods.
+ * @deprecated This method is not intended to be called from client code.
+ * @see java.lang.AutoCloseable
+ */
+ @Deprecated
+ @Override
+ public final void close() {
+ if(this instanceof CLResource) {
+ ((CLResource)this).release();
+ }
+ }
+
+ public boolean isReleased() {
+ return released;
+ }
+
+
+}
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java
index 18c981f..ce844bf 100644
--- a/src/com/jogamp/opencl/CLProgram.java
+++ b/src/com/jogamp/opencl/CLProgram.java
@@ -61,7 +61,7 @@ import static com.jogamp.common.nio.Buffers.*;
* @see CLContext#createProgram(java.util.Map)
* @author Michael Bien
*/
-public class CLProgram extends CLObject implements CLResource {
+public class CLProgram extends CLObjectResource {
private final static ReentrantLock buildLock = new ReentrantLock();
private final CLProgramBinding binding;
@@ -475,6 +475,7 @@ public class CLProgram extends CLObject implements CLResource {
@Override
public void release() {
+ super.release();
releaseKernels();
executable = false;
diff --git a/src/com/jogamp/opencl/CLResource.java b/src/com/jogamp/opencl/CLResource.java
index 4918e72..cd14c59 100644
--- a/src/com/jogamp/opencl/CLResource.java
+++ b/src/com/jogamp/opencl/CLResource.java
@@ -39,4 +39,8 @@ public interface CLResource {
*/
public void release();
+ /**
+ * Returns true if {@link #release()} has been called.
+ */
+ public boolean isReleased();
}
diff --git a/src/com/jogamp/opencl/CLSampler.java b/src/com/jogamp/opencl/CLSampler.java
index 141deb5..3f145b3 100644
--- a/src/com/jogamp/opencl/CLSampler.java
+++ b/src/com/jogamp/opencl/CLSampler.java
@@ -43,7 +43,7 @@ import static com.jogamp.opencl.util.CLUtil.*;
* @see CLContext#createSampler(com.jogamp.opencl.CLSampler.AddressingMode, com.jogamp.opencl.CLSampler.FilteringMode, boolean)
* @author Michael Bien
*/
-public class CLSampler extends CLObject implements CLResource {
+public class CLSampler extends CLObjectResource {
private final CLSamplerInfoAccessor samplerInfo;
private final CLSamplerBinding binding;
@@ -80,6 +80,7 @@ public class CLSampler extends CLObject implements CLResource {
@Override
public void release() {
+ super.release();
int ret = binding.clReleaseSampler(ID);
context.onSamplerReleased(this);
if(ret != CL_SUCCESS) {
diff --git a/src/com/jogamp/opencl/util/CLMultiContext.java b/src/com/jogamp/opencl/util/CLMultiContext.java
index eb42092..156a9fa 100644
--- a/src/com/jogamp/opencl/util/CLMultiContext.java
+++ b/src/com/jogamp/opencl/util/CLMultiContext.java
@@ -25,6 +25,7 @@ import static com.jogamp.opencl.CLDevice.Type.*;
public class CLMultiContext implements CLResource {
private final List<CLContext> contexts;
+ private boolean released;
private CLMultiContext() {
contexts = new ArrayList<CLContext>();
@@ -132,7 +133,12 @@ public class CLMultiContext implements CLResource {
* Releases all contexts.
* @see CLContext#release()
*/
+ @Override
public void release() {
+ if(released) {
+ throw new RuntimeException(getClass().getSimpleName()+" already released");
+ }
+ released = true;
for (CLContext context : contexts) {
context.release();
}
@@ -154,6 +160,10 @@ public class CLMultiContext implements CLResource {
return devices;
}
+ public boolean isReleased() {
+ return released;
+ }
+
@Override
public String toString() {
return getClass().getSimpleName()+" [" + contexts.size()+" contexts, "
diff --git a/src/com/jogamp/opencl/util/concurrent/CLCommandQueuePool.java b/src/com/jogamp/opencl/util/concurrent/CLCommandQueuePool.java
index 9ea960a..e8bd012 100644
--- a/src/com/jogamp/opencl/util/concurrent/CLCommandQueuePool.java
+++ b/src/com/jogamp/opencl/util/concurrent/CLCommandQueuePool.java
@@ -29,6 +29,7 @@ public class CLCommandQueuePool<C extends CLQueueContext> implements CLResource
private List<CLQueueContext> contexts;
private ExecutorService excecutor;
private FinishAction finishAction = FinishAction.DO_NOTHING;
+ private boolean released;
private CLCommandQueuePool(CLQueueContextFactory factory, Collection<CLCommandQueue> queues) {
this.contexts = initContexts(queues, factory);
@@ -157,7 +158,12 @@ public class CLCommandQueuePool<C extends CLQueueContext> implements CLResource
/**
* Releases all queues.
*/
+ @Override
public void release() {
+ if(released) {
+ throw new RuntimeException(getClass().getSimpleName()+" already released");
+ }
+ released = true;
excecutor.shutdown();
for (CLQueueContext context : contexts) {
context.queue.finish().release();
@@ -187,6 +193,11 @@ public class CLCommandQueuePool<C extends CLQueueContext> implements CLResource
return finishAction;
}
+ @Override
+ public boolean isReleased() {
+ return released;
+ }
+
/**
* Sets the action which is run after every completed task.
* This is mainly intended for debugging, default value is {@link FinishAction#DO_NOTHING}.
diff --git a/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java b/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
index 3f89ad0..9f92b9a 100644
--- a/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
+++ b/src/com/jogamp/opencl/util/concurrent/CLQueueContext.java
@@ -63,10 +63,16 @@ public abstract class CLQueueContext implements CLResource {
return program;
}
+ @Override
public void release() {
program.release();
}
+ @Override
+ public boolean isReleased() {
+ return program.isReleased();
+ }
+
}
}