pub struct CacheAligned<T> { /* private fields */ }Expand description
Cache-line-aligned wrapper type for eliminating false sharing.
Wraps a value T and ensures it is aligned to a full cache line
boundary (64 bytes). When placed in arrays or adjacent to other
per-CPU data, this prevents false sharing between cores.
§Example
ⓘ
use crate::mm::cache_aligned::CacheAligned;
use core::sync::atomic::{AtomicU64, Ordering};
// Each counter occupies its own cache line
static COUNTERS: [CacheAligned<AtomicU64>; 4] = [
CacheAligned::new(AtomicU64::new(0)),
CacheAligned::new(AtomicU64::new(0)),
CacheAligned::new(AtomicU64::new(0)),
CacheAligned::new(AtomicU64::new(0)),
];Implementations§
Source§impl<T> CacheAligned<T>
impl<T> CacheAligned<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the wrapper and return the inner value.
Trait Implementations§
Source§impl<T: Clone> Clone for CacheAligned<T>
impl<T: Clone> Clone for CacheAligned<T>
Source§impl<T: Debug> Debug for CacheAligned<T>
impl<T: Debug> Debug for CacheAligned<T>
Source§impl<T: Default> Default for CacheAligned<T>
impl<T: Default> Default for CacheAligned<T>
Source§impl<T> DerefMut for CacheAligned<T>
impl<T> DerefMut for CacheAligned<T>
Source§impl<T> Deref for CacheAligned<T>
impl<T> Deref for CacheAligned<T>
impl<T: Copy> Copy for CacheAligned<T>
impl<T: Send> Send for CacheAligned<T>
impl<T: Sync> Sync for CacheAligned<T>
Auto Trait Implementations§
impl<T> Freeze for CacheAligned<T>where
T: Freeze,
impl<T> RefUnwindSafe for CacheAligned<T>where
T: RefUnwindSafe,
impl<T> Unpin for CacheAligned<T>where
T: Unpin,
impl<T> UnwindSafe for CacheAligned<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)