rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: sync: Add Guard related type-aliases
@ 2024-11-20 22:26 Lyude Paul
  2024-11-20 22:26 ` [PATCH 1/2] rust: sync: Add MutexGuard type alias Lyude Paul
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lyude Paul @ 2024-11-20 22:26 UTC (permalink / raw)
  To: rust-for-linux
  Cc: linux-kernel, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross

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
-- 
2.47.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] rust: sync: Add MutexGuard type alias
  2024-11-20 22:26 [PATCH 0/2] rust: sync: Add Guard related type-aliases Lyude Paul
@ 2024-11-20 22:26 ` Lyude Paul
  2024-11-25  9:47   ` Alice Ryhl
  2024-11-20 22:26 ` [PATCH 2/2] rust: sync: Add SpinLockGuard " Lyude Paul
  2024-11-27 18:22 ` [PATCH 0/2] rust: sync: Add Guard related type-aliases Boqun Feng
  2 siblings, 1 reply; 6+ messages in thread
From: Lyude Paul @ 2024-11-20 22:26 UTC (permalink / raw)
  To: rust-for-linux
  Cc: linux-kernel, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Martin Rodriguez Reboredo, Filipe Xavier,
	Danilo Krummrich, Wedson Almeida Filho

A simple helper alias for code that needs to deal with Guard types returned
from Mutexes.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 rust/kernel/sync.rs            | 2 +-
 rust/kernel/sync/lock/mutex.rs | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/sync.rs b/rust/kernel/sync.rs
index 2bdd1cffcdab3..0f630714da2aa 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -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;
 
diff --git a/rust/kernel/sync/lock/mutex.rs b/rust/kernel/sync/lock/mutex.rs
index 0e946ebefce12..10a70c07268dc 100644
--- a/rust/kernel/sync/lock/mutex.rs
+++ b/rust/kernel/sync/lock/mutex.rs
@@ -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;
 
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] rust: sync: Add SpinLockGuard type alias
  2024-11-20 22:26 [PATCH 0/2] rust: sync: Add Guard related type-aliases Lyude Paul
  2024-11-20 22:26 ` [PATCH 1/2] rust: sync: Add MutexGuard type alias Lyude Paul
@ 2024-11-20 22:26 ` Lyude Paul
  2024-11-25  9:47   ` Alice Ryhl
  2024-11-27 18:22 ` [PATCH 0/2] rust: sync: Add Guard related type-aliases Boqun Feng
  2 siblings, 1 reply; 6+ messages in thread
From: Lyude Paul @ 2024-11-20 22:26 UTC (permalink / raw)
  To: rust-for-linux
  Cc: linux-kernel, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Martin Rodriguez Reboredo, Filipe Xavier,
	Valentin Obst, Wedson Almeida Filho, Danilo Krummrich

A simple helper alias for code that needs to deal with Guard types returned
from SpinLocks.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 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 0f630714da2aa..b469d796747a4 100644
--- a/rust/kernel/sync.rs
+++ b/rust/kernel/sync.rs
@@ -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`.
diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spinlock.rs
index 9f4d128bed983..081c0220013b3 100644
--- a/rust/kernel/sync/lock/spinlock.rs
+++ b/rust/kernel/sync/lock/spinlock.rs
@@ -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 {
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] rust: sync: Add SpinLockGuard type alias
  2024-11-20 22:26 ` [PATCH 2/2] rust: sync: Add SpinLockGuard " Lyude Paul
@ 2024-11-25  9:47   ` Alice Ryhl
  0 siblings, 0 replies; 6+ messages in thread
From: Alice Ryhl @ 2024-11-25  9:47 UTC (permalink / raw)
  To: Lyude Paul
  Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Martin Rodriguez Reboredo,
	Filipe Xavier, Valentin Obst, Wedson Almeida Filho,
	Danilo Krummrich

On Wed, Nov 20, 2024 at 11:28 PM Lyude Paul <lyude@redhat.com> wrote:
>
> 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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] rust: sync: Add MutexGuard type alias
  2024-11-20 22:26 ` [PATCH 1/2] rust: sync: Add MutexGuard type alias Lyude Paul
@ 2024-11-25  9:47   ` Alice Ryhl
  0 siblings, 0 replies; 6+ messages in thread
From: Alice Ryhl @ 2024-11-25  9:47 UTC (permalink / raw)
  To: Lyude Paul
  Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Martin Rodriguez Reboredo,
	Filipe Xavier, Danilo Krummrich, Wedson Almeida Filho

On Wed, Nov 20, 2024 at 11:27 PM Lyude Paul <lyude@redhat.com> wrote:
>
> 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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] rust: sync: Add Guard related type-aliases
  2024-11-20 22:26 [PATCH 0/2] rust: sync: Add Guard related type-aliases Lyude Paul
  2024-11-20 22:26 ` [PATCH 1/2] rust: sync: Add MutexGuard type alias Lyude Paul
  2024-11-20 22:26 ` [PATCH 2/2] rust: sync: Add SpinLockGuard " Lyude Paul
@ 2024-11-27 18:22 ` Boqun Feng
  2 siblings, 0 replies; 6+ messages in thread
From: Boqun Feng @ 2024-11-27 18:22 UTC (permalink / raw)
  To: Lyude Paul
  Cc: rust-for-linux, linux-kernel, Miguel Ojeda, Alex Gaynor, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross

On Wed, Nov 20, 2024 at 05:26:27PM -0500, Lyude Paul wrote:
> 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
> 

Queued for future tests and reviews, thanks!

Regards,
Boqun

>  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
> -- 
> 2.47.0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-27 18:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-20 22:26 [PATCH 0/2] rust: sync: Add Guard related type-aliases Lyude Paul
2024-11-20 22:26 ` [PATCH 1/2] rust: sync: Add MutexGuard type alias Lyude Paul
2024-11-25  9:47   ` Alice Ryhl
2024-11-20 22:26 ` [PATCH 2/2] rust: sync: Add SpinLockGuard " Lyude Paul
2024-11-25  9:47   ` Alice Ryhl
2024-11-27 18:22 ` [PATCH 0/2] rust: sync: Add Guard related type-aliases Boqun Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).