rust-embedded / bare-metal

Abstractions common to microcontrollers
Apache License 2.0
114 stars 16 forks source link

Inefficiency in the CriticalSection API #7

Closed TethysSvensson closed 4 years ago

TethysSvensson commented 6 years ago

It seems inefficient to pass around a &'a CriticalSection, since reference to zero-sized types are not themselves zero-sized in rust. In a lot of cases, this would be compiled out, but it is not guaranteed.

It would be better if CriticalSection was defined like this:

struct CriticalSection<'a> {
    _0: PhantomData<&'a ()>,
}

Instead of passing &'a CriticalSection you would then pass a CriticalSection<'a> around. This would have the same purpose