diff options
author | Michael Bien <[email protected]> | 2010-02-28 16:41:24 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-02-28 16:41:24 +0100 |
commit | 19c1825b81e9add833077260bb937416268a1bf6 (patch) | |
tree | 3a7cc340d457b33c8eacd9652220ffca86592365 /src | |
parent | f24477382cc1c26d5f5fd0a09e2c42c7f60cb974 (diff) |
introduced (package private) Disposable interface for forward compatiblility with JDK7's ARM blocks.
CLResource extends Disposable.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/mbien/opencl/CLCommandQueue.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLEvent.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLEventList.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLKernel.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLMemory.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLResource.java | 8 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLSampler.java | 4 | ||||
-rw-r--r-- | src/com/mbien/opencl/Disposable.java | 21 |
10 files changed, 60 insertions, 1 deletions
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java index 582bce5f..0001eb65 100644 --- a/src/com/mbien/opencl/CLCommandQueue.java +++ b/src/com/mbien/opencl/CLCommandQueue.java @@ -779,6 +779,10 @@ public class CLCommandQueue extends CLObject implements CLResource { checkForError(ret, "can not release command queue"); } + public void close() { + release(); + } + private static PointerBuffer copy2NIO(PointerBuffer buffer, long a) { return buffer.put(2, a).position(2); } diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 4cc21d0f..6b09cc37 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -378,6 +378,10 @@ public class CLContext extends CLObject implements CLResource { checkForError(ret, "error releasing context"); } + public void close() { + release(); + } + /** * Returns the CLPlatform this context is running on. */ diff --git a/src/com/mbien/opencl/CLEvent.java b/src/com/mbien/opencl/CLEvent.java index fb0af13f..1eb3bb64 100644 --- a/src/com/mbien/opencl/CLEvent.java +++ b/src/com/mbien/opencl/CLEvent.java @@ -30,6 +30,10 @@ public class CLEvent extends CLObject implements CLResource { checkForError(ret, "can not release event"); } + public void close() { + release(); + } + /** * Returns the execution status of the command which triggers this event. */ diff --git a/src/com/mbien/opencl/CLEventList.java b/src/com/mbien/opencl/CLEventList.java index 66b07d55..6a2716db 100644 --- a/src/com/mbien/opencl/CLEventList.java +++ b/src/com/mbien/opencl/CLEventList.java @@ -40,6 +40,10 @@ public final class CLEventList implements CLResource, Iterable<CLEvent> { 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); diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java index b661d31c..a50478aa 100644 --- a/src/com/mbien/opencl/CLKernel.java +++ b/src/com/mbien/opencl/CLKernel.java @@ -236,6 +236,10 @@ public class CLKernel extends CLObject implements CLResource, Cloneable { checkForError(ret, "can not release kernel"); } + public void close() { + release(); + } + @Override public String toString() { return "CLKernel [id: " + ID diff --git a/src/com/mbien/opencl/CLMemory.java b/src/com/mbien/opencl/CLMemory.java index 6498bcc7..84aeb6b1 100644 --- a/src/com/mbien/opencl/CLMemory.java +++ b/src/com/mbien/opencl/CLMemory.java @@ -101,6 +101,10 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL checkForError(ret, "can not release mem object"); } + public void close() { + release(); + } + // kept only for debugging purposes /** * Returns the OpenGL buffer type of this shared buffer. diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java index 806383f6..df556937 100644 --- a/src/com/mbien/opencl/CLProgram.java +++ b/src/com/mbien/opencl/CLProgram.java @@ -331,6 +331,10 @@ public class CLProgram extends CLObject implements CLResource { checkForError(ret, "can not release program"); } + public void close() { + release(); + } + private void releaseKernels() { if(!kernels.isEmpty()) { // copy to array to prevent concurrent modification exception diff --git a/src/com/mbien/opencl/CLResource.java b/src/com/mbien/opencl/CLResource.java index 4f0d9d01..8996b40e 100644 --- a/src/com/mbien/opencl/CLResource.java +++ b/src/com/mbien/opencl/CLResource.java @@ -4,11 +4,17 @@ package com.mbien.opencl; * Releasable OpenCL resource. * @author Michael Bien */ -public interface CLResource { +public interface CLResource extends Disposable<CLException> { /** * Releases the OpenCL resource. */ public void release(); + /** + * Calls {@link #release()}; + * @see #release() + */ + @Override public void close(); + } diff --git a/src/com/mbien/opencl/CLSampler.java b/src/com/mbien/opencl/CLSampler.java index e12fc43b..28b712a9 100644 --- a/src/com/mbien/opencl/CLSampler.java +++ b/src/com/mbien/opencl/CLSampler.java @@ -49,6 +49,10 @@ public class CLSampler extends CLObject implements CLResource { checkForError(ret, "can not release sampler"); } + public void close() { + release(); + } + private class CLSamplerInfoAccessor extends CLInfoAccessor { @Override diff --git a/src/com/mbien/opencl/Disposable.java b/src/com/mbien/opencl/Disposable.java new file mode 100644 index 00000000..f85f99b6 --- /dev/null +++ b/src/com/mbien/opencl/Disposable.java @@ -0,0 +1,21 @@ +package com.mbien.opencl; + +/* + * JDK7 ARM proposal, cypied to be forward compatible with java 7 automatic resource managment blocks. + * @author Michael Bien + */ + +//package java.lang; + +/** + * A resource that must be closed when it is no longer needed. + * + * @param X the type of exception thrown by the close method (or + * {@link RuntimeException} if the close method is not permitted + * to throw any checked exceptions). + */ +/*public*/ interface Disposable<X extends Throwable> { + + void close() throws X; + +} |