-
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathDevFlags.cpp
More file actions
38 lines (33 loc) · 980 Bytes
/
DevFlags.cpp
File metadata and controls
38 lines (33 loc) · 980 Bytes
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
// DevFlags.cpp
#include "DevFlags.h"
#include "JEnv.h"
#include <atomic>
#include <mutex>
namespace tns {
bool IsScriptLoadingLogEnabled() {
static std::atomic<int> cached{-1}; // -1 unknown, 0 false, 1 true
int v = cached.load(std::memory_order_acquire);
if (v != -1) {
return v == 1;
}
static std::once_flag initFlag;
std::call_once(initFlag, []() {
bool enabled = false;
try {
JEnv env;
jclass runtimeClass = env.FindClass("com/tns/Runtime");
if (runtimeClass != nullptr) {
jmethodID mid = env.GetStaticMethodID(runtimeClass, "getLogScriptLoadingEnabled", "()Z");
if (mid != nullptr) {
jboolean res = env.CallStaticBooleanMethod(runtimeClass, mid);
enabled = (res == JNI_TRUE);
}
}
} catch (...) {
// keep default false
}
cached.store(enabled ? 1 : 0, std::memory_order_release);
});
return cached.load(std::memory_order_acquire) == 1;
}
} // namespace tns