aboutsummaryrefslogtreecommitdiffstats
path: root/sample-java/src/main/cpp/ComputeInNativeProxy.cpp
blob: 9f71224ce1d0ce892b80dce0102e94e04e542889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * File generated by Jenny -- https://github.com/LanderlYoung/Jenny
 *
 * DO NOT EDIT THIS FILE.
 *
 * For bug report, please refer to github issue tracker https://github.com/LanderlYoung/Jenny/issues,
 * or contact author landerlyoung@gmail.com.
 */
#include "ComputeInNativeProxy.h"


jclass ComputeInNativeProxy::sClazz = nullptr;

// thread safe init
std::mutex ComputeInNativeProxy::sInitLock;
std::atomic_bool ComputeInNativeProxy::sInited;

/*static*/ bool ComputeInNativeProxy::initClazz(JNIEnv *env) {
#define JENNY_CHECK_NULL(val)                      \
       do {                                        \
           if ((val) == nullptr) {                 \
               return false;                       \
           }                                       \
       } while(false)

    if (!sInited) {
        std::lock_guard<std::mutex> lg(sInitLock);
        if (!sInited) {
            auto clazz = env->FindClass(FULL_CLASS_NAME);
            JENNY_CHECK_NULL(clazz);
            sClazz = reinterpret_cast<jclass>(env->NewGlobalRef(clazz));
            env->DeleteLocalRef(clazz);
            JENNY_CHECK_NULL(sClazz);



            sField_nativeContext_0 = env->GetFieldID(sClazz, "nativeContext", "J");
            JENNY_CHECK_NULL(sField_nativeContext_0);


            sInited = true;
        }
    }
#undef JENNY_CHECK_NULL
   return true;
}

/*static*/ void ComputeInNativeProxy::releaseClazz(JNIEnv *env) {
    if (sInited) {
        std::lock_guard<std::mutex> lg(sInitLock);
        if (sInited) {
            env->DeleteLocalRef(sClazz);
            sInited = false;
        }
    }
}



jfieldID ComputeInNativeProxy::sField_nativeContext_0;