diff options
| author | Christopher Durham <cad97@cad97.com> | 2024-09-19 00:15:03 -0400 |
|---|---|---|
| committer | Pavel Grigorenko <GrigorenkoPV@ya.ru> | 2025-04-27 02:18:08 +0300 |
| commit | 4d93f6056824c338751f19356d33bb61ce818749 (patch) | |
| tree | 44c5e3f9da28279a1e391f19ea6367677bf0adfa /library/std/src/sync/mpmc | |
| parent | 96b4ed90c658acf7f180bf1b95192b4f08802059 (diff) | |
| download | rust-4d93f6056824c338751f19356d33bb61ce818749.tar.gz rust-4d93f6056824c338751f19356d33bb61ce818749.zip | |
use generic Atomic type where possible
in core/alloc/std only for now, and ignoring test files Co-authored-by: Pavel Grigorenko <GrigorenkoPV@ya.ru>
Diffstat (limited to 'library/std/src/sync/mpmc')
| -rw-r--r-- | library/std/src/sync/mpmc/array.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sync/mpmc/context.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sync/mpmc/counter.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sync/mpmc/list.rs | 14 | ||||
| -rw-r--r-- | library/std/src/sync/mpmc/waker.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sync/mpmc/zero.rs | 4 |
6 files changed, 22 insertions, 22 deletions
diff --git a/library/std/src/sync/mpmc/array.rs b/library/std/src/sync/mpmc/array.rs index a467237fef1..880d8b5f57c 100644 --- a/library/std/src/sync/mpmc/array.rs +++ b/library/std/src/sync/mpmc/array.rs @@ -16,13 +16,13 @@ use super::waker::SyncWaker; use crate::cell::UnsafeCell; use crate::mem::MaybeUninit; use crate::ptr; -use crate::sync::atomic::{self, AtomicUsize, Ordering}; +use crate::sync::atomic::{self, Atomic, AtomicUsize, Ordering}; use crate::time::Instant; /// A slot in a channel. struct Slot<T> { /// The current stamp. - stamp: AtomicUsize, + stamp: Atomic<usize>, /// The message in this slot. Either read out in `read` or dropped through /// `discard_all_messages`. @@ -55,7 +55,7 @@ pub(crate) struct Channel<T> { /// represent the lap. The mark bit in the head is always zero. /// /// Messages are popped from the head of the channel. - head: CachePadded<AtomicUsize>, + head: CachePadded<Atomic<usize>>, /// The tail of the channel. /// @@ -64,7 +64,7 @@ pub(crate) struct Channel<T> { /// represent the lap. The mark bit indicates that the channel is disconnected. /// /// Messages are pushed into the tail of the channel. - tail: CachePadded<AtomicUsize>, + tail: CachePadded<Atomic<usize>>, /// The buffer holding slots. buffer: Box<[Slot<T>]>, diff --git a/library/std/src/sync/mpmc/context.rs b/library/std/src/sync/mpmc/context.rs index 51aa7e82e78..6b2f4cb6ffd 100644 --- a/library/std/src/sync/mpmc/context.rs +++ b/library/std/src/sync/mpmc/context.rs @@ -5,7 +5,7 @@ use super::waker::current_thread_id; use crate::cell::Cell; use crate::ptr; use crate::sync::Arc; -use crate::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; +use crate::sync::atomic::{Atomic, AtomicPtr, AtomicUsize, Ordering}; use crate::thread::{self, Thread}; use crate::time::Instant; @@ -19,10 +19,10 @@ pub struct Context { #[derive(Debug)] struct Inner { /// Selected operation. - select: AtomicUsize, + select: Atomic<usize>, /// A slot into which another thread may store a pointer to its `Packet`. - packet: AtomicPtr<()>, + packet: Atomic<*mut ()>, /// Thread handle. thread: Thread, diff --git a/library/std/src/sync/mpmc/counter.rs b/library/std/src/sync/mpmc/counter.rs index d1bfe612f53..efa6af11483 100644 --- a/library/std/src/sync/mpmc/counter.rs +++ b/library/std/src/sync/mpmc/counter.rs @@ -1,16 +1,16 @@ -use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use crate::sync::atomic::{Atomic, AtomicBool, AtomicUsize, Ordering}; use crate::{ops, process}; /// Reference counter internals. struct Counter<C> { /// The number of senders associated with the channel. - senders: AtomicUsize, + senders: Atomic<usize>, /// The number of receivers associated with the channel. - receivers: AtomicUsize, + receivers: Atomic<usize>, /// Set to `true` if the last sender or the last receiver reference deallocates the channel. - destroy: AtomicBool, + destroy: Atomic<bool>, /// The internal channel. chan: C, diff --git a/library/std/src/sync/mpmc/list.rs b/library/std/src/sync/mpmc/list.rs index 1c6acb29e37..3fcfb85cf2a 100644 --- a/library/std/src/sync/mpmc/list.rs +++ b/library/std/src/sync/mpmc/list.rs @@ -9,7 +9,7 @@ use crate::cell::UnsafeCell; use crate::marker::PhantomData; use crate::mem::MaybeUninit; use crate::ptr; -use crate::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}; +use crate::sync::atomic::{self, Atomic, AtomicPtr, AtomicUsize, Ordering}; use crate::time::Instant; // Bits indicating the state of a slot: @@ -37,7 +37,7 @@ struct Slot<T> { msg: UnsafeCell<MaybeUninit<T>>, /// The state of the slot. - state: AtomicUsize, + state: Atomic<usize>, } impl<T> Slot<T> { @@ -55,7 +55,7 @@ impl<T> Slot<T> { /// Each block in the list can hold up to `BLOCK_CAP` messages. struct Block<T> { /// The next block in the linked list. - next: AtomicPtr<Block<T>>, + next: Atomic<*mut Block<T>>, /// Slots for messages. slots: [Slot<T>; BLOCK_CAP], @@ -65,11 +65,11 @@ impl<T> Block<T> { /// Creates an empty block. fn new() -> Box<Block<T>> { // SAFETY: This is safe because: - // [1] `Block::next` (AtomicPtr) may be safely zero initialized. + // [1] `Block::next` (Atomic<*mut _>) may be safely zero initialized. // [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4]. // [3] `Slot::msg` (UnsafeCell) may be safely zero initialized because it // holds a MaybeUninit. - // [4] `Slot::state` (AtomicUsize) may be safely zero initialized. + // [4] `Slot::state` (Atomic<usize>) may be safely zero initialized. unsafe { Box::new_zeroed().assume_init() } } @@ -110,10 +110,10 @@ impl<T> Block<T> { #[derive(Debug)] struct Position<T> { /// The index in the channel. - index: AtomicUsize, + index: Atomic<usize>, /// The block in the linked list. - block: AtomicPtr<Block<T>>, + block: Atomic<*mut Block<T>>, } /// The token type for the list flavor. diff --git a/library/std/src/sync/mpmc/waker.rs b/library/std/src/sync/mpmc/waker.rs index f5e764e69bd..4216fb7ac59 100644 --- a/library/std/src/sync/mpmc/waker.rs +++ b/library/std/src/sync/mpmc/waker.rs @@ -4,7 +4,7 @@ use super::context::Context; use super::select::{Operation, Selected}; use crate::ptr; use crate::sync::Mutex; -use crate::sync::atomic::{AtomicBool, Ordering}; +use crate::sync::atomic::{Atomic, AtomicBool, Ordering}; /// Represents a thread blocked on a specific channel operation. pub(crate) struct Entry { @@ -137,7 +137,7 @@ pub(crate) struct SyncWaker { inner: Mutex<Waker>, /// `true` if the waker is empty. - is_empty: AtomicBool, + is_empty: Atomic<bool>, } impl SyncWaker { diff --git a/library/std/src/sync/mpmc/zero.rs b/library/std/src/sync/mpmc/zero.rs index 577997c07a6..f1ecf80fcb9 100644 --- a/library/std/src/sync/mpmc/zero.rs +++ b/library/std/src/sync/mpmc/zero.rs @@ -10,7 +10,7 @@ use super::waker::Waker; use crate::cell::UnsafeCell; use crate::marker::PhantomData; use crate::sync::Mutex; -use crate::sync::atomic::{AtomicBool, Ordering}; +use crate::sync::atomic::{Atomic, AtomicBool, Ordering}; use crate::time::Instant; use crate::{fmt, ptr}; @@ -35,7 +35,7 @@ struct Packet<T> { on_stack: bool, /// Equals `true` once the packet is ready for reading or writing. - ready: AtomicBool, + ready: Atomic<bool>, /// The message. msg: UnsafeCell<Option<T>>, |
