summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 858a3a5b..b1644cf2 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 96478c27..a901de4f 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 95b82ab8..78f7d3dc 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 53d59d41..e8d697b1 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 2c982f0f..57ef316e 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 d87129a4..0edfb7e2 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 3273c4db..58a6333c 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 00000000..fcea22c1
--- /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 18c981f2..ce844bf8 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 4918e725..cd14c59c 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 141deb5a..3f145b3b 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 eb42092e..156a9fa6 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 9ea960ae..e8bd0124 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 3f89ad0e..9f92b9a3 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();
+ }
+
}
}