Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pin to pin RWLock. #77865

Closed
wants to merge 2 commits into from

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Oct 12, 2020

Use Pin to guarantee the no-moving requirement of sys_common::RWLock.

This makes some things safe that were unsafe before.

sys_common::RWLock::destroy is now changed to a regular (safe) Drop implementation, because it no longer has unsafe requirements.

This change leaves the unsafe sys::RwLock untouched. Those implementations should probably also use a Pin to make them a bit safer, and move their destroy() to Drop. But that can be a later change. (I want to wait for #77666 and #77657 before touching sys.)


r? @withoutboats

Following our conversation on Zulip, this is a better example where Pin<&Self> is useful.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2020
@m-ou-se m-ou-se marked this pull request as draft October 12, 2020 18:36
library/core/src/pin.rs Outdated Show resolved Hide resolved
library/core/src/pin.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Mar 10, 2021

☔ The latest upstream changes (presumably #82982) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 16, 2021

I want to wait for #77666 and #77657 before touching sys.

Both those PRs have been merged.

@jackh726 jackh726 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Dec 18, 2021
Comment on lines -82 to +78
/// Behavior is undefined if there are any currently active users of this
/// lock.
impl Drop for RWLock {
#[inline]
pub unsafe fn destroy(&self) {
self.0.destroy()
fn drop(&mut self) {
// SAFETY: The rwlock wasn't moved since using any of its
// functions, because they all require a Pin.
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this changing the safety preconditions? Previously there was something about "active users", which is no longer mentioned.

This seems related to #85434. The "no active users" condition is not actually upheld by the users of this code. So it makes sense to remove this comment here, but IMO then there should be a comment one layer down -- because there pthread_mutex_destroy is being called and the safety precondition does not ensure all that needs to be ensured. (Basically, this moves the "active users" comment instead of removing it entirely, and acknowledges that we have a gap in our safety reasoning here.)

@Dylan-DPC
Copy link
Member

@m-ou-se any updates on this?

@Dylan-DPC
Copy link
Member

Closing this due to inactivity.

@Dylan-DPC Dylan-DPC closed this Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants