未验证 提交 8bf1054d 编写于 作者: H haojun Liao 提交者: GitHub

Merge pull request #544 from localvar/fix-jni-init-race

fix race in jni initialization
......@@ -62,7 +62,14 @@ jmethodID g_rowdataSetByteArrayFp;
void jniGetGlobalMethod(JNIEnv *env) {
// make sure init function executed once
if (__sync_val_compare_and_swap_32(&__init, 0, 1) == 1) {
switch (__sync_val_compare_and_swap_32(&__init, 0, 1)) {
case 0:
break;
case 1:
do {
taosMsleep(0);
} while (__atomic_load_n(&__init, __ATOMIC_ACQUIRE) == 1);
case 2:
return;
}
......@@ -101,6 +108,7 @@ void jniGetGlobalMethod(JNIEnv *env) {
g_rowdataSetByteArrayFp = (*env)->GetMethodID(env, g_rowdataClass, "setByteArray", "(I[B)V");
(*env)->DeleteLocalRef(env, rowdataClass);
__atomic_store_n(&__init, 2, __ATOMIC_RELEASE);
jniTrace("native method register finished");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册