From: Boqun Feng <boqun@kernel.org>
To: FUJITA Tomonori <tomo@aliasing.net>
Cc: gary@garyguo.net, ojeda@kernel.org, peterz@infradead.org,
will@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
bjorn3_gh@protonmail.com, dakr@kernel.org, lossin@kernel.org,
mark.rutland@arm.com, tmgross@umich.edu,
rust-for-linux@vger.kernel.org, fujita.tomonori@gmail.com
Subject: Re: [PATCH v2 1/2] rust: sync: atomic: Add AtomicFlag::get_mut
Date: Tue, 27 Jan 2026 19:38:05 -0800 [thread overview]
Message-ID: <aXmEnWcra0Ccqav7@tardis.local> (raw)
In-Reply-To: <20260128.123212.248535348759706770.fujita@bee>
On Wed, Jan 28, 2026 at 12:32:12PM +0900, FUJITA Tomonori wrote:
[...]
> >>
> >> I think what Fujita has is more "proper". Your approach still have the issue of
> >> requiring a specific ordering of the fields. If this is messed up, then the
> >> entire thing is broken. I.e. the safety proof of `get_mut` depends on the fields
> >> being ordered correctly in `FlagInner`.
> >>
> >> If you want to go down this route then I would just scrap `enum Flag` all
> >> together and always define it as struct, with an internal `bool` + 3 bytes of
> >> zero padding. This way we don't even need unsafe for `get_mut`.
> >>
> >
> > Hmm.. so like:
> >
> > const PAD_SIZE: usize = <3 or 0 depending on ARCHs>
> >
> > /// # Invariants
> > /// `pad` has to be all zero.
> > struct Flag {
> > bool_field: bool,
> > pad: [i8; PAD_SIZE],
> > }
> >
> > impl Flag {
> > pub const fn set() -> Flag {
> > Self { true, pad: [0; PAD_SIZE] }
> > }
> >
> > pub const fn clear() -> Flag {
> > Self { false, pad: [0; PAD_SIZE] }
> > }
> > }
> >
> > ?
> >
> > Yes, I think it's better ;-)
> >
> > Also, now given that `AtomicFlag` behaves exactly like a `Atomic<bool>`,
> > should we do:
> >
> > /// `AtomicFlag` documentation here.
> > #[cfg(<Arch supports byte-wise atomic>)]
> > type AtomicFlag = Atomic<bool>;
> > #[cfg(<Arch doesn't supprot byte-wise atomic>)]
> > struct AtomicFlag(Atomic<BooleanFlag>);
> >
> > // `Flag` doesn't even need to be public.
> > #[cfg(<Arch doesn't supprot byte-wise atomic>)]
> > struct BooleanFlag { ... }
> >
> > (I renamed `Flag` -> `BooleanFlag`)
> >
> > Thoughts? I don't think there is any extra benefit of exposing
> > `Atomic<BooleanFlag>`.
>
> Agreed.
>
> You prefer the cleaner git history? Then I'll send the next version
> for rust-sync-fixes, to implement BooleanFlag (or Flag) and AtomicFlag
> from scratch.
>
Yes, that'll be great, thank you!
Regards,
Boqun
next prev parent reply other threads:[~2026-01-28 3:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 12:52 [PATCH v2 0/2] rust: add AtomicFlag::get_mut FUJITA Tomonori
2026-01-27 12:52 ` [PATCH v2 1/2] rust: sync: atomic: Add AtomicFlag::get_mut FUJITA Tomonori
2026-01-27 13:53 ` Gary Guo
2026-01-27 14:32 ` Miguel Ojeda
2026-01-28 3:47 ` FUJITA Tomonori
2026-01-28 3:55 ` Boqun Feng
2026-01-27 15:35 ` Boqun Feng
2026-01-27 15:42 ` Gary Guo
2026-01-27 15:59 ` Boqun Feng
2026-01-27 16:10 ` Gary Guo
2026-01-27 16:34 ` Boqun Feng
2026-01-28 3:32 ` FUJITA Tomonori
2026-01-28 3:38 ` Boqun Feng [this message]
2026-01-27 12:53 ` [PATCH v2 2/2] rust: list: Use AtomicFlag in AtomicTracker FUJITA Tomonori
2026-01-27 13:54 ` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aXmEnWcra0Ccqav7@tardis.local \
--to=boqun@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=dakr@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=lossin@kernel.org \
--cc=mark.rutland@arm.com \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=tomo@aliasing.net \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox