Skip to content

Commit 9a200cb

Browse files
danielalmeida-collaborabroonie
authored andcommitted
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@collabora.com> Link: https://patch.msgid.link/20250729-regulator-send-sync-v1-2-8bcbd546b940@collabora.com Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f7fbf30 commit 9a200cb

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

rust/kernel/regulator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ impl<T: RegulatorState> Drop for Regulator<T> {
398398
}
399399
}
400400

401+
// SAFETY: It is safe to send a `Regulator<T>` across threads. In particular, a
402+
// Regulator<T> can be dropped from any thread.
403+
unsafe impl<T: RegulatorState> Send for Regulator<T> {}
404+
405+
// SAFETY: It is safe to send a &Regulator<T> across threads because the C side
406+
// handles its own locking.
407+
unsafe impl<T: RegulatorState> Sync for Regulator<T> {}
408+
401409
/// A voltage.
402410
///
403411
/// This type represents a voltage value in microvolts.

0 commit comments

Comments
 (0)