diff options
author | Michael Bien <[email protected]> | 2011-06-19 22:31:05 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-06-19 22:31:05 +0200 |
commit | 826dacffbae941a35a7cc74515751ddb1d5711a2 (patch) | |
tree | 5cf5d5f67ceda1cbf136a6f30295f4ffa8c6c640 /src/com/jogamp/opencl/CLObjectResource.java | |
parent | 00096ac5b2c824fc7e8d7203229c8f246caf833c (diff) |
- added isReleased() to CLResource, made CLObject public.
- a CLResource will throw an Exception if released twice.
Diffstat (limited to 'src/com/jogamp/opencl/CLObjectResource.java')
-rw-r--r-- | src/com/jogamp/opencl/CLObjectResource.java | 51 |
1 files changed, 51 insertions, 0 deletions
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; + } + + +} |