summaryrefslogtreecommitdiffstats
path: root/resources/clImplCustomCode.c
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-05-04 02:22:19 +0200
committerMichael Bien <[email protected]>2010-05-04 02:22:19 +0200
commit9125a275449cb533798357914945de1f742a91f9 (patch)
treec25d5357ac99ec24bee4e7f2c95775362877db0b /resources/clImplCustomCode.c
parentea95ca1b96300fc9b2ec937759663eb0ed1406bf (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.c')
-rw-r--r--resources/clImplCustomCode.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c
index b491eb7f..1314e7b8 100644
--- a/resources/clImplCustomCode.c
+++ b/resources/clImplCustomCode.c
@@ -25,7 +25,7 @@ JNI_OnLoad(JavaVM * _jvm, void *reserved) {
// throws ClassNotFoundException (or other reflection stuff)
jclass buildCBClassID = (*env)->FindClass(env, "com/jogamp/opencl/impl/BuildProgramCallback");
- jclass errorHandlerClassID = (*env)->FindClass(env, "com/jogamp/opencl/CreateContextCallback");
+ jclass errorHandlerClassID = (*env)->FindClass(env, "com/jogamp/opencl/CLErrorHandler");
// throws even more reflection Exceptions
// IDs are unique and do not change
@@ -35,7 +35,7 @@ JNI_OnLoad(JavaVM * _jvm, void *reserved) {
if (errorHandlerClassID != NULL) {
cccb_mid = (*env)->GetMethodID(env, errorHandlerClassID, "onError", "(Ljava/lang/String;Ljava/nio/ByteBuffer;J)V");
}
-
+
return JNI_VERSION_1_2;
}
@@ -47,8 +47,10 @@ void buildProgramCallback(cl_program id, void * object) {
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
- (*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)id);
- (*env)->DeleteGlobalRef(env, obj);
+ (*env)->CallVoidMethod(env, obj, bcb_mid, (jlong)id);
+ (*env)->DeleteGlobalRef(env, obj);
+
+ (*jvm)->DetachCurrentThread(jvm);
}
@@ -59,11 +61,12 @@ void createContextCallback(const char * errinfo, const void * private_info, size
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
- jstring errorString = (*env)->NewStringUTF(env, errinfo);
+ jstring errorString = (*env)->NewStringUTF(env, errinfo);
- //TODO private_info
- (*env)->CallVoidMethod(env, obj, cccb_mid, errorString, NULL, 0);
- //(*env)->DeleteGlobalRef(env, obj);
+ //TODO private_info
+ (*env)->CallVoidMethod(env, obj, cccb_mid, errorString, NULL, 0);
+
+ (*jvm)->DetachCurrentThread(jvm);
}
@@ -80,7 +83,7 @@ void createContextCallback(const char * errinfo, const void * private_info, size
*/
JNIEXPORT jlong JNICALL
Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject _unused,
- jobject props, jint props_byte_offset, jobject device_type, jobject cb, jobject errcode, jint errcode_byte_offset) {
+ jobject props, jint props_byte_offset, jobject device_type, jobject cb, jobject global, jobject errcode, jint errcode_byte_offset) {
cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
@@ -103,9 +106,16 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
_ctx = clCreateContextFromType(_props_ptr, (uint64_t) device_type, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
- // if something went wrong
- if (_ctx == NULL && globalCB != NULL) {
- (*env)->DeleteGlobalRef(env, globalCB);
+ if(globalCB != NULL) {
+ jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
+ // if something went wrong
+ if(_ctx == NULL) {
+ g[0] = 0;
+ (*env)->DeleteGlobalRef(env, globalCB);
+ }else{
+ g[0] = (jlong)globalCB;
+ }
+ (*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
return (jlong) (intptr_t)_ctx;
@@ -123,7 +133,7 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContextFromType0(JNIEnv *env, jobject
*/
JNIEXPORT jlong JNICALL
Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused,
- jobject props, jint props_byte_offset, jint numDevices, jobject deviceList, jint device_type_offset, jobject cb, jobject errcode, jint errcode_byte_offset) {
+ jobject props, jint props_byte_offset, jint numDevices, jobject deviceList, jint device_type_offset, jobject cb, jobject global, jobject errcode, jint errcode_byte_offset) {
cl_context_properties* _props_ptr = NULL;
int32_t * _errcode_ptr = NULL;
@@ -149,14 +159,38 @@ Java_com_jogamp_opencl_impl_CLImpl_clCreateContext0(JNIEnv *env, jobject _unused
_ctx = clCreateContext(_props_ptr, numDevices, (cl_device_id *)_deviceListPtr, pfn_notify, globalCB, (int32_t *) _errcode_ptr);
- // if something went wrong
- if (_ctx == NULL && globalCB != NULL) {
- (*env)->DeleteGlobalRef(env, globalCB);
+ if(globalCB != NULL) {
+ jlong *g = (*env)->GetPrimitiveArrayCritical(env, global, NULL);
+ // if something went wrong
+ if(_ctx == NULL) {
+ g[0] = 0;
+ (*env)->DeleteGlobalRef(env, globalCB);
+ }else{
+ g[0] = (jlong)globalCB;
+ }
+ (*env)->ReleasePrimitiveArrayCritical(env, global, g, 0);
}
return (jlong) (intptr_t)_ctx;
}
+/* Java->C glue code:
+ * Java package: com.jogamp.opencl.impl.CLImpl
+ * Java method: int clReleaseContextImpl(long context)
+ * C function: int32_t clReleaseContextImpl(cl_context context);
+ */
+JNIEXPORT jint JNICALL
+Java_com_jogamp_opencl_impl_CLImpl_clReleaseContextImpl(JNIEnv *env, jobject _unused, jlong context, jlong global) {
+ int32_t _res;
+ _res = clReleaseContext((cl_context) (intptr_t) context);
+ // TODO deal with retains
+ if (global != 0) {
+ (*env)->DeleteGlobalRef(env, (jobject) global);
+ }
+ return _res;
+}
+
+
/**
* Entry point to C language function:
* extern CL_API_ENTRY cl_int CL_API_CALL