From 8d3d8afa5b628e461299b33f1d35551d53ed4776 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 30 Mar 2020 19:32:46 -0700 Subject: [PATCH] Fabric: Using `executeSynchronouslyOnSameThread_CAN_DEADLOCK` in MainRunLoopEventBeat Summary: We are replacing inline-ed implementation with practically the same one implemented as the helper method. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20551409 fbshipit-source-id: fcc6f497cd240af65fba534051c217fe5746ce82 --- React/Fabric/Utils/MainRunLoopEventBeat.mm | 25 +--------------------- 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/React/Fabric/Utils/MainRunLoopEventBeat.mm b/React/Fabric/Utils/MainRunLoopEventBeat.mm index dab0e10810..563cebde21 100644 --- a/React/Fabric/Utils/MainRunLoopEventBeat.mm +++ b/React/Fabric/Utils/MainRunLoopEventBeat.mm @@ -58,30 +58,7 @@ void MainRunLoopEventBeat::lockExecutorAndBeat() const return; } - // Note: We need the third mutex to get back to the main thread before - // the lambda is finished (because all mutexes are allocated on the stack). - std::mutex mutex1; - std::mutex mutex2; - std::mutex mutex3; - - mutex1.lock(); - mutex2.lock(); - mutex3.lock(); - - jsi::Runtime *runtimePtr; - - runtimeExecutor_([&](jsi::Runtime &runtime) { - runtimePtr = &runtime; - mutex1.unlock(); - // `beat` is called somewhere here. - mutex2.lock(); - mutex3.unlock(); - }); - - mutex1.lock(); - beat(*runtimePtr); - mutex2.unlock(); - mutex3.lock(); + executeSynchronouslyOnSameThread_CAN_DEADLOCK(runtimeExecutor_, [this](jsi::Runtime &runtime) { beat(runtime); }); } } // namespace react