[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250729-regulator-send-sync-v1-2-8bcbd546b940@collabora.com>
Date: Tue, 29 Jul 2025 14:31:41 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...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>
Cc: linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
Daniel Almeida <daniel.almeida@...labora.com>
Subject: [PATCH 2/2] rust: regulator: implement Send and Sync for
Regulator<T>
Sending a &Regulator<T> to another thread is safe, as the regulator core
will properly handle the locking for us. Additionally, there are no
restrictions that prevents sending a Regulator<T> to another thread.
Given these two facts, implement Send and Sync.
Signed-off-by: Daniel Almeida <daniel.almeida@...labora.com>
---
rust/kernel/regulator.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/rust/kernel/regulator.rs b/rust/kernel/regulator.rs
index d56aa229e838c45258a27cea742a693dd71e8e40..704147e18bfc9c993a00f7a187105360ad1d4956 100644
--- a/rust/kernel/regulator.rs
+++ b/rust/kernel/regulator.rs
@@ -398,6 +398,14 @@ fn drop(&mut self) {
}
}
+// SAFETY: It is safe to send a `Regulator<T>` across threads. In particular, a
+// Regulator<T> can be dropped from any thread.
+unsafe impl<T: RegulatorState> Send for Regulator<T> {}
+
+// SAFETY: It is safe to send a &Regulator<T> across threads because the C side
+// handles its own locking.
+unsafe impl<T: RegulatorState> Sync for Regulator<T> {}
+
/// A voltage.
///
/// This type represents a voltage value in microvolts.
--
2.50.0
Powered by blists - more mailing lists