Relax memory ordering of operations within the test CountingAlloc

This commit is contained in:
Loïc Lecrenier 2022-11-24 09:29:10 +01:00
parent 8d0ace2d64
commit 8284bd760f

View File

@ -1395,14 +1395,14 @@ mod test {
} }
unsafe impl GlobalAlloc for CountingAlloc { unsafe impl GlobalAlloc for CountingAlloc {
unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 { unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {
self.allocated.fetch_add(layout.size() as i64, atomic::Ordering::SeqCst); self.allocated.fetch_add(layout.size() as i64, atomic::Ordering::Relaxed);
self.resident.fetch_add(layout.size() as i64, atomic::Ordering::SeqCst); self.resident.fetch_add(layout.size() as i64, atomic::Ordering::Relaxed);
System.alloc(layout) System.alloc(layout)
} }
unsafe fn dealloc(&self, ptr: *mut u8, layout: std::alloc::Layout) { unsafe fn dealloc(&self, ptr: *mut u8, layout: std::alloc::Layout) {
self.resident.fetch_sub(layout.size() as i64, atomic::Ordering::SeqCst); self.resident.fetch_sub(layout.size() as i64, atomic::Ordering::Relaxed);
System.dealloc(ptr, layout) System.dealloc(ptr, layout)
} }
} }