[vlc-devel] [PATCH] MediaCodec: simplify jni thread attach/detach
Zhang Rui
bbcallen at gmail.com
Wed Feb 26 05:40:28 CET 2014
2014-02-25 23:49 GMT+08:00 Rémi Denis-Courmont <remi at remlab.net>:
> On Tue, 25 Feb 2014 17:02:13 +0800, Zhang Rui <bbcallen at gmail.com> wrote:
>> +static void vlcjni_thread_destroy(void* value)
>> +{
>> + JNIEnv *env = (JNIEnv*) value;
>> + if (env != NULL) {
>
> Tautology, I believe.
OK
>
>> + (*myVm)->DetachCurrentThread(myVm);
>> + pthread_setspecific(g_thread_key, NULL);
>> + }
>> +}
>> +
>> +static void vlcjni_make_thread_key()
>
> Missing void.
>
>> +{
>> + pthread_key_create(&g_thread_key, vlcjni_thread_destroy);
>> +}
>
> This may be theoretical so far. But technically that is a leak and a
> potentially dangling clean-up handler callback.
>
>> +
>> +static jint vlcjni_setup_thread_env(JNIEnv **p_env)
>> +{
>> + JavaVM *jvm = myVm;
>> + if (!jvm)
>> + return -1;
>> +
>> + pthread_once(&g_key_once, vlcjni_make_thread_key);
>> +
>> + JNIEnv *env = (JNIEnv*) pthread_getspecific(g_thread_key);
>> + if (env) {
>> + *p_env = env;
>> + return 0;
>> + }
>> +
>> + static JavaVMAttachArgs vlc_thr_args = {JNI_VERSION_1_2,
>> "MediaCodec", NULL};
>
> Not reentrant.
>
>> + if ((*jvm)->AttachCurrentThread(jvm, &env, &vlc_thr_args) ==
> JNI_OK) {
>> + pthread_setspecific(g_thread_key, env);
>> + *p_env = env;
>> + return 0;
>> + }
>> +
>> + return -1;
>> +}
>> +
>>
> /*****************************************************************************
>> * OpenDecoder: Create the decoder instance
>>
> *****************************************************************************/
>
> --
> Rémi Denis-Courmont
> Sent from my collocated server
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list