Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: sync: set_once: Implement Send and Sync

Implement Send and Sync for SetOnce<T> to allow it to be used across
thread boundaries.

Send: SetOnce<T> can be transferred across threads when T: Send, as
the contained value is also transferred and will be dropped on the
destination thread.

Sync: SetOnce<T> can be shared across threads when T: Sync, as
as_ref() provides shared references &T and atomic operations ensure
proper synchronization. Since the inner T may be dropped on any
thread, we also require T: Send.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251216000901.221375-1-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
8a581130 106ab474

+8
+8
rust/kernel/sync/set_once.rs
··· 123 123 } 124 124 } 125 125 } 126 + 127 + // SAFETY: `SetOnce` can be transferred across thread boundaries iff the data it contains can. 128 + unsafe impl<T: Send> Send for SetOnce<T> {} 129 + 130 + // SAFETY: `SetOnce` synchronises access to the inner value via atomic operations, 131 + // so shared references are safe when `T: Sync`. Since the inner `T` may be dropped 132 + // on any thread, we also require `T: Send`. 133 + unsafe impl<T: Send + Sync> Sync for SetOnce<T> {}