Skip to content

Commit 6f23e20

Browse files
committed
feat: use proper cache lines based on arch
1 parent 4d1f36f commit 6f23e20

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,43 @@ use std::sync::Arc;
3939
use std::sync::atomic::{AtomicUsize, Ordering};
4040

4141
/// Padding to prevent false sharing
42-
#[repr(C, align(64))]
42+
#[cfg_attr(
43+
any(
44+
target_arch = "x86_64",
45+
target_arch = "aarch64",
46+
target_arch = "arm64ec",
47+
target_arch = "powerpc64",
48+
),
49+
repr(C, align(128))
50+
)]
51+
#[cfg_attr(
52+
any(
53+
target_arch = "arm",
54+
target_arch = "mips",
55+
target_arch = "mips32r6",
56+
target_arch = "mips64",
57+
target_arch = "mips64r6",
58+
target_arch = "sparc",
59+
target_arch = "hexagon",
60+
),
61+
repr(C, align(32))
62+
)]
63+
#[cfg_attr(
64+
not(any(
65+
target_arch = "x86_64",
66+
target_arch = "aarch64",
67+
target_arch = "arm64ec",
68+
target_arch = "powerpc64",
69+
target_arch = "arm",
70+
target_arch = "mips",
71+
target_arch = "mips32r6",
72+
target_arch = "mips64",
73+
target_arch = "mips64r6",
74+
target_arch = "sparc",
75+
target_arch = "hexagon",
76+
)),
77+
repr(C, align(64))
78+
)]
4379
struct CachePadded<T>(T);
4480

4581
/// A fast lock-free single-producer, single-consumer queue

0 commit comments

Comments
 (0)