Skip to content

Commit 37624dd

Browse files
Lyudefbq
authored andcommitted
rust: sync: Add MutexGuard type alias
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
1 parent daa03fe commit 37624dd

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
@@ -16,7 +16,7 @@ pub mod poll;
1616
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};
19-
pub use lock::mutex::{new_mutex, Mutex};
19+
pub use lock::mutex::{new_mutex, Mutex, MutexGuard};
2020
pub use lock::spinlock::{new_spinlock, SpinLock};
2121
pub use locked_by::LockedBy;
2222

rust/kernel/sync/lock/mutex.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ pub use new_mutex;
8686
/// [`struct mutex`]: srctree/include/linux/mutex.h
8787
pub type Mutex<T> = super::Lock<T, MutexBackend>;
8888

89+
/// A [`Guard`] acquired from locking a [`Mutex`].
90+
///
91+
/// This is simply a type alias for a [`Guard`] returned from locking a [`Mutex`]. It will unlock
92+
/// the [`Mutex`] upon being dropped.
93+
///
94+
/// [`Guard`]: super::Guard
95+
pub type MutexGuard<'a, T> = super::Guard<'a, T, MutexBackend>;
96+
8997
/// A kernel `struct mutex` lock backend.
9098
pub struct MutexBackend;
9199

0 commit comments

Comments
 (0)