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:
Austin Kiekintveld 2022-05-01 16:46:19 -07:00 committed by GitHub
parent 4dd8b420c0
commit df4457e20b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ 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)
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