Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ CommitStatus ShadowTree::tryCommit(
newRootShadowNode = delegate_.shadowTreeWillCommit(
*this, oldRootShadowNode, newRootShadowNode);

if (!newRootShadowNode ||
(commitOptions.shouldYield && commitOptions.shouldYield())) {
return CommitStatus::Cancelled;
}

// Layout nodes.
std::vector<LayoutableShadowNode const *> affectedLayoutableNodes{};
affectedLayoutableNodes.reserve(1024);
Expand All @@ -368,17 +373,16 @@ CommitStatus ShadowTree::tryCommit(
// Updating `currentRevision_` in unique manner if it hasn't changed.
std::unique_lock lock(commitMutex_);

if (commitOptions.shouldYield && commitOptions.shouldYield()) {
return CommitStatus::Cancelled;
}

if (currentRevision_.number != oldRevision.number) {
return CommitStatus::Failed;
}

auto newRevisionNumber = oldRevision.number + 1;

if (!newRootShadowNode ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to remove the !newRootShadowNode check from here because we already checked it in the new block you added, but I think we should keep the rest. Layout is relatively slow so it could happen that the commit is requested to yield during layout, and we should still be able to cancel then. Changing this behavior without testing its impact would be risky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing.

By the way, what do you think about restoring that block with moving it just after getting a lock and before checking for revision numbers' mismatch? It may allow developers to cancel commit instead of getting failure on specific cases and shouldn't cause any behaviour changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed suggested changes, @rubennorte give me a shout about your opinion on that approach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that makes sense! thanks!

(commitOptions.shouldYield && commitOptions.shouldYield())) {
return CommitStatus::Cancelled;
}

{
std::lock_guard<std::mutex> dispatchLock(EventEmitter::DispatchMutex());

Expand Down