Skip to content

Commit

Permalink
Synchronize access to LongLivedObjectCollection instances (facebook#4…
Browse files Browse the repository at this point in the history
…3450)

Summary:
Pull Request resolved: facebook#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
  • Loading branch information
fabriziocucci authored and facebook-github-bot committed Mar 12, 2024
1 parent eef87ca commit 41b6371
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 41b6371

Please sign in to comment.