From 20f1f62d9b5a2eee0c845da63db7670f29f8809e Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 12 Mar 2024 10:44:37 -0700 Subject: [PATCH] Synchronize access to LongLivedObjectCollection instances Summary: 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 --- .../ReactCommon/react/bridging/LongLivedObject.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native/ReactCommon/react/bridging/LongLivedObject.cpp b/packages/react-native/ReactCommon/react/bridging/LongLivedObject.cpp index 64a93c1b7ec5..9c6d7c38d86f 100644 --- a/packages/react-native/ReactCommon/react/bridging/LongLivedObject.cpp +++ b/packages/react-native/ReactCommon/react/bridging/LongLivedObject.cpp @@ -16,6 +16,9 @@ LongLivedObjectCollection& LongLivedObjectCollection::get( jsi::Runtime& runtime) { static std::unordered_map> instances; + static std::mutex instancesMutex; + + std::scoped_lock lock(instancesMutex); void* key = static_cast(&runtime); auto entry = instances.find(key); if (entry == instances.end()) {