[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260121223933.1568682-16-lyude@redhat.com>
Date: Wed, 21 Jan 2026 17:39:18 -0500
From: Lyude Paul <lyude@...hat.com>
To: rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>
Cc: Boqun Feng <boqun.feng@...il.com>,
Daniel Almeida <daniel.almeida@...labora.com>,
Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>
Subject: [PATCH v17 15/16] rust: sync: lock/global: Add ContextualBackend support to GlobalLock
Now that we have the ability to provide an explicit lifetime for a
GlobalGuard and an explicit Backend for a GlobalGuard, we can finally
implement lock_with() and try_lock_with().
Signed-off-by: Lyude Paul <lyude@...hat.com>
---
rust/kernel/sync/lock/global.rs | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
index 94f6b3b21324f..cfc71af7482ed 100644
--- a/rust/kernel/sync/lock/global.rs
+++ b/rust/kernel/sync/lock/global.rs
@@ -6,7 +6,7 @@
use crate::{
str::{CStr, CStrExt as _},
- sync::lock::{Backend, Guard, Lock},
+ sync::lock::{Backend, BackendWithContext, Guard, Lock},
sync::{LockClassKey, LockedBy},
types::Opaque,
};
@@ -89,6 +89,34 @@ pub fn try_lock(&'static self) -> Option<GlobalGuard<'static, G, G::Backend>> {
inner: self.inner.try_lock()?,
})
}
+
+ /// Lock this global lock with the provided `context`.
+ pub fn lock_with<'a, B>(
+ &'static self,
+ context: <G::Backend as BackendWithContext>::Context<'a>,
+ ) -> GlobalGuard<'a, G, B>
+ where
+ G::Backend: BackendWithContext<ContextualBackend = B>,
+ B: Backend,
+ {
+ GlobalGuard {
+ inner: self.inner.lock_with(context),
+ }
+ }
+
+ /// Try to lock this global lock with the provided `context`.
+ pub fn try_lock_with<'a, B>(
+ &'static self,
+ context: <G::Backend as BackendWithContext>::Context<'a>,
+ ) -> Option<GlobalGuard<'a, G, B>>
+ where
+ G::Backend: BackendWithContext<ContextualBackend = B>,
+ B: Backend,
+ {
+ Some(GlobalGuard {
+ inner: self.inner.try_lock_with(context)?,
+ })
+ }
}
/// A guard for a [`GlobalLock`].
--
2.52.0
Powered by blists - more mailing lists