diff options
author | Michael Bien <[email protected]> | 2010-05-04 02:22:19 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-05-04 02:22:19 +0200 |
commit | 9125a275449cb533798357914945de1f742a91f9 (patch) | |
tree | c25d5357ac99ec24bee4e7f2c95775362877db0b /resources/clImplCustomCode.java | |
parent | ea95ca1b96300fc9b2ec937759663eb0ed1406bf (diff) |
finished main functionality of ErrorHandler impl.
- using event listener add/remove pattern instead add on context creation
- context -> error handler object global reference mapping(TM) using LongLongMap in CLImpl
- global ref is deleted on context release
Diffstat (limited to 'resources/clImplCustomCode.java')
-rw-r--r-- | resources/clImplCustomCode.java | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java index f3daddf0..d2993f96 100644 --- a/resources/clImplCustomCode.java +++ b/resources/clImplCustomCode.java @@ -1,33 +1,66 @@ private final CLProcAddressTable addressTable; + //maps the context id to its error handler's global object pointer + private final com.jogamp.common.util.LongLongHashMap contextCallbackMap; + public CLImpl(CLProcAddressTable addressTable) { this.addressTable = addressTable; + this.contextCallbackMap = new com.jogamp.common.util.LongLongHashMap(); + this.contextCallbackMap.setKeyNotFoundValue(0); } - public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CreateContextCallback pfn_notify, IntBuffer errcode_ret) { + public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CLErrorHandler pfn_notify, IntBuffer errcode_ret) { if(properties!=null && !properties.isDirect()) throw new RuntimeException("Argument \"properties\" was not a direct buffer"); - return this.clCreateContext0( + long[] global = new long[1]; + long ctx = this.clCreateContext0( properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties), devices!=null?devices.remaining():0, devices!=null?devices.getBuffer():null, Buffers.getDirectBufferByteOffset(devices), - null, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) ); + pfn_notify, global, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) ); + + if(pfn_notify != null && global[0] != 0) { + synchronized(contextCallbackMap) { + contextCallbackMap.put(ctx, global[0]); + } + } + return ctx; } - private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, CreateContextCallback pfn_notify, Object errcode_ret, int err_offset); + private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, CLErrorHandler pfn_notify, long[] global, Object errcode_ret, int err_offset); - public long clCreateContextFromType(PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, IntBuffer errcode_ret) { + public long clCreateContextFromType(PointerBuffer properties, long device_type, CLErrorHandler pfn_notify, IntBuffer errcode_ret) { if(properties!=null && !properties.isDirect()) throw new RuntimeException("Argument \"properties\" was not a direct buffer"); - return this.clCreateContextFromType0( + long[] global = new long[1]; + long ctx = this.clCreateContextFromType0( properties!=null?properties.getBuffer():null, Buffers.getDirectBufferByteOffset(properties), - device_type, pfn_notify, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) ); + device_type, pfn_notify, global, errcode_ret, Buffers.getDirectBufferByteOffset(errcode_ret) ); + + if(pfn_notify != null && global[0] != 0) { + synchronized(contextCallbackMap) { + contextCallbackMap.put(ctx, global[0]); + } + } + return ctx; } - private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CreateContextCallback pfn_notify, Object errcode_ret, int err_offset); + private native long clCreateContextFromType0(Object properties, int props_offset, long device_type, CLErrorHandler pfn_notify, long[] global, Object errcode_ret, int err_offset); + + + public int clReleaseContext(long context) { + long global = 0; + synchronized(contextCallbackMap) { + global = contextCallbackMap.remove(context); + } + return clReleaseContextImpl(context, global); + } + + /** Interface to C language function: <br> <code> int32_t {@native clReleaseContext}(cl_context context); </code> */ + public native int clReleaseContextImpl(long context, long global); /** Interface to C language function: <br> <code> int32_t clBuildProgram(cl_program, uint32_t, cl_device_id * , const char * , void * ); </code> */ |