src/core/android/SDL_android.c
changeset 8055 3e2f230a6d62
parent 8047 a5270cef21a7
child 8057 801d84e26f91
     1.1 --- a/src/core/android/SDL_android.c	Fri Dec 06 16:12:18 2013 -0800
     1.2 +++ b/src/core/android/SDL_android.c	Sat Dec 07 11:19:52 2013 -0800
     1.3 @@ -98,12 +98,10 @@
     1.4       * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
     1.5       * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
     1.6       */
     1.7 -    if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed)) {
     1.8 +    if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed) != 0) {
     1.9          __android_log_print(ANDROID_LOG_ERROR, "SDL", "Error initializing pthread key");
    1.10      }
    1.11 -    else {
    1.12 -        Android_JNI_SetupThread();
    1.13 -    }
    1.14 +    Android_JNI_SetupThread();
    1.15  
    1.16      return JNI_VERSION_1_4;
    1.17  }
    1.18 @@ -454,7 +452,8 @@
    1.19      return retval;
    1.20  }
    1.21  
    1.22 -static void Android_JNI_ThreadDestroyed(void* value) {
    1.23 +static void Android_JNI_ThreadDestroyed(void* value)
    1.24 +{
    1.25      /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
    1.26      JNIEnv *env = (JNIEnv*) value;
    1.27      if (env != NULL) {
    1.28 @@ -463,7 +462,8 @@
    1.29      }
    1.30  }
    1.31  
    1.32 -JNIEnv* Android_JNI_GetEnv(void) {
    1.33 +JNIEnv* Android_JNI_GetEnv(void)
    1.34 +{
    1.35      /* From http://developer.android.com/guide/practices/jni.html
    1.36       * All threads are Linux threads, scheduled by the kernel.
    1.37       * They're usually started from managed code (using Thread.start), but they can also be created elsewhere and then
    1.38 @@ -483,10 +483,6 @@
    1.39          return 0;
    1.40      }
    1.41  
    1.42 -    return env;
    1.43 -}
    1.44 -
    1.45 -int Android_JNI_SetupThread(void) {
    1.46      /* From http://developer.android.com/guide/practices/jni.html
    1.47       * Threads attached through JNI must call DetachCurrentThread before they exit. If coding this directly is awkward,
    1.48       * in Android 2.0 (Eclair) and higher you can use pthread_key_create to define a destructor function that will be
    1.49 @@ -496,8 +492,14 @@
    1.50       * Note: You can call this function any number of times for the same thread, there's no harm in it
    1.51       *       (except for some lost CPU cycles)
    1.52       */
    1.53 -    JNIEnv *env = Android_JNI_GetEnv();
    1.54      pthread_setspecific(mThreadKey, (void*) env);
    1.55 +
    1.56 +    return env;
    1.57 +}
    1.58 +
    1.59 +int Android_JNI_SetupThread(void)
    1.60 +{
    1.61 +    Android_JNI_GetEnv();
    1.62      return 1;
    1.63  }
    1.64