mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #96619 - akiekintveld:same_mutex_check_relaxed_ordering, r=m-ou-se
Relax memory ordering used in SameMutexCheck `SameMutexCheck` only requires atomicity for `self.addr`, but does not need ordering of other memory accesses in either the success or failure case. Using `Relaxed`, the code still correctly handles the case when two threads race to store an address.
This commit is contained in:
commit
b792258b32
@ -24,8 +24,14 @@ impl SameMutexCheck {
|
||||
}
|
||||
pub fn verify(&self, mutex: &MovableMutex) {
|
||||
let addr = mutex.raw() as *const imp::Mutex as *const () as *mut _;
|
||||
match self.addr.compare_exchange(ptr::null_mut(), addr, Ordering::SeqCst, Ordering::SeqCst)
|
||||
{
|
||||
// Relaxed is okay here because we never read through `self.addr`, and only use it to
|
||||
// compare addresses.
|
||||
match self.addr.compare_exchange(
|
||||
ptr::null_mut(),
|
||||
addr,
|
||||
Ordering::Relaxed,
|
||||
Ordering::Relaxed,
|
||||
) {
|
||||
Ok(_) => {} // Stored the address
|
||||
Err(n) if n == addr => {} // Lost a race to store the same address
|
||||
_ => panic!("attempted to use a condition variable with two mutexes"),
|
||||
|
Loading…
Reference in New Issue
Block a user