about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-17 02:32:14 +0000
committerbors <bors@rust-lang.org>2022-06-17 02:32:14 +0000
commit3cf1275ecced3ef088e030a697ff442a7740ae54 (patch)
tree1587dac277bc46027c7881c85dcc4078009ccdb1 /library/std/src/sys
parent349bda2051e94b7aefb33d6541f48f561bf06dbc (diff)
parent78577096f66acc3fe79c89c269361952b7dc0242 (diff)
downloadrust-3cf1275ecced3ef088e030a697ff442a7740ae54.tar.gz
rust-3cf1275ecced3ef088e030a697ff442a7740ae54.zip
Auto merge of #98143 - cuviper:futex-rwlock-inline, r=thomcc
Add `#[inline]` to small fns of futex `RwLock`

The important methods like `read` and `write` were already inlined,
which can propagate all the way to inlining in user code, but these
small state functions were left behind as normal calls. They should
almost always be inlined as well, as they're just a few instructions.
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/locks/futex_rwlock.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/locks/futex_rwlock.rs b/library/std/src/sys/unix/locks/futex_rwlock.rs
index 1f902f50587..b3bbbf743f8 100644
--- a/library/std/src/sys/unix/locks/futex_rwlock.rs
+++ b/library/std/src/sys/unix/locks/futex_rwlock.rs
@@ -27,22 +27,27 @@ const MAX_READERS: u32 = MASK - 1;
 const READERS_WAITING: u32 = 1 << 30;
 const WRITERS_WAITING: u32 = 1 << 31;
 
+#[inline]
 fn is_unlocked(state: u32) -> bool {
     state & MASK == 0
 }
 
+#[inline]
 fn is_write_locked(state: u32) -> bool {
     state & MASK == WRITE_LOCKED
 }
 
+#[inline]
 fn has_readers_waiting(state: u32) -> bool {
     state & READERS_WAITING != 0
 }
 
+#[inline]
 fn has_writers_waiting(state: u32) -> bool {
     state & WRITERS_WAITING != 0
 }
 
+#[inline]
 fn is_read_lockable(state: u32) -> bool {
     // This also returns false if the counter could overflow if we tried to read lock it.
     //
@@ -53,6 +58,7 @@ fn is_read_lockable(state: u32) -> bool {
     state & MASK < MAX_READERS && !has_readers_waiting(state) && !has_writers_waiting(state)
 }
 
+#[inline]
 fn has_reached_max_readers(state: u32) -> bool {
     state & MASK == MAX_READERS
 }
@@ -287,6 +293,7 @@ impl RwLock {
     }
 
     /// Spin for a while, but stop directly at the given condition.
+    #[inline]
     fn spin_until(&self, f: impl Fn(u32) -> bool) -> u32 {
         let mut spin = 100; // Chosen by fair dice roll.
         loop {
@@ -299,11 +306,13 @@ impl RwLock {
         }
     }
 
+    #[inline]
     fn spin_write(&self) -> u32 {
         // Stop spinning when it's unlocked or when there's waiting writers, to keep things somewhat fair.
         self.spin_until(|state| is_unlocked(state) || has_writers_waiting(state))
     }
 
+    #[inline]
     fn spin_read(&self) -> u32 {
         // Stop spinning when it's unlocked or read locked, or when there's waiting threads.
         self.spin_until(|state| {