Re: [PATCH v1 0/2] Add support for print exactly once

Boqun Feng
2025-11-14T00:57:22Z

On Fri, Nov 14, 2025 at 09:47:30AM +0900, FUJITA Tomonori wrote:
[...]
> >> Using u8 as atomic type instead of i32 would require a fair amount of
> >> work, since at the moment only i32 and i64 are supported as atomic
> >> types, right?
> >
> > Supporting u8 atomics in general is tricky, but I think *specifically*
> > load/store should not be a problem.
>
> You meant using read_volatile/write_volatile? Since we only need
> "Relaxed" order so something like the following?
>
> #[repr(transparent)]
> struct AtomicU8(UnsafeCell<u8>);
>

Please don't. Please make it work with Atomic<T>, also store release and
load acquire should be introduced as well.

Regards,
Boqun

> impl AtomicU8 {
> #[inline(always)]
> fn load(&self) -> u8 {
> unsafe { core::ptr::read_volatile(self.0.get()) }
> }
>
> #[inline(always)]
> fn store(&self, v: u8) {
> unsafe { core::ptr::write_volatile(self.0.get(), v) }
> }
> }