mirror of
https://github.com/LSPosed/LSPlant.git
synced 2025-05-04 20:42:02 +08:00
Add JNIMonitor
This commit is contained in:
parent
b0c3e27061
commit
2bd7051841
@ -96,12 +96,24 @@ class ScopedLocalRef<T>;
|
|||||||
class JNIScopeFrame {
|
class JNIScopeFrame {
|
||||||
JNIEnv *env_;
|
JNIEnv *env_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(JNIScopeFrame);
|
||||||
public:
|
public:
|
||||||
JNIScopeFrame(JNIEnv *env, jint size) : env_(env) { env_->PushLocalFrame(size); }
|
JNIScopeFrame(JNIEnv *env, jint size) : env_(env) { env_->PushLocalFrame(size); }
|
||||||
|
|
||||||
~JNIScopeFrame() { env_->PopLocalFrame(nullptr); }
|
~JNIScopeFrame() { env_->PopLocalFrame(nullptr); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class JNIMonitor {
|
||||||
|
JNIEnv *env_;
|
||||||
|
jobject obj_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(JNIMonitor);
|
||||||
|
public:
|
||||||
|
JNIMonitor(JNIEnv *env, jobject obj) : env_(env), obj_(obj) { env_->MonitorEnter(obj_); }
|
||||||
|
|
||||||
|
~JNIMonitor() { env_->MonitorExit(obj_); }
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
concept ScopeOrRaw = std::is_convertible_v<T, U> ||
|
concept ScopeOrRaw = std::is_convertible_v<T, U> ||
|
||||||
(is_instance_v<std::decay_t<T>, ScopedLocalRef>
|
(is_instance_v<std::decay_t<T>, ScopedLocalRef>
|
||||||
@ -902,7 +914,7 @@ public:
|
|||||||
|
|
||||||
explicit ScopedLocalRef(JNIEnv *env) noexcept : ScopedLocalRef(env, T{nullptr}) {}
|
explicit ScopedLocalRef(JNIEnv *env) noexcept : ScopedLocalRef(env, T{nullptr}) {}
|
||||||
|
|
||||||
~ScopedLocalRef() { release(); }
|
~ScopedLocalRef() { env_->DeleteLocalRef(release()); }
|
||||||
|
|
||||||
void reset(T ptr = nullptr) {
|
void reset(T ptr = nullptr) {
|
||||||
if (ptr != local_ref_) {
|
if (ptr != local_ref_) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user