Skip to content

Commit

Permalink
Make all {Mutex, Condvar, RwLock}::new #[inline].
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Jun 6, 2022
1 parent e70c60d commit acc3ab4
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion library/std/src/sync/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ impl Condvar {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
pub fn new() -> Condvar {
#[inline]
pub const fn new() -> Condvar {
Condvar { inner: sys::Condvar::new() }
}

Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ impl<T> Mutex<T> {
/// let mutex = Mutex::new(0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(t: T) -> Mutex<T> {
#[inline]
pub const fn new(t: T) -> Mutex<T> {
Mutex {
inner: sys::MovableMutex::new(),
poison: poison::Flag::new(),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Flag {
// all cases.

impl Flag {
#[inline]
pub const fn new() -> Flag {
Flag { failed: AtomicBool::new(false) }
}
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ impl<T> RwLock<T> {
/// let lock = RwLock::new(5);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(t: T) -> RwLock<T> {
#[inline]
pub const fn new(t: T) -> RwLock<T> {
RwLock {
inner: sys::MovableRwLock::new(),
poison: poison::Flag::new(),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/itron/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn new_mtx() -> Result<abi::ID, ItronError> {
}

impl Mutex {
#[inline]
pub const fn new() -> Mutex {
Mutex { mtx: SpinIdOnceCell::new() }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/solid/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn new_rwl() -> Result<abi::ID, ItronError> {
}

impl RwLock {
#[inline]
pub const fn new() -> RwLock {
RwLock { rwl: SpinIdOnceCell::new() }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unsupported/locks/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Condvar {}
pub type MovableCondvar = Condvar;

impl Condvar {
#[inline]
pub const fn new() -> Condvar {
Condvar {}
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unsupported/locks/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unsupported/locks/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/windows/locks/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/windows/locks/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/windows/locks/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys_common/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub struct Condvar {

impl Condvar {
/// Creates a new condition variable for use.
pub fn new() -> Self {
#[inline]
pub const fn new() -> Self {
Self { inner: imp::MovableCondvar::new(), check: CondvarCheck::new() }
}

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys_common/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ unsafe impl Sync for StaticMutex {}

impl StaticMutex {
/// Creates a new mutex for use.
#[inline]
pub const fn new() -> Self {
Self(imp::Mutex::new())
}
Expand Down Expand Up @@ -60,6 +61,7 @@ unsafe impl Sync for MovableMutex {}

impl MovableMutex {
/// Creates a new mutex.
#[inline]
pub fn new() -> Self {
Self(imp::MovableMutex::new())
}
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys_common/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct StaticRwLock(imp::RwLock);

impl StaticRwLock {
/// Creates a new rwlock for use.
#[inline]
pub const fn new() -> Self {
Self(imp::RwLock::new())
}
Expand Down Expand Up @@ -73,6 +74,7 @@ pub struct MovableRwLock(imp::MovableRwLock);

impl MovableRwLock {
/// Creates a new reader-writer lock for use.
#[inline]
pub fn new() -> Self {
Self(imp::MovableRwLock::new())
}
Expand Down

0 comments on commit acc3ab4

Please sign in to comment.