Background Executor: Move complete root event counting to static variable

Summary:
Changelog: [internal]

This simplifies logic, there is no need to keep the counter as an ivar of UIManager.

Reviewed By: JoshuaGross, shergin

Differential Revision: D26125928

fbshipit-source-id: bd266586463a9f9b85d6dc189cdab19f79e3d107
This commit is contained in:
Samuel Susla
2021-01-28 12:40:11 -08:00
committed by Facebook GitHub Bot
parent 5dc15222b2
commit d5a1bbe64a
2 changed files with 6 additions and 14 deletions
@@ -167,12 +167,6 @@ class UIManager final : public ShadowTreeDelegate {
ShadowTreeRegistry shadowTreeRegistry_{};
BackgroundExecutor backgroundExecutor_{};
// Used only when BackgroundExecutor is enabled.
// Property is used to keep count of `completeRoot` events to
// determine whether a commit should be cancelled. Only to be used
// inside UIManagerBinding.
std::atomic_uint_fast8_t completeRootEventCounter_{0};
mutable better::shared_mutex commitHookMutex_;
mutable std::vector<UIManagerCommitHook const *> commitHooks_;
@@ -452,20 +452,18 @@ jsi::Value UIManagerBinding::get(
auto surfaceId = surfaceIdFromValue(runtime, arguments[0]);
auto shadowNodeList =
shadowNodeListFromValue(runtime, arguments[1]);
sharedUIManager->completeRootEventCounter_ += 1;
static std::atomic_uint_fast8_t completeRootEventCounter{0};
completeRootEventCounter += 1;
sharedUIManager->backgroundExecutor_(
[sharedUIManager,
surfaceId,
shadowNodeList,
eventCount =
sharedUIManager->completeRootEventCounter_.load()] {
auto shouldCancel = [eventCount, sharedUIManager]() -> bool {
// If `eventCounter_` was incremented, another
eventCount = completeRootEventCounter.load()] {
auto shouldCancel = [eventCount]() -> bool {
// If `completeRootEventCounter` was incremented, another
// `completeSurface` call has been scheduled and current
// `completeSurface` should be cancelled.
return sharedUIManager->completeRootEventCounter_ >
eventCount;
return completeRootEventCounter > eventCount;
};
sharedUIManager->completeSurface(
surfaceId, shadowNodeList, {true, shouldCancel});