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
1 changed files with 8 additions and 2 deletions
|
@ -24,8 +24,14 @@ impl SameMutexCheck {
|
||||||
}
|
}
|
||||||
pub fn verify(&self, mutex: &MovableMutex) {
|
pub fn verify(&self, mutex: &MovableMutex) {
|
||||||
let addr = mutex.raw() as *const imp::Mutex as *const () as *mut _;
|
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
|
Ok(_) => {} // Stored the address
|
||||||
Err(n) if n == addr => {} // Lost a race to store the same address
|
Err(n) if n == addr => {} // Lost a race to store the same address
|
||||||
_ => panic!("attempted to use a condition variable with two mutexes"),
|
_ => panic!("attempted to use a condition variable with two mutexes"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue