Files
react-native/ReactCommon/react/renderer/scheduler/SynchronousEventBeat.cpp
T
empyrical fcfa4309f7 Fabric: Replace #import statement in SynchronousEventBeat (#29885)
Summary:
This function replaces the usage of an Objective-C `#import` statement with `#include` in `react/renderer/scheduler/SynchronousEventBeat.cpp`.

Clang seems to have no problems with `#import` being used in CPP files, but it was causing errors in MSVC. ([it has a different purpose](https://docs.microsoft.com/en-us/cpp/preprocessor/hash-import-directive-cpp?view=vs-2019) on Windows)

## Changelog

Changelog: [Internal][Changed] - Fabric: Replace #import statement in SynchronousEventBeat

Pull Request resolved: https://github.com/facebook/react-native/pull/29885

Test Plan: This CPP file now compiles in MSVC

Reviewed By: sammy-SC

Differential Revision: D23591933

Pulled By: shergin

fbshipit-source-id: ee2cb8152f37e5ee09500af621a57b59d5a18400
2020-09-11 14:51:00 -07:00

51 lines
1.2 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "SynchronousEventBeat.h"
namespace facebook {
namespace react {
SynchronousEventBeat::SynchronousEventBeat(
RunLoopObserver::Unique uiRunLoopObserver,
RuntimeExecutor runtimeExecutor)
: EventBeat({}),
uiRunLoopObserver_(std::move(uiRunLoopObserver)),
runtimeExecutor_(std::move(runtimeExecutor)) {
uiRunLoopObserver_->setDelegate(this);
uiRunLoopObserver_->enable();
}
void SynchronousEventBeat::activityDidChange(
RunLoopObserver::Delegate const *delegate,
RunLoopObserver::Activity activity) const noexcept {
assert(delegate == this);
lockExecutorAndBeat();
}
void SynchronousEventBeat::induce() const {
if (!this->isRequested_) {
return;
}
if (uiRunLoopObserver_->isOnRunLoopThread()) {
this->lockExecutorAndBeat();
}
}
void SynchronousEventBeat::lockExecutorAndBeat() const {
if (!this->isRequested_) {
return;
}
executeSynchronouslyOnSameThread_CAN_DEADLOCK(
runtimeExecutor_, [this](jsi::Runtime &runtime) { beat(runtime); });
}
} // namespace react
} // namespace facebook