From b91f6d1e93465bb4b035b20922e45a7ac4c18467 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Sep 2018 10:02:01 -0700 Subject: [PATCH] Fabric: Using EventBeatBasedExecutor to ensure threading during installing UIManager Summary: This is the last step before making JSIUIManagerInstaller a direct dependency of UIManager (and making UIManager installation process completely seamless/platform-agnostic). Reviewed By: mdvacca Differential Revision: D9995781 fbshipit-source-id: 6f8c7177495b01ebaac1dbe330f49dce2e2a552c --- .../fabric/events/EventBeatBasedExecutor.cpp | 2 ++ .../fabric/uimanager/FabricUIManager.cpp | 19 ++++++++++++++----- .../fabric/uimanager/FabricUIManager.h | 8 +++++++- ReactCommon/fabric/uimanager/Scheduler.cpp | 8 ++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ReactCommon/fabric/events/EventBeatBasedExecutor.cpp b/ReactCommon/fabric/events/EventBeatBasedExecutor.cpp index 61607c68a4..13c15080a6 100644 --- a/ReactCommon/fabric/events/EventBeatBasedExecutor.cpp +++ b/ReactCommon/fabric/events/EventBeatBasedExecutor.cpp @@ -9,6 +9,8 @@ #include "EventBeatBasedExecutor.h" +#include + namespace facebook { namespace react { diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 1b1dd67d42..0101bed135 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -89,15 +89,24 @@ static const std::string componentNameByReactViewName(std::string viewName) { return viewName; } -FabricUIManager::FabricUIManager(std::function installer, std::function uninstaller): - installer_(std::move(installer)), - uninstaller_(std::move(uninstaller)) { + FabricUIManager::FabricUIManager( + std::unique_ptr executor, + std::function installer, + std::function uninstaller + ): + executor_(std::move(executor)), + installer_(std::move(installer)), + uninstaller_(std::move(uninstaller)) { - installer_(*this); + (*executor_)([this] { + installer_(*this); + }); } FabricUIManager::~FabricUIManager() { - uninstaller_(); + (*executor_)([this] { + uninstaller_(); + }, EventBeatBasedExecutor::Mode::Synchronous); } void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) { diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.h b/ReactCommon/fabric/uimanager/FabricUIManager.h index 5c561511c5..70ae482919 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.h +++ b/ReactCommon/fabric/uimanager/FabricUIManager.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -34,7 +35,11 @@ using DispatchEventToTargetFunction = void (const EventHandler &eventHandler, co class FabricUIManager { public: - FabricUIManager(std::function installer, std::function uninstaller); + FabricUIManager( + std::unique_ptr executor, + std::function installer, + std::function uninstaller + ); ~FabricUIManager(); #pragma mark - Native-facing Interface @@ -88,6 +93,7 @@ private: std::function dispatchEventToEmptyTargetFunction_; std::function dispatchEventToTargetFunction_; + std::unique_ptr executor_; std::function installer_; std::function uninstaller_; }; diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 020605cee9..aeb92eda04 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -18,7 +18,11 @@ namespace react { Scheduler::Scheduler(const SharedContextContainer &contextContainer): contextContainer_(contextContainer) { + const auto asynchronousEventBeatFactory = contextContainer->getInstance("asynchronous"); + const auto synchronousEventBeatFactory = contextContainer->getInstance("synchronous"); + uiManager_ = std::make_shared( + std::make_unique(asynchronousEventBeatFactory()), contextContainer->getInstance>("uimanager-installer"), contextContainer->getInstance>("uimanager-uninstaller") ); @@ -32,8 +36,8 @@ Scheduler::Scheduler(const SharedContextContainer &contextContainer): std::placeholders::_2, std::placeholders::_3 ), - contextContainer->getInstance("synchronous"), - contextContainer->getInstance("asynchronous") + synchronousEventBeatFactory, + asynchronousEventBeatFactory ); uiManager_->setComponentDescriptorRegistry(