Synchronize access to LongLivedObjectCollection instances (#43450)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43450

Changelog: [Internal]

This is just to make sure that all instances of `LongLivedObjectCollection` map can be safely accessed by multiple threads.

Reviewed By: RSNara

Differential Revision: D54801015

fbshipit-source-id: e0b15bfbeac9ce3a1051f83a59c5513a90ba2a4b
This commit is contained in:
Fabrizio Cucci
2024-03-12 13:18:25 -07:00
committed by Facebook GitHub Bot
parent eef87ca59e
commit 41b6371940
@@ -16,6 +16,9 @@ LongLivedObjectCollection& LongLivedObjectCollection::get(
jsi::Runtime& runtime) {
static std::unordered_map<void*, std::shared_ptr<LongLivedObjectCollection>>
instances;
static std::mutex instancesMutex;
std::scoped_lock lock(instancesMutex);
void* key = static_cast<void*>(&runtime);
auto entry = instances.find(key);
if (entry == instances.end()) {