Re: [TECH TOPIC] Rust for Linux

Miguel Ojeda
2021-07-07T22:44:55Z

On Wed, Jul 7, 2021 at 11:47 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Out of curiosity: we have in the kernel objects shared between multiple
> threads that require locking, but in some contexts taking the lock isn't
> required. I'm thinking in particular about initialization time when you
> create the object, before it is made visible to other users, or
> destruction time, when you nobody else can have a reference to the
> object anymore. Avoiding lock operations in those cases can be an
> optimization. Cn rust handle that ?

Yes, you could provide e.g. an `unsafe fn` for users to access the
underlying data if the users know that such a thing is sound (by other
means that the compiler cannot verify).

To use it, users will, of course, need an `unsafe` block to make the
call compile; and a `SAFETY` comment on top of it explaining why it is
actually sound to make such a call (we require these).

Cheers,
Miguel