Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: list: Switch to kernel::sync atomic primitives

Convert uses of `AtomicBool` to `Atomic<bool>`.

Note that the compare_exchange migration simplifies to
`try_cmpxchg()`, since `try_cmpxchg()` provides relaxed ordering on
failure, making the explicit failure ordering unnecessary.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251230093718.1852322-3-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
323e4bfc 4bac2872

+6 -8
+6 -8
rust/kernel/list/arc.rs
··· 6 6 7 7 use crate::alloc::{AllocError, Flags}; 8 8 use crate::prelude::*; 9 + use crate::sync::atomic::{ordering, Atomic}; 9 10 use crate::sync::{Arc, ArcBorrow, UniqueArc}; 10 11 use core::marker::PhantomPinned; 11 12 use core::ops::Deref; 12 13 use core::pin::Pin; 13 - use core::sync::atomic::{AtomicBool, Ordering}; 14 14 15 15 /// Declares that this type has some way to ensure that there is exactly one `ListArc` instance for 16 16 /// this id. ··· 469 469 /// If the boolean is `false`, then there is no [`ListArc`] for this value. 470 470 #[repr(transparent)] 471 471 pub struct AtomicTracker<const ID: u64 = 0> { 472 - inner: AtomicBool, 472 + inner: Atomic<bool>, 473 473 // This value needs to be pinned to justify the INVARIANT: comment in `AtomicTracker::new`. 474 474 _pin: PhantomPinned, 475 475 } ··· 480 480 // INVARIANT: Pin-init initializers can't be used on an existing `Arc`, so this value will 481 481 // not be constructed in an `Arc` that already has a `ListArc`. 482 482 Self { 483 - inner: AtomicBool::new(false), 483 + inner: Atomic::new(false), 484 484 _pin: PhantomPinned, 485 485 } 486 486 } 487 487 488 - fn project_inner(self: Pin<&mut Self>) -> &mut AtomicBool { 488 + fn project_inner(self: Pin<&mut Self>) -> &mut Atomic<bool> { 489 489 // SAFETY: The `inner` field is not structurally pinned, so we may obtain a mutable 490 490 // reference to it even if we only have a pinned reference to `self`. 491 491 unsafe { &mut Pin::into_inner_unchecked(self).inner } ··· 500 500 501 501 unsafe fn on_drop_list_arc(&self) { 502 502 // INVARIANT: We just dropped a ListArc, so the boolean should be false. 503 - self.inner.store(false, Ordering::Release); 503 + self.inner.store(false, ordering::Release); 504 504 } 505 505 } 506 506 ··· 514 514 fn try_new_list_arc(&self) -> bool { 515 515 // INVARIANT: If this method returns true, then the boolean used to be false, and is no 516 516 // longer false, so it is okay for the caller to create a new [`ListArc`]. 517 - self.inner 518 - .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed) 519 - .is_ok() 517 + self.inner.cmpxchg(false, true, ordering::Acquire).is_ok() 520 518 } 521 519 }