Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

client/finality-grandpa/src/until_imported: Refactor BlockGlobalMessage #5390

Merged
merged 4 commits into from
Mar 25, 2020

Conversation

mxinden
Copy link
Contributor

@mxinden mxinden commented Mar 24, 2020

BlockGlobalMessage owns an inner which contains (1) a count for the
amount of outstanding blocks to be waited on and (2) the message itself.

Given that both is already wrapped in an Arc there is no need to keep
track of the outstanding blocks, given that it simply corresponds to the
amount of strong reference counts on the Arc itself.

This commit removes the atomic counter within inner and piggy backs on
the Arc reference counter instead.


On the one hand this reduces the amount of complexity given that there is no need to update the blocks-to-be-awaited counter anymore, on the other hand it makes the blocks-to-be-awaited counting implicit instead of explicit. Let me know what you think.

`BlockGlobalMessage` owns an `inner` which contains (1) a count for the
amount of outstanding blocks to be waited on and (2) the message itself.

Given that both is already wrapped in an `Arc` there is no need to keep
track of the outstanding blocks, given that it simply corresponds to the
amount of strong reference counts on the `Arc` itself.

This commit removes the atomic counter within `inner` and piggy backs on
the `Arc` reference counter instead.
@mxinden mxinden added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes labels Mar 24, 2020
return None;
}

let mut last_count = self.inner.0.load(Ordering::Acquire);

// CAS loop to ensure that we always have a last reader.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case we decide against this, we should at least replace this CAS loop with a single fetch_sub call.

}
match Arc::try_unwrap(self.inner) {
// This is the last reference, thus this was the last outstanding block to be awaited.
Ok(inner) => match Mutex::into_inner(inner) {
Copy link
Member

Choose a reason for hiding this comment

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

This match doesn't makes any sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. At first I thought this would make it more explicit. Removed it and improved comment above it instead.

@mxinden
Copy link
Contributor Author

mxinden commented Mar 25, 2020

Thanks for the review @bkchr. Would you mind taking another look?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants