Skip to content

Add data_ptr method to Mutex and RwLock #140369

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

jplatte
Copy link
Contributor

@jplatte jplatte commented Apr 27, 2025

Implementation of #140368 / rust-lang/libs-team#531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

  • Return a LockResult or not?
  • Return *mut T like existing APIs (Cell::as_ptr / MaybeUninit::as[_mut]_ptr / Vec::as_ptr / ...) or be more precise and return NonNull<T>?

@rustbot
Copy link
Collaborator

rustbot commented Apr 27, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 27, 2025
@tgross35
Copy link
Contributor

This seems fine to me, but libs-api didn't specify an exact API so I'll ask them to review.

r? @Amanieu

@Amanieu
Copy link
Member

Amanieu commented May 19, 2025

Can you add this for ReentrantLock as well?

Also add a sentence to the docs saying that you are responsible for ensuring that accesses to the data are synchronized properly.

@rustbot

This comment has been minimized.

@jplatte jplatte force-pushed the mutex-rwlock-data-ptr branch from e9bc1d1 to 20589bd Compare May 21, 2025 06:07
@jplatte
Copy link
Contributor Author

jplatte commented May 21, 2025

I wasn't previously familiar with the unstable ReentrantLock. It looks like it doesn't directly allow writes so I've made the data_ptr method return *const T and made its docs only talk about reads, not writes.

Do you have any comments about the unresolved questions?

@Amanieu
Copy link
Member

Amanieu commented May 26, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 26, 2025

📌 Commit 20589bd has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2025
bors added a commit that referenced this pull request May 27, 2025
Add data_ptr method to Mutex and RwLock

Implementation of #140368 / rust-lang/libs-team#531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
@bors
Copy link
Collaborator

bors commented May 27, 2025

⌛ Testing commit 20589bd with merge 2c9990b...

@bors
Copy link
Collaborator

bors commented May 27, 2025

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 27, 2025
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@tgross35
Copy link
Contributor

No reason for this to time out.

@bors retry

@jplatte these could use example doctests at some point, feel free to either add them here or in a follow up.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 28, 2025
tgross35 added a commit to tgross35/rust that referenced this pull request May 28, 2025
…manieu

Add data_ptr method to Mutex and RwLock

Implementation of rust-lang#140368 / rust-lang/libs-team#531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141407 (Refactor the two-phase check for impls and impl items)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request May 28, 2025
…manieu

Add data_ptr method to Mutex and RwLock

Implementation of rust-lang#140368 / rust-lang/libs-team#531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141407 (Refactor the two-phase check for impls and impl items)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request May 28, 2025
Rollup of 7 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5f17779 into rust-lang:master May 28, 2025
6 of 7 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 28, 2025
rust-timer added a commit that referenced this pull request May 28, 2025
Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=Amanieu

Add data_ptr method to Mutex and RwLock

Implementation of #140368 / rust-lang/libs-team#531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
@jplatte jplatte deleted the mutex-rwlock-data-ptr branch May 28, 2025 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants