-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Lazily allocate and initialize pthread locks. #97647
Conversation
72b67ce
to
6d2c27d
Compare
_phantom: PhantomData<T>, | ||
} | ||
|
||
pub(crate) unsafe trait LazyInit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
unsafe fn init(&mut self); | ||
/// This is called before deallocating the box, with the same address for | ||
/// `self` as used in `init()`. | ||
unsafe fn destroy(&mut self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is destroy
still needed? Can't we just use the Drop
impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
destroy
still needed? Can't we just use theDrop
impl?
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 static
s, which don't get dropped anyway. So moving this to a Drop impl should work now.
How about just making |
At that point, why both with a trait? Just have |
Because that |
@bors r+ Looking forward to finally making |
📌 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#93740
Rollup 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#93740
Hermit: Fix initializing lazy locks Closes hermit-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 Closes hermit-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#93740
Hermit: Fix initializing lazy locks Closes hermit-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