summaryrefslogtreecommitdiff
path: root/platform/android/src/jni/generic_global_ref_deleter.hpp
blob: 4e53e0a0ce96cd229c25ed969f8181952d259be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once

#include <jni/jni.hpp>

#include "../attach_env.hpp"

namespace mbgl {
namespace android {

// A deleter that doesn't retain an JNIEnv handle but instead tries to attach the JVM. This means
// it can be used on any thread to delete a global ref.
struct GenericGlobalRefDeleter {
    void operator()(jni::jobject* p) const {
        if (p) {
            auto env = AttachEnv();
            env->DeleteGlobalRef(jni::Unwrap(p));
        }
    }
};

} // namespace android
} // namespace mbgl