rust: sync: Add Guard related type-aliases
Subsystems (3)
Lyude Paul
reviewercover rust: sync: Add Guard related type-aliases
This is something I originally meant to do when adding Lock::from_raw and exposing Guard::new - introduce type aliases for the various types of Guard that we can run into.
Lyude Paul (2):
rust: sync: Add MutexGuard type alias
rust: sync: Add SpinLockGuard type alias
rust/kernel/sync.rs | 4 ++-- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ rust/kernel/sync/lock/spinlock.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-)
base-commit: b2603f8ac8217bc59f5c7f248ac248423b9b99cb
prerequisite-patch-id: 8c65a39abe47832d0c98c9c266b4b9348fb3526a
prerequisite-patch-id: 211faf8533feec77907b0a1b9b2f788e72c5ac58
Signature · 1 line
2.47.0
Lyude Paul
reviewerPATCH 1/2 rust: sync: Add MutexGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from Mutexes.
--- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
rust/kernel/sync.rs +1 -1
@@ -15,7 +15,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 }; +pub use lock::mutex::{new_mutex,Mutex ,MutexGuard };pub use lock::spinlock::{new_spinlock,SpinLock };pub use locked_by::LockedBy ;
rust/kernel/sync/lock/mutex.rs +8 -0
@@ -86,6 +86,14 @@ macro_rules! 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 ;
Signature · 1 line
2.47.0
Re: [PATCH 1/2] rust: sync: Add MutexGuard type alias
Quoted 5 lines · Lyude Paul
A simple helper alias for code that needs to deal with Guard types returned from Mutexes.
Signed-off-by Lyude Paul <[email protected]>
[tip: locking/core] rust: sync: Add MutexGuard type alias
In reply to Lyude PaulThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 37624dde4768ec25d2f9798aa75bf32e18c0eae2 Gitweb: https://git.kernel.org/tip/37624dde4768ec25d2f9798aa75bf32e18c0eae2 Author: Lyude Paul <[email protected]> AuthorDate: Wed, 20 Nov 2024 17:26:28 -05:00 Committer: Boqun Feng <[email protected]> CommitterDate: Thu, 19 Dec 2024 14:04:42 -08:00
rust: sync: Add MutexGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from Mutexes.
--- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
rust/kernel/sync.rs +1 -1
@@ -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 ;
rust/kernel/sync/lock/mutex.rs +8 -0
@@ -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 ;
Lyude Paul
reviewerPATCH 2/2 rust: sync: Add SpinLockGuard type alias
In reply to Lyude PaulA simple helper alias for code that needs to deal with Guard types returned from SpinLocks.
--- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
rust/kernel/sync.rs +1 -1
@@ -16,7 +16,7 @@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`.
rust/kernel/sync/lock/spinlock.rs +8 -0
@@ -87,6 +87,14 @@ macro_rules! new_spinlock {/// 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 {
Signature · 1 line
2.47.0
Re: [PATCH 2/2] rust: sync: Add SpinLockGuard type alias
Quoted 5 lines · Lyude Paul
A simple helper alias for code that needs to deal with Guard types returned from SpinLocks.
Signed-off-by Lyude Paul <[email protected]>
[tip: locking/core] rust: sync: Add SpinLockGuard type alias
In reply to Lyude PaulThe following commit has been merged into the locking/core branch of tip:
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 <[email protected]> AuthorDate: Wed, 20 Nov 2024 17:26:29 -05:00 Committer: Boqun Feng <[email protected]> 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.
--- rust/kernel/sync.rs | 2 +- rust/kernel/sync/lock/spinlock.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-)
rust/kernel/sync.rs +1 -1
@@ -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`.
rust/kernel/sync/lock/spinlock.rs +8 -0
@@ -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 {
Quoted 8 lines · Lyude Paul
This is something I originally meant to do when adding
Lock::from_rawand exposingGuard::new- introduce type aliases for the various types of Guard that we can run into.Lyude Paul (2):
rust: sync: Add MutexGuard type alias
rust: sync: Add SpinLockGuard type alias
Queued for future tests and reviews, thanks!
Regards,
Boqun
Quoted 12 lines
rust/kernel/sync.rs | 4 ++-- rust/kernel/sync/lock/mutex.rs | 8 ++++++++ rust/kernel/sync/lock/spinlock.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-)base-commit:
b2603f8ac8217bc59f5c7f248ac248423b9b99cb
prerequisite-patch-id:8c65a39abe47832d0c98c9c266b4b9348fb3526a
prerequisite-patch-id:211faf8533feec77907b0a1b9b2f788e72c5ac58Signature · 1 line
2.47.0