mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
chore: use std::AtomicPtr and std::AtomicU8 (#5071)
This commit is contained in:
@@ -1,34 +0,0 @@
|
|||||||
use std::fmt;
|
|
||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
|
|
||||||
/// `AtomicPtr` providing an additional `load_unsync` function.
|
|
||||||
pub(crate) struct AtomicPtr<T> {
|
|
||||||
inner: std::sync::atomic::AtomicPtr<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> AtomicPtr<T> {
|
|
||||||
pub(crate) fn new(ptr: *mut T) -> AtomicPtr<T> {
|
|
||||||
let inner = std::sync::atomic::AtomicPtr::new(ptr);
|
|
||||||
AtomicPtr { inner }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for AtomicPtr<T> {
|
|
||||||
type Target = std::sync::atomic::AtomicPtr<T>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> DerefMut for AtomicPtr<T> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> fmt::Debug for AtomicPtr<T> {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.deref().fmt(fmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ use std::cell::UnsafeCell;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// `AtomicU16` providing an additional `load_unsync` function.
|
/// `AtomicU16` providing an additional `unsync_load` function.
|
||||||
pub(crate) struct AtomicU16 {
|
pub(crate) struct AtomicU16 {
|
||||||
inner: UnsafeCell<std::sync::atomic::AtomicU16>,
|
inner: UnsafeCell<std::sync::atomic::AtomicU16>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::cell::UnsafeCell;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// `AtomicU32` providing an additional `load_unsync` function.
|
/// `AtomicU32` providing an additional `unsync_load` function.
|
||||||
pub(crate) struct AtomicU32 {
|
pub(crate) struct AtomicU32 {
|
||||||
inner: UnsafeCell<std::sync::atomic::AtomicU32>,
|
inner: UnsafeCell<std::sync::atomic::AtomicU32>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
use std::cell::UnsafeCell;
|
|
||||||
use std::fmt;
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
/// `AtomicU8` providing an additional `load_unsync` function.
|
|
||||||
pub(crate) struct AtomicU8 {
|
|
||||||
inner: UnsafeCell<std::sync::atomic::AtomicU8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for AtomicU8 {}
|
|
||||||
unsafe impl Sync for AtomicU8 {}
|
|
||||||
|
|
||||||
impl AtomicU8 {
|
|
||||||
pub(crate) const fn new(val: u8) -> AtomicU8 {
|
|
||||||
let inner = UnsafeCell::new(std::sync::atomic::AtomicU8::new(val));
|
|
||||||
AtomicU8 { inner }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for AtomicU8 {
|
|
||||||
type Target = std::sync::atomic::AtomicU8;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
// safety: it is always safe to access `&self` fns on the inner value as
|
|
||||||
// we never perform unsafe mutations.
|
|
||||||
unsafe { &*self.inner.get() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for AtomicU8 {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.deref().fmt(fmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ use std::cell::UnsafeCell;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
|
||||||
/// `AtomicUsize` providing an additional `load_unsync` function.
|
/// `AtomicUsize` providing an additional `unsync_load` function.
|
||||||
pub(crate) struct AtomicUsize {
|
pub(crate) struct AtomicUsize {
|
||||||
inner: UnsafeCell<std::sync::atomic::AtomicUsize>,
|
inner: UnsafeCell<std::sync::atomic::AtomicUsize>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#![cfg_attr(any(not(feature = "full"), loom), allow(unused_imports, dead_code))]
|
#![cfg_attr(any(not(feature = "full"), loom), allow(unused_imports, dead_code))]
|
||||||
|
|
||||||
mod atomic_ptr;
|
|
||||||
mod atomic_u16;
|
mod atomic_u16;
|
||||||
mod atomic_u32;
|
mod atomic_u32;
|
||||||
mod atomic_u64;
|
mod atomic_u64;
|
||||||
mod atomic_u8;
|
|
||||||
mod atomic_usize;
|
mod atomic_usize;
|
||||||
mod mutex;
|
mod mutex;
|
||||||
#[cfg(feature = "parking_lot")]
|
#[cfg(feature = "parking_lot")]
|
||||||
@@ -71,14 +69,12 @@ pub(crate) mod sync {
|
|||||||
pub(crate) use crate::loom::std::mutex::Mutex;
|
pub(crate) use crate::loom::std::mutex::Mutex;
|
||||||
|
|
||||||
pub(crate) mod atomic {
|
pub(crate) mod atomic {
|
||||||
pub(crate) use crate::loom::std::atomic_ptr::AtomicPtr;
|
|
||||||
pub(crate) use crate::loom::std::atomic_u16::AtomicU16;
|
pub(crate) use crate::loom::std::atomic_u16::AtomicU16;
|
||||||
pub(crate) use crate::loom::std::atomic_u32::AtomicU32;
|
pub(crate) use crate::loom::std::atomic_u32::AtomicU32;
|
||||||
pub(crate) use crate::loom::std::atomic_u64::AtomicU64;
|
pub(crate) use crate::loom::std::atomic_u64::AtomicU64;
|
||||||
pub(crate) use crate::loom::std::atomic_u8::AtomicU8;
|
|
||||||
pub(crate) use crate::loom::std::atomic_usize::AtomicUsize;
|
pub(crate) use crate::loom::std::atomic_usize::AtomicUsize;
|
||||||
|
|
||||||
pub(crate) use std::sync::atomic::{fence, AtomicBool, Ordering};
|
pub(crate) use std::sync::atomic::{fence, AtomicBool, AtomicPtr, AtomicU8, Ordering};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user