Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Shuffle around #[inline] and #[cold] in mutex impl.
  • Loading branch information
m-ou-se committed Apr 1, 2022
commit 6392f1555e6515c59faa8393d1bf106b0c8872bd
12 changes: 7 additions & 5 deletions library/std/src/sys/unix/locks/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Mutex {
}
}

#[cold]
fn lock_contended(&self) {
// Spin first to speed things up if the lock is released quickly.
let mut state = self.spin();
Expand Down Expand Up @@ -91,9 +92,14 @@ impl Mutex {
// will mark the mutex as contended (2) (see lock_contended above),
// which makes sure that any other waiting threads will also be
// woken up eventually.
futex_wake(&self.futex);
self.wake();
}
}

#[cold]
fn wake(&self) {
futex_wake(&self.futex);
}
}

pub struct Condvar {
Expand All @@ -118,24 +124,20 @@ impl Condvar {
// All the memory orderings here are `Relaxed`,
// because synchronization is done by unlocking and locking the mutex.

#[inline]
pub unsafe fn notify_one(&self) {
self.futex.fetch_add(1, Relaxed);
futex_wake(&self.futex);
}

#[inline]
pub unsafe fn notify_all(&self) {
self.futex.fetch_add(1, Relaxed);
futex_wake_all(&self.futex);
}

#[inline]
pub unsafe fn wait(&self, mutex: &Mutex) {
self.wait_optional_timeout(mutex, None);
}

#[inline]
pub unsafe fn wait_timeout(&self, mutex: &Mutex, timeout: Duration) -> bool {
self.wait_optional_timeout(mutex, Some(timeout))
}
Expand Down