Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ecfdb1d authored by Andy Hung's avatar Andy Hung Committed by Gerrit Code Review
Browse files

Merge "SoundPool: never-delete singleton to avoid exit race" into main

parents ff8a5a36 223e0a03
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ public:
    }

    // Retrieves the associated object, returns nullValue T if not available.
    T get(JNIEnv *env, jobject thiz) {
    T get(JNIEnv *env, jobject thiz) const {
        std::lock_guard lg(mLock);
        // NOLINTNEXTLINE(performance-no-int-to-ptr)
        auto ptr = reinterpret_cast<T*>(env->GetLongField(thiz, mFieldId));
@@ -167,8 +167,10 @@ private:
//    is possible by checking if the WeakGlobalRef is null equivalent.

auto& getSoundPoolManager() {
    static ObjectManager<std::shared_ptr<SoundPool>> soundPoolManager(fields.mNativeContext);
    return soundPoolManager;
    // never-delete singleton
    static auto soundPoolManager =
            new ObjectManager<std::shared_ptr<SoundPool>>(fields.mNativeContext);
    return *soundPoolManager;
}

inline auto getSoundPool(JNIEnv *env, jobject thiz) {
@@ -274,8 +276,9 @@ static_assert(std::is_same_v<JWeakValue*, jweak>);
auto& getSoundPoolJavaRefManager() {
    // Note this can store shared_ptrs to either jweak and jobject,
    // as the underlying type is identical.
    static ConcurrentHashMap<SoundPool *, std::shared_ptr<JWeakValue>> concurrentHashMap;
    return concurrentHashMap;
    static auto concurrentHashMap =
            new ConcurrentHashMap<SoundPool *, std::shared_ptr<JWeakValue>>();
    return *concurrentHashMap;
}

// make_shared_globalref_from_localref() creates a sharable Java global