mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
b3930f935f
Summary:
See react_native_assert.{h,cpp}. Because of the BUCK+Android issue where NDEBUG is always defined, we use react_native_assert instead of assert to enable xplat asserts in debug/dev mode.
This migrates most of the codebase, but probably not 100%. The goal is to increase assertion coverage on Android, not to get to 100% (yet).
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D26562866
fbshipit-source-id: a7bf2055b973e1d3650ed8d68a6d02d556604af9
53 lines
1.3 KiB
C++
53 lines
1.3 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"
|
|
|
|
#include <react/debug/react_native_assert.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 {
|
|
react_native_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
|