diff options
| author | bors <bors@rust-lang.org> | 2022-06-19 08:20:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-19 08:20:36 +0000 |
| commit | 15fc228d0d0a68b5ba565758fab13ed7f863fcea (patch) | |
| tree | e7b2995928c0484ecc6c82a443a3533226aba222 /library/std/src/sys | |
| parent | 5fb8a3926619a18a2e31627e4cdf05f16530b0eb (diff) | |
| parent | edae4958556a6150841b9964b322d1e96e7a4586 (diff) | |
| download | rust-15fc228d0d0a68b5ba565758fab13ed7f863fcea.tar.gz rust-15fc228d0d0a68b5ba565758fab13ed7f863fcea.zip | |
Auto merge of #97791 - m-ou-se:const-locks, r=m-ou-se
Make {Mutex, Condvar, RwLock}::new() const.
This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉
Our implementations [on Linux](https://github.com/rust-lang/rust/pull/95035), [on Windows](https://github.com/rust-lang/rust/pull/77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of https://github.com/rust-lang/rust/pull/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: https://github.com/rust-lang/rust/issues/93740
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/itron/mutex.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/solid/rwlock.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/locks/condvar.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/locks/mutex.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/locks/rwlock.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/windows/locks/condvar.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/windows/locks/mutex.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/windows/locks/rwlock.rs | 1 |
8 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/sys/itron/mutex.rs b/library/std/src/sys/itron/mutex.rs index 2ba8454ff92..715e94c3b3d 100644 --- a/library/std/src/sys/itron/mutex.rs +++ b/library/std/src/sys/itron/mutex.rs @@ -26,6 +26,7 @@ fn new_mtx() -> Result<abi::ID, ItronError> { } impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { mtx: SpinIdOnceCell::new() } } diff --git a/library/std/src/sys/solid/rwlock.rs b/library/std/src/sys/solid/rwlock.rs index 433abc895f5..0a770cf03f2 100644 --- a/library/std/src/sys/solid/rwlock.rs +++ b/library/std/src/sys/solid/rwlock.rs @@ -23,6 +23,7 @@ fn new_rwl() -> Result<abi::ID, ItronError> { } impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { rwl: SpinIdOnceCell::new() } } diff --git a/library/std/src/sys/unsupported/locks/condvar.rs b/library/std/src/sys/unsupported/locks/condvar.rs index f27bf2b26bd..e703fd0d269 100644 --- a/library/std/src/sys/unsupported/locks/condvar.rs +++ b/library/std/src/sys/unsupported/locks/condvar.rs @@ -6,6 +6,7 @@ pub struct Condvar {} pub type MovableCondvar = Condvar; impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar {} } diff --git a/library/std/src/sys/unsupported/locks/mutex.rs b/library/std/src/sys/unsupported/locks/mutex.rs index 56bad71b189..d7cb12e0cf9 100644 --- a/library/std/src/sys/unsupported/locks/mutex.rs +++ b/library/std/src/sys/unsupported/locks/mutex.rs @@ -11,6 +11,7 @@ unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} // no threads on this platform impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { locked: Cell::new(false) } } diff --git a/library/std/src/sys/unsupported/locks/rwlock.rs b/library/std/src/sys/unsupported/locks/rwlock.rs index bf6e2d3d080..aca5fb7152c 100644 --- a/library/std/src/sys/unsupported/locks/rwlock.rs +++ b/library/std/src/sys/unsupported/locks/rwlock.rs @@ -11,6 +11,7 @@ unsafe impl Send for RwLock {} unsafe impl Sync for RwLock {} // no threads on this platform impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { mode: Cell::new(0) } } diff --git a/library/std/src/sys/windows/locks/condvar.rs b/library/std/src/sys/windows/locks/condvar.rs index 59e2c1be0f0..be9a2abbe35 100644 --- a/library/std/src/sys/windows/locks/condvar.rs +++ b/library/std/src/sys/windows/locks/condvar.rs @@ -14,6 +14,7 @@ unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar { inner: UnsafeCell::new(c::CONDITION_VARIABLE_INIT) } } diff --git a/library/std/src/sys/windows/locks/mutex.rs b/library/std/src/sys/windows/locks/mutex.rs index 08f55844a0e..f91e8f9f59a 100644 --- a/library/std/src/sys/windows/locks/mutex.rs +++ b/library/std/src/sys/windows/locks/mutex.rs @@ -33,6 +33,7 @@ pub unsafe fn raw(m: &Mutex) -> c::PSRWLOCK { } impl Mutex { + #[inline] pub const fn new() -> Mutex { Mutex { srwlock: UnsafeCell::new(c::SRWLOCK_INIT) } } diff --git a/library/std/src/sys/windows/locks/rwlock.rs b/library/std/src/sys/windows/locks/rwlock.rs index a32df85e2f6..fa5ffe5749f 100644 --- a/library/std/src/sys/windows/locks/rwlock.rs +++ b/library/std/src/sys/windows/locks/rwlock.rs @@ -11,6 +11,7 @@ unsafe impl Send for RwLock {} unsafe impl Sync for RwLock {} impl RwLock { + #[inline] pub const fn new() -> RwLock { RwLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) } } |
