Skip to content

Commit 46bb382

Browse files
committed
Improve: Validate CacheAligned padding
1 parent 9982ad9 commit 46bb382

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ pub const DEFAULT_ALIGNMENT: usize = 128;
6666
#[derive(Clone, Copy, Debug, Default)]
6767
pub struct CacheAligned<T>(pub T);
6868

69+
// Compile-time assertion that alignment matches DEFAULT_ALIGNMENT
70+
const _: () = assert!(
71+
core::mem::align_of::<CacheAligned<u8>>() == DEFAULT_ALIGNMENT,
72+
"CacheAligned alignment must match DEFAULT_ALIGNMENT"
73+
);
74+
6975
/// A generic spin mutex that uses CPU-specific pause instructions for efficient busy-waiting.
7076
///
7177
/// This is a low-level synchronization primitive that spins on a busy loop rather than

0 commit comments

Comments
 (0)