diff options
author | Sven Gothel <[email protected]> | 2014-01-11 02:11:47 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-01-11 02:11:47 +0100 |
commit | 6647b4a63866a554c738e0b7b61e6dc40a6fb511 (patch) | |
tree | abc0c866524857b207d5beb406bc768c70c6c06a /src/newt/native/NewtCommon.h | |
parent | 5ef83c2b8576ccd764ffc4953eea506bd96277c3 (diff) |
[Jogl|Nativewindow|Newt]Common: Align all *Common_GetJNIEnv()/_ReleaseJNIEnv() Methods and Usage / Check arguments ..
Since we still don't use inter-module native code sharing, align the JNIEnv get/release methods and usage.
Most beneficary here is OSX and the GLDebugMessageHandle,
both managed the JVM handle on their own - removed now.
Also ensuring that *Common_init(..) is called for all modules on all platforms.
Diffstat (limited to 'src/newt/native/NewtCommon.h')
-rw-r--r-- | src/newt/native/NewtCommon.h | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/newt/native/NewtCommon.h b/src/newt/native/NewtCommon.h index 9cc9e93a6..43db72b5b 100644 --- a/src/newt/native/NewtCommon.h +++ b/src/newt/native/NewtCommon.h @@ -42,23 +42,18 @@ void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...); /** * - * 1) Store jvmHandle and jvmVersion + * 1) Init static jvmHandle, jvmVersion and clazz references + * from an early initialization call w/ valid 'JNIEnv * env' - JavaVM *jvmHandle = NULL; - int jvmVersion = 0; - - if(0 != (*env)->GetJavaVM(env, &jvmHandle)) { - jvmHandle = NULL; - } else { - jvmVersion = (*env)->GetVersion(env); - } + NewtCommon_init(env); * * 2) Use current thread JNIEnv or attach current thread to JVM, generating new JNIEnv * + int asDaemon = 0; int shallBeDetached = 0; - JNIEnv* env = NewtCommon_GetJNIEnv(jvmHandle, jvmVersion, &shallBeDetached); + JNIEnv* env = NewtCommon_GetJNIEnv(asDaemon, &shallBeDetached); if(NULL==env) { DBG_PRINT("drawRect: null JNIEnv\n"); return; @@ -70,12 +65,13 @@ void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...); .. your JNIEnv code here .. * - * 4) Detach thread from JVM, if required + * 4) Detach thread from JVM if required, i.e. not attached as daemon! + * Not recommended for recurring _daemon_ threads (performance) * - if (shallBeDetached) { - (*jvmHandle)->DetachCurrentThread(jvmHandle); - } + NativewindowCommon_ReleaseJNIEnv(shallBeDetached); */ -JNIEnv* NewtCommon_GetJNIEnv (JavaVM * jvmHandle, int jvmVersion, int asDaemon, int * shallBeDetached); +JNIEnv* NewtCommon_GetJNIEnv (int asDaemon, int * shallBeDetached); + +void NewtCommon_ReleaseJNIEnv (int shallBeDetached); #endif |