summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/CLObjectResource.java
blob: 3a8fe5006e0a3552fa1908cec5c139c732bb3f16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * 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);
    }

    @Override
    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();
        }
    }

    @Override
    public boolean isReleased() {
        return released;
    }
    

}