Skip to content

Commit e08cb3e

Browse files
committed
Auto merge of #117519 - mj10021:issue-117470-fix, r=<try>
Add cache line size padding to RWLock Fixing issue #117470, this PR just copies the `cfg_attr` `repr` from the cache padding crate to stop RWLocks from sharing cache lines.
2 parents b20f40d + 1e43257 commit e08cb3e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

library/std/src/sync/rwlock.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,41 @@ use crate::sys::locks as sys;
7777
/// [`Mutex`]: super::Mutex
7878
#[stable(feature = "rust1", since = "1.0.0")]
7979
#[cfg_attr(not(test), rustc_diagnostic_item = "RwLock")]
80+
#[cfg_attr(
81+
any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64",),
82+
repr(align(128))
83+
)]
84+
#[cfg_attr(
85+
any(
86+
target_arch = "arm",
87+
target_arch = "mips",
88+
target_arch = "mips64",
89+
target_arch = "riscv32",
90+
target_arch = "riscv64",
91+
target_arch = "sparc",
92+
target_arch = "hexagon",
93+
),
94+
repr(align(32))
95+
)]
96+
#[cfg_attr(target_arch = "m68k", repr(align(16)))]
97+
#[cfg_attr(target_arch = "s390x", repr(align(256)))]
98+
#[cfg_attr(
99+
not(any(
100+
target_arch = "x86_64",
101+
target_arch = "aarch64",
102+
target_arch = "powerpc64",
103+
target_arch = "arm",
104+
target_arch = "mips",
105+
target_arch = "mips64",
106+
target_arch = "riscv32",
107+
target_arch = "riscv64",
108+
target_arch = "sparc",
109+
target_arch = "hexagon",
110+
target_arch = "m68k",
111+
target_arch = "s390x",
112+
)),
113+
repr(align(64))
114+
)]
80115
pub struct RwLock<T: ?Sized> {
81116
inner: sys::RwLock,
82117
poison: poison::Flag,

0 commit comments

Comments
 (0)