Skip to content

Commit 323e4bf

Browse files
fujitafbq
authored andcommitted
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
1 parent 4bac287 commit 323e4bf

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

rust/kernel/list/arc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
77
use crate::alloc::{AllocError, Flags};
88
use crate::prelude::*;
9+
use crate::sync::atomic::{ordering, Atomic};
910
use crate::sync::{Arc, ArcBorrow, UniqueArc};
1011
use core::marker::PhantomPinned;
1112
use core::ops::Deref;
1213
use core::pin::Pin;
13-
use core::sync::atomic::{AtomicBool, Ordering};
1414

1515
/// Declares that this type has some way to ensure that there is exactly one `ListArc` instance for
1616
/// this id.
@@ -469,7 +469,7 @@ where
469469
/// If the boolean is `false`, then there is no [`ListArc`] for this value.
470470
#[repr(transparent)]
471471
pub struct AtomicTracker<const ID: u64 = 0> {
472-
inner: AtomicBool,
472+
inner: Atomic<bool>,
473473
// This value needs to be pinned to justify the INVARIANT: comment in `AtomicTracker::new`.
474474
_pin: PhantomPinned,
475475
}
@@ -480,12 +480,12 @@ impl<const ID: u64> AtomicTracker<ID> {
480480
// INVARIANT: Pin-init initializers can't be used on an existing `Arc`, so this value will
481481
// not be constructed in an `Arc` that already has a `ListArc`.
482482
Self {
483-
inner: AtomicBool::new(false),
483+
inner: Atomic::new(false),
484484
_pin: PhantomPinned,
485485
}
486486
}
487487

488-
fn project_inner(self: Pin<&mut Self>) -> &mut AtomicBool {
488+
fn project_inner(self: Pin<&mut Self>) -> &mut Atomic<bool> {
489489
// SAFETY: The `inner` field is not structurally pinned, so we may obtain a mutable
490490
// reference to it even if we only have a pinned reference to `self`.
491491
unsafe { &mut Pin::into_inner_unchecked(self).inner }
@@ -500,7 +500,7 @@ impl<const ID: u64> ListArcSafe<ID> for AtomicTracker<ID> {
500500

501501
unsafe fn on_drop_list_arc(&self) {
502502
// 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);
504504
}
505505
}
506506

@@ -514,8 +514,6 @@ unsafe impl<const ID: u64> TryNewListArc<ID> for AtomicTracker<ID> {
514514
fn try_new_list_arc(&self) -> bool {
515515
// INVARIANT: If this method returns true, then the boolean used to be false, and is no
516516
// 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()
520518
}
521519
}

0 commit comments

Comments
 (0)