Re: [PATCH v2] rust: add global lock support
From: Gary Guo
Date: Fri Aug 30 2024 - 11:10:14 EST
On Fri, 30 Aug 2024 07:34:00 +0200
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> > > Due to the initialization requirement, constructing a global mutex is
> > > unsafe with the current approach. In the future, it would be really nice
> > > to support global mutexes that don't need to be initialized, which would
> > > make them safe. Unfortunately, this is not possible today because
> > > bindgen refuses to expose __ARCH_SPIN_LOCK_UNLOCKED to Rust as a
> > > compile-time constant. It just generates an `extern "C"` global
> > > reference instead.
> >
> > Ideally, we would have support for static initialization in pinned-init.
>
> I don't think traits work with const today, so pin-init would need an
> entirely different mechanism? If you're talking about using
> CONSTRUCTORS, then I think it's an undesirable solution. C code can
> define static mutexes without load-time initialization hooks. We
> should be able to do the same.
I think I actually prefer using constructors to unsafe.
Best,
Gary