Skip to content

Commit c5afd1a

Browse files
javachemeta-codesync[bot]
authored andcommitted
Use dispatch_semaphore for eager-main-queue module setup gate
Summary: Replace the `std::mutex` + `std::condition_variable` + `std::shared_ptr<bool>` trio that gates the JS thread on main-queue module construction with a single `dispatch_semaphore_t`. The wait block is invoked exactly once (from `_loadScriptFromSource:`'s `beforeLoad` lambda), so single-shot semaphore semantics fit the contract directly — no condition predicate, no shared state captured by three independent `shared_ptr`s. Net: 12 lines deleted, 1 captured object instead of 3, no behavior change. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D105953979 fbshipit-source-id: 149e959d04e8466589798ae38c68059db77ecd8b
1 parent d672c96 commit c5afd1a

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

  • packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,10 @@ - (void)_start
379379
*/
380380
NSArray<NSString *> *modulesRequiringMainQueueSetup = [_delegate unstableModulesRequiringMainQueueSetup];
381381

382-
std::shared_ptr<std::mutex> mutex = std::make_shared<std::mutex>();
383-
std::shared_ptr<std::condition_variable> cv = std::make_shared<std::condition_variable>();
384-
std::shared_ptr<bool> isReady = std::make_shared<bool>(false);
382+
dispatch_semaphore_t moduleSetupComplete = dispatch_semaphore_create(0);
385383

386384
_waitUntilModuleSetupComplete = ^{
387-
std::unique_lock<std::mutex> lock(*mutex);
388-
cv->wait(lock, [isReady] { return *isReady; });
385+
dispatch_semaphore_wait(moduleSetupComplete, DISPATCH_TIME_FOREVER);
389386
};
390387

391388
// TODO(T218039767): Integrate perf logging into main queue module init
@@ -398,9 +395,7 @@ - (void)_start
398395
RCTScreenScale();
399396
RCTSwitchSize();
400397

401-
std::lock_guard<std::mutex> lock(*mutex);
402-
*isReady = true;
403-
cv->notify_all();
398+
dispatch_semaphore_signal(moduleSetupComplete);
404399
});
405400
}
406401

0 commit comments

Comments
 (0)