Re: [PATCH 1/3] rust: Introduce irq module

From: Boqun Feng
Date: Fri Jul 26 2024 - 17:41:41 EST


On Fri, Jul 26, 2024 at 09:30:00PM +0000, Benno Lossin wrote:
> On 26.07.24 23:21, Boqun Feng wrote:
> > On Thu, Jul 25, 2024 at 06:27:50PM -0400, Lyude Paul wrote:
> > [...]
> >> +pub struct IrqDisabled<'a>(PhantomData<&'a ()>);
> >
> > I think you need to make this type !Send and !Sync (because you are
> > going to make it Copy). Otherwise, you will be able to pass the irq
> > disabled token to another thread on a different CPU which doesn't have
> > irq disabled.
>
> Oh yeah this is a good catch! (although it should not matter at the
> moment, see the end of the note below)
>
> Just a note: it is not because of making it Copy, this problem already
> exists in the current implementation. One could have sent the reference

Ah, you're right. I was thinking ahead, i.e. dont_interrupt_me() takes a
`IrqDisabled` instead of a `&IrqDisabled`. But it comes along with the
deal of making `IrqDisabled` `Copy` ;-)

> to a different thread using a "scoped spawn"-esque function [1]. IIRC we
> currently do not have such a function, but it should be possible to
> later add such a function. (and it is much more accurate to make this

Yes, scoped spawned timers and works will be very useful, because they
can use stacks for the data structures.

Regards,
Boqun

> type not be thread safe)
>
> [1]: https://doc.rust-lang.org/std/thread/struct.Scope.html#method.spawn
>
> ---
> Cheers,
> Benno
>