]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: sync: Add MutexGuard type alias
authorLyude Paul <lyude@redhat.com>
Wed, 20 Nov 2024 22:26:28 +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 Mutexes.

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-2-lyude@redhat.com
rust/kernel/sync.rs
rust/kernel/sync/lock/mutex.rs

index 1eab7ebf25fd39d343bdab5856152177b4bfa8d4..2721b5c8deda85b8c3cdad88394d771041b60291 100644 (file)
@@ -16,7 +16,7 @@ pub mod poll;
 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};
+pub use lock::mutex::{new_mutex, Mutex, MutexGuard};
 pub use lock::spinlock::{new_spinlock, SpinLock};
 pub use locked_by::LockedBy;
 
index 0e946ebefce125790c0461de616653471f182067..10a70c07268dc7eb641a98242fa76c8056fc365a 100644 (file)
@@ -86,6 +86,14 @@ pub use new_mutex;
 /// [`struct mutex`]: srctree/include/linux/mutex.h
 pub type Mutex<T> = super::Lock<T, MutexBackend>;
 
+/// A [`Guard`] acquired from locking a [`Mutex`].
+///
+/// This is simply a type alias for a [`Guard`] returned from locking a [`Mutex`]. It will unlock
+/// the [`Mutex`] upon being dropped.
+///
+/// [`Guard`]: super::Guard
+pub type MutexGuard<'a, T> = super::Guard<'a, T, MutexBackend>;
+
 /// A kernel `struct mutex` lock backend.
 pub struct MutexBackend;