Uh oh!
There was an error while loading. Please reload this page.
Lazily allocate and initialize pthread locks. - #97647
Conversation
Uh oh!
There was an error while loading. Please reload this page.
72b67ce to
6d2c27dCompareThere was a problem hiding this comment.
I had to make this trait pub(crate) instead of pub, otherwise rustc will start suggesting to implement std::sys_common::lazy_box::LazyInit every time a user tries to call a non-existent new function. And due to it being a bound on LazyBox, the change from pub to pub(crate) went a bit viral through std::sys.
See #95080
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Why is destroy still needed? Can't we just use the Drop impl?
There was a problem hiding this comment.
Why is
destroystill needed? Can't we just use theDropimpl?
That's a leftover from the very weird interface of sys's Mutex: init() and destroy() are "optional".
Since #77147, however, the only cases where destroy() is not called are for statics, which don't get dropped anyway. So moving this to a Drop impl should work now.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nbdd0121
commented
Jun 2, 2022
How about just making |
Amanieu
commented
Jun 2, 2022
At that point, why both with a trait? Just have |
m-ou-se
commented
Jun 3, 2022
Because that |
Amanieu
commented
Jun 3, 2022
@bors r+ Looking forward to finally making |
bors
commented
Jun 3, 2022
📌 Commit 6a417d4 has been approved by |
Lazily allocate and initialize pthread locks.
Lazily allocate and initialize pthread locks.
This allows {Mutex, Condvar, RwLock}::new() to be const, while still using the platform's native locks for features like priority inheritance and debug tooling. E.g. on macOS, we cannot directly use the (private) APIs that pthread's locks are implemented with, making it impossible for us to use anything other than pthread while still preserving priority inheritance, etc.
This PR doesn't yet make the public APIs const. That's for a separate PR with an FCP.
Tracking issue: rust-lang#93740Rollup of 5 pull requests Successful merges: - rust-lang#96642 (Avoid zero-sized allocs in ThinBox if T and H are both ZSTs.) - rust-lang#97647 (Lazily allocate and initialize pthread locks.) - rust-lang#97715 (Support the `#[expect]` attribute on fn parameters (RFC-2383)) - rust-lang#97716 (Fix reachability analysis for const methods) - rust-lang#97722 (Tighten spans for bad fields in struct deriving `Copy`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Make {Mutex, Condvar, RwLock}::new() const.
This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉
Our implementations [on Linux](rust-lang#95035), [on Windows](rust-lang#77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of rust-lang#97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const.
Tracking issue: rust-lang#93740Hermit: Fix initializing lazy locks Closeshermit-os/hermit-rs#322. The initialization function of hermit's `Condvar` is not called since rust-lang#97647 and was erroneously removed in rust-lang#97879. r? `@m-ou-se` CC: `@stlankes`
Hermit: Fix initializing lazy locks Closeshermit-os/hermit-rs#322. The initialization function of hermit's `Condvar` is not called since rust-lang#97647 and was erroneously removed in rust-lang#97879. r? ``@m-ou-se`` CC: ``@stlankes``
Make {Mutex, Condvar, RwLock}::new() const.
This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉
Our implementations [on Linux](rust-lang/rust#95035), [on Windows](rust-lang/rust#77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of rust-lang/rust#97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const.
Tracking issue: rust-lang/rust#93740Hermit: Fix initializing lazy locks Closeshermit-os/hermit-rs#322. The initialization function of hermit's `Condvar` is not called since rust-lang/rust#97647 and was erroneously removed in rust-lang/rust#97879. r? ``@m-ou-se`` CC: ``@stlankes``
Lazily allocate and initialize pthread locks.
This allows {Mutex, Condvar, RwLock}::new() to be const, while still using the platform's native locks for features like priority inheritance and debug tooling. E.g. on macOS, we cannot directly use the (private) APIs that pthread's locks are implemented with, making it impossible for us to use anything other than pthread while still preserving priority inheritance, etc.
This PR doesn't yet make the public APIs const. That's for a separate PR with an FCP.
Tracking issue: #93740