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
This commit is contained in:
Pieter De Baets authored and meta-codesync[bot] committed 2026-05-22 09:46:18 -07:00
1 parent d672c96445
commit c5afd1a204
1 file changed
+3 -8
@@ -379,13 +379,10 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
*/
NSArray<NSString *> *modulesRequiringMainQueueSetup = [_delegate unstableModulesRequiringMainQueueSetup];
std::shared_ptr<std::mutex> mutex = std::make_shared<std::mutex>();
std::shared_ptr<std::condition_variable> cv = std::make_shared<std::condition_variable>();
std::shared_ptr<bool> isReady = std::make_shared<bool>(false);
dispatch_semaphore_t moduleSetupComplete = dispatch_semaphore_create(0);
_waitUntilModuleSetupComplete = ^{
std::unique_lock<std::mutex> lock(*mutex);
cv->wait(lock, [isReady] { return *isReady; });
dispatch_semaphore_wait(moduleSetupComplete, DISPATCH_TIME_FOREVER);
};
// TODO(T218039767): Integrate perf logging into main queue module init
@@ -398,9 +395,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
RCTScreenScale();
RCTSwitchSize();
std::lock_guard<std::mutex> lock(*mutex);
*isReady = true;
cv->notify_all();
dispatch_semaphore_signal(moduleSetupComplete);
});
}