Skip to content

Commit eb5ccb0

Browse files
Lyudefbq
authored andcommitted
rust: sync: Add SpinLockGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from SpinLocks. Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241120222742.2490495-3-lyude@redhat.com
1 parent 37624dd commit eb5ccb0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

rust/kernel/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use arc::{Arc, ArcBorrow, UniqueArc};
1717
pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult};
1818
pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBackend, GlobalLockedBy};
1919
pub use lock::mutex::{new_mutex, Mutex, MutexGuard};
20-
pub use lock::spinlock::{new_spinlock, SpinLock};
20+
pub use lock::spinlock::{new_spinlock, SpinLock, SpinLockGuard};
2121
pub use locked_by::LockedBy;
2222

2323
/// Represents a lockdep class. It's a wrapper around C's `lock_class_key`.

rust/kernel/sync/lock/spinlock.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ pub type SpinLock<T> = super::Lock<T, SpinLockBackend>;
8787
/// A kernel `spinlock_t` lock backend.
8888
pub struct SpinLockBackend;
8989

90+
/// A [`Guard`] acquired from locking a [`SpinLock`].
91+
///
92+
/// This is simply a type alias for a [`Guard`] returned from locking a [`SpinLock`]. It will unlock
93+
/// the [`SpinLock`] upon being dropped.
94+
///
95+
/// [`Guard`]: super::Guard
96+
pub type SpinLockGuard<'a, T> = super::Guard<'a, T, SpinLockBackend>;
97+
9098
// SAFETY: The underlying kernel `spinlock_t` object ensures mutual exclusion. `relock` uses the
9199
// default implementation that always calls the same locking method.
92100
unsafe impl super::Backend for SpinLockBackend {

0 commit comments

Comments
 (0)