SeqCst->Relaxed in pal::windows::pipe.

Relaxed is enough to ensure fetch_add(1) returns each integer exactly
once.
This commit is contained in:
Mara Bos 2024-03-19 15:05:46 +01:00
parent 46bb073423
commit 60ad49005a

View File

@ -7,7 +7,7 @@ use crate::path::Path;
use crate::ptr;
use crate::slice;
use crate::sync::atomic::AtomicUsize;
use crate::sync::atomic::Ordering::SeqCst;
use crate::sync::atomic::Ordering::Relaxed;
use crate::sys::c;
use crate::sys::fs::{File, OpenOptions};
use crate::sys::handle::Handle;
@ -214,11 +214,11 @@ pub fn spawn_pipe_relay(
fn random_number() -> usize {
static N: AtomicUsize = AtomicUsize::new(0);
loop {
if N.load(SeqCst) != 0 {
return N.fetch_add(1, SeqCst);
if N.load(Relaxed) != 0 {
return N.fetch_add(1, Relaxed);
}
N.store(hashmap_random_keys().0 as usize, SeqCst);
N.store(hashmap_random_keys().0 as usize, Relaxed);
}
}