Struct maitake::sync::util::CachePadded
source · #[repr(align(128))]pub struct CachePadded<T>(/* private fields */);
Expand description
Aligns the wrapped value to the size of a cache line.
This is used to avoid false sharing for values that may be accessed concurrently.
§Size/Alignment
The size and alignment of this type depends on the target architecture,
and on whether or not the no-cache-pad
feature flag is enabled.
When the no-cache-pad
crate feature flag is enabled, this is simply a
no-op wrapper struct. This is intended for use on useful for platforms
with no data cache, such as many Cortex-M targets.
In other cases, this type is always aligned to the size of a cache line,
based on the target architecture. On x86_64
/aarch64
, a cache line is
128 bytes. On all other targets, a cache line is assumed to 64 bytes
long. This type’s size will always be a multiple of the cache line size;
if the wrapped type is longer than the alignment of a cache line, then
this type will be padded to multiple cache lines.
Implementations§
source§impl<T> CachePadded<T>
impl<T> CachePadded<T>
sourcepub const fn new(value: T) -> CachePadded<T>
pub const fn new(value: T) -> CachePadded<T>
Pads value
to the length of a cache line.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the inner value and returns it.
Trait Implementations§
source§impl<T> Clone for CachePadded<T>where
T: Clone,
impl<T> Clone for CachePadded<T>where
T: Clone,
source§fn clone(&self) -> CachePadded<T>
fn clone(&self) -> CachePadded<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T> Debug for CachePadded<T>where
T: Debug,
impl<T> Debug for CachePadded<T>where
T: Debug,
source§impl<T> Default for CachePadded<T>where
T: Default,
impl<T> Default for CachePadded<T>where
T: Default,
source§fn default() -> CachePadded<T>
fn default() -> CachePadded<T>
source§impl<T> Deref for CachePadded<T>
impl<T> Deref for CachePadded<T>
source§impl<T> DerefMut for CachePadded<T>
impl<T> DerefMut for CachePadded<T>
source§impl<T> Hash for CachePadded<T>where
T: Hash,
impl<T> Hash for CachePadded<T>where
T: Hash,
source§impl<T> PartialEq for CachePadded<T>where
T: PartialEq,
impl<T> PartialEq for CachePadded<T>where
T: PartialEq,
impl<T> Copy for CachePadded<T>where
T: Copy,
impl<T> Eq for CachePadded<T>where
T: Eq,
impl<T> StructuralPartialEq for CachePadded<T>
Auto Trait Implementations§
impl<T> Freeze for CachePadded<T>where
T: Freeze,
impl<T> RefUnwindSafe for CachePadded<T>where
T: RefUnwindSafe,
impl<T> Send for CachePadded<T>where
T: Send,
impl<T> Sync for CachePadded<T>where
T: Sync,
impl<T> Unpin for CachePadded<T>where
T: Unpin,
impl<T> UnwindSafe for CachePadded<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)