diff options
Diffstat (limited to 'src/com/jogamp/opencl/CLInfoAccessor.java')
-rw-r--r-- | src/com/jogamp/opencl/CLInfoAccessor.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLInfoAccessor.java new file mode 100644 index 00000000..56f2318d --- /dev/null +++ b/src/com/jogamp/opencl/CLInfoAccessor.java @@ -0,0 +1,62 @@ +package com.jogamp.opencl; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.Int64Buffer; +import com.jogamp.opencl.util.CLUtil; +import java.nio.Buffer; +import java.nio.ByteBuffer; + +import static com.jogamp.opencl.CLException.*; + +/** + * Internal utility for common OpenCL clGetFooInfo calls. + * Threadsafe. + * @author Michael Bien + */ +abstract class CLInfoAccessor { + + protected final static ThreadLocal<ByteBuffer> localBB = new ThreadLocal<ByteBuffer>() { + + @Override + protected ByteBuffer initialValue() { + return Buffers.newDirectByteBuffer(512); + } + + }; + protected final static ThreadLocal<Int64Buffer> localPB = new ThreadLocal<Int64Buffer>() { + + @Override + protected Int64Buffer initialValue() { + return Int64Buffer.allocateDirect(1); + } + + }; + + public final long getLong(int key) { + + ByteBuffer buffer = localBB.get(); + int ret = getInfo(key, 8, buffer, null); + checkForError(ret, "error while asking for info value"); + + return buffer.getLong(0); + } + + public final String getString(int key) { + + ByteBuffer buffer = localBB.get(); + Int64Buffer sizeBuffer = localPB.get(); + int ret = getInfo(key, buffer.capacity(), buffer, sizeBuffer); + checkForError(ret, "error while asking for info string"); + + int clSize = (int)sizeBuffer.get(0); + byte[] array = new byte[clSize-1]; // last char is always null + buffer.get(array).rewind(); + + return CLUtil.clString2JavaString(array, clSize); + + } + + protected abstract int getInfo(int name, long valueSize, Buffer value, Int64Buffer valueSizeRet); + + +} |