[tip: locking/core] rust: sync: Add SpinLockGuard type alias

From: tip-bot2 for Lyude Paul
Date: Tue Dec 24 2024 - 13:53:59 EST


The following commit has been merged into the locking/core branch of tip:

Commit-ID: eb5ccb038284dc0e69822d71aafcbf7b57394aad
Gitweb: https://git.kernel.org/tip/eb5ccb038284dc0e69822d71aafcbf7b57394aad
Author: Lyude Paul <lyude@xxxxxxxxxx>
AuthorDate: Wed, 20 Nov 2024 17:26:29 -05:00
Committer: Boqun Feng <boqun.feng@xxxxxxxxx>
CommitterDate: Thu, 19 Dec 2024 14:04:42 -08:00

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@xxxxxxxxxx>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>
Link: https://lore.kernel.org/r/20241120222742.2490495-3-lyude@xxxxxxxxxx
---
rust/kernel/sync.rs | 2 +-
rust/kernel/sync/lock/spinlock.rs | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index 2721b5c..dffdaad 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -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`.
diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spinlock.rs
index 9f4d128..081c022 100644
--- a/rust/kernel/sync/lock/spinlock.rs
+++ b/rust/kernel/sync/lock/spinlock.rs
@@ -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 {