]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: sync: Add SpinLockGuard type alias
authorLyude Paul <lyude@redhat.com>
Wed, 20 Nov 2024 22:26:29 +0000 (17:26 -0500)
committerBoqun Feng <boqun.feng@gmail.com>
Thu, 19 Dec 2024 22:04:42 +0000 (14:04 -0800)
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
rust/kernel/sync.rs
rust/kernel/sync/lock/spinlock.rs

index 2721b5c8deda85b8c3cdad88394d771041b60291..dffdaad972cebf460cc1d400480b910c401ea219 100644 (file)
@@ -17,7 +17,7 @@ pub use arc::{Arc, ArcBorrow, UniqueArc};
 pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult};
 pub use lock::global::{global_lock, GlobalGuard, GlobalLock, GlobalLockBackend, GlobalLockedBy};
 pub use lock::mutex::{new_mutex, Mutex, MutexGuard};
-pub use lock::spinlock::{new_spinlock, SpinLock};
+pub use lock::spinlock::{new_spinlock, SpinLock, SpinLockGuard};
 pub use locked_by::LockedBy;
 
 /// Represents a lockdep class. It's a wrapper around C's `lock_class_key`.
index 9f4d128bed983e4eebc1bed53c41a8ead463d27b..081c0220013b3dcdb10fef9e2238f3fece697c52 100644 (file)
@@ -87,6 +87,14 @@ pub type SpinLock<T> = super::Lock<T, SpinLockBackend>;
 /// A kernel `spinlock_t` lock backend.
 pub struct SpinLockBackend;
 
+/// A [`Guard`] acquired from locking a [`SpinLock`].
+///
+/// This is simply a type alias for a [`Guard`] returned from locking a [`SpinLock`]. It will unlock
+/// the [`SpinLock`] upon being dropped.
+///
+/// [`Guard`]: super::Guard
+pub type SpinLockGuard<'a, T> = super::Guard<'a, T, SpinLockBackend>;
+
 // SAFETY: The underlying kernel `spinlock_t` object ensures mutual exclusion. `relock` uses the
 // default implementation that always calls the same locking method.
 unsafe impl super::Backend for SpinLockBackend {