Skip to content
Snippets Groups Projects
Commit 223e0a03 authored by Andy Hung's avatar Andy Hung
Browse files

SoundPool: never-delete singleton to avoid exit race

Test: atest SoundPoolOggTest SoundPoolAacTest SoundPoolMidiTest SoundPoolHapticTest
Bug: 316799609
Merged-In: I5b278960207d1b2c9fa80bbc57b2e15dd4498f13
Change-Id: I5b278960207d1b2c9fa80bbc57b2e15dd4498f13
parent ff8a5a36
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment