Skip to content

Commit dcb053c

Browse files
authored
Merge pull request #17 from mkroening/inline
perf: inline everything
2 parents 02fce20 + 42e204d commit dcb053c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/spinlock.rs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct RawSpinlock {
3232
impl RawSpinlock {
3333
// Can fail to lock even if the spinlock is not locked. May be more efficient than `try_lock`
3434
// when called in a loop.
35+
#[inline]
3536
fn try_lock_weak(&self) -> bool {
3637
// The Orderings are the same as try_lock, and are still correct here.
3738
self.locked
@@ -48,6 +49,7 @@ unsafe impl RawMutex for RawSpinlock {
4849
// A spinlock guard can be sent to another thread and unlocked there
4950
type GuardMarker = GuardSend;
5051

52+
#[inline]
5153
fn lock(&self) {
5254
while !self.try_lock_weak() {
5355
// Wait until the lock looks unlocked before retrying
@@ -59,6 +61,7 @@ unsafe impl RawMutex for RawSpinlock {
5961
}
6062
}
6163

64+
#[inline]
6265
fn try_lock(&self) -> bool {
6366
// Code taken from:
6467
// https://github.com/Amanieu/parking_lot/blob/fa294cd677936bf365afa0497039953b10c722f5/lock_api/src/lib.rs#L49-L53
@@ -74,10 +77,12 @@ unsafe impl RawMutex for RawSpinlock {
7477
.is_ok()
7578
}
7679

80+
#[inline]
7781
unsafe fn unlock(&self) {
7882
self.locked.store(false, Ordering::Release);
7983
}
8084

85+
#[inline]
8186
fn is_locked(&self) -> bool {
8287
// Relaxed is sufficient because this operation does not provide synchronization, only atomicity.
8388
self.locked.load(Ordering::Relaxed)
@@ -197,6 +202,7 @@ pub type MappedSpinlockGuard<'a, T> = lock_api::MappedMutexGuard<'a, RawSpinlock
197202
///
198203
/// static SPINLOCK: Spinlock<i32> = const_spinlock(42);
199204
/// ```
205+
#[inline]
200206
pub const fn const_spinlock<T>(val: T) -> Spinlock<T> {
201207
Spinlock::const_new(<RawSpinlock as lock_api::RawMutex>::INIT, val)
202208
}

0 commit comments

Comments
 (0)