Re: [PATCH v2] rust: add global lock support
From: Boqun Feng
Date: Mon Sep 02 2024 - 10:18:22 EST
On Mon, Sep 02, 2024 at 01:42:53PM +0200, Alice Ryhl wrote:
> On Mon, Sep 2, 2024 at 1:37 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> >
> > On Fri, Aug 30, 2024 at 3:22 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
> > >
> > > On 30.08.24 07:34, Alice Ryhl wrote:
> > > > On Thu, Aug 29, 2024 at 8:17 PM Benno Lossin <benno.lossin@xxxxxxxxx> wrote:
> > > >>
> > > >> On 27.08.24 10:41, Alice Ryhl wrote:
> > > >>> For architectures that don't use all-zeros for the unlocked case, we
> > > >>> will most likely have to hard-code the correct representation on the
> > > >>> Rust side.
> > > >>
> > > >> You mean in `unsafe_const_init`?
> > > >
> > > > No, I mean we would have `unsafe_const_new` directly set `state` to
> > > > the right value and let `unsafe_const_init` be a no-op.
> > >
> > > But how do you set the right value of a list_head? The value will be
> > > moved.
> >
> > Right ... we probably can't get around needing a macro. Can statics
> > even reference themselves?
>
> Looks like they can:
>
> use std::ptr::addr_of;
>
> struct MyStruct {
> ptr: *const MyStruct,
> }
>
> static mut MY_STRUCT: MyStruct = MyStruct {
> ptr: addr_of!(MY_STRUCT),
I'm guessing you're using nightly or new enough rustc, in the current
stable (1.80), this would complain using static mut without unsafe:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2954daab193caf14d1fb91492dcf325a
, which gets changed recently:
https://github.com/rust-lang/rust/pull/125834
Regards,
Boqun
> };
>
> Alice