Background Executor: only cancel commit if it is for the same surface

Summary:
Changelog: [internal]

In theory, a commit from different surface could cancel a commit for unrelated surface. Adding surfaceId to cancellation logic assures this doesn't happen.

Reviewed By: shergin

Differential Revision: D26126003

fbshipit-source-id: 15b9b73f1000a2b4ae882e0a5129fe26fbb53fd2
This commit is contained in:
Samuel Susla
2021-01-28 12:40:11 -08:00
committed by Facebook GitHub Bot
parent d5a1bbe64a
commit f92cc5ba77
@@ -453,17 +453,17 @@ jsi::Value UIManagerBinding::get(
auto shadowNodeList =
shadowNodeListFromValue(runtime, arguments[1]);
static std::atomic_uint_fast8_t completeRootEventCounter{0};
static std::atomic_uint_fast32_t mostRecentSurfaceId{0};
completeRootEventCounter += 1;
mostRecentSurfaceId = surfaceId;
sharedUIManager->backgroundExecutor_(
[sharedUIManager,
surfaceId,
shadowNodeList,
eventCount = completeRootEventCounter.load()] {
auto shouldCancel = [eventCount]() -> bool {
[=, eventCount = completeRootEventCounter.load()] {
auto shouldCancel = [=]() -> bool {
// If `completeRootEventCounter` was incremented, another
// `completeSurface` call has been scheduled and current
// `completeSurface` should be cancelled.
return completeRootEventCounter > eventCount;
return completeRootEventCounter > eventCount &&
mostRecentSurfaceId == surfaceId;
};
sharedUIManager->completeSurface(
surfaceId, shadowNodeList, {true, shouldCancel});