diff options
author | 2024-03-13 19:34:52 +0000 | |
---|---|---|
committer | 2024-03-13 19:34:52 +0000 | |
commit | 2ecfdb1d2dd832c637aacfa15c257822b94f10b1 (patch) | |
tree | 168eaae29b69167fde082c06f11987d3f3870992 | |
parent | ff8a5a36732e914d3f56b9a1f87bcae856d1da94 (diff) | |
parent | 223e0a03c3ed055b70ed94ee24a762a2746e54c6 (diff) |
Merge "SoundPool: never-delete singleton to avoid exit race" into main
-rw-r--r-- | media/jni/soundpool/android_media_SoundPool.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/media/jni/soundpool/android_media_SoundPool.cpp b/media/jni/soundpool/android_media_SoundPool.cpp index 25040a942061..e872a58c96cf 100644 --- a/media/jni/soundpool/android_media_SoundPool.cpp +++ b/media/jni/soundpool/android_media_SoundPool.cpp @@ -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 |