Re: [PATCH net-next v7 1/5] rust: core abstractions for network PHY drivers

Boqun Feng
2023-11-22T18:17:10Z

On Tue, Nov 21, 2023 at 11:13:06AM +0900, FUJITA Tomonori wrote:
[...]
>
> I'm not sure we discussed but making DriverVTable Sync works.
>
> #[repr(transparent)]
> pub struct DriverVTable(Opaque<bindings::phy_driver>);
>
> // SAFETY: DriverVTable has no &self methods, so immutable references to it are useless.

Minor nitpicking, I would add one more sentense in the safety comment:

therefore it's safe to share immutable references between
threads.

or
therefore it's safe to share immutable references between
execution contexts.

once we decide the term here ;-)

The reason is to match Sync definition [1]:

"""
Types for which it is safe to share references between threads.

This trait is automatically implemented when the compiler determines
it’s appropriate.

The precise definition is: a type T is Sync if and only if &T is Send.
In other words, if there is no possibility of undefined behavior
(including data races) when passing &T references between threads.
"""

[1]: https://doc.rust-lang.org/std/marker/trait.Sync.html

Regards,
Boqun

> unsafe impl Sync for DriverVTable {}
>
>
> looks correct?
>