@@ -3,6 +3,8 @@ use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
33use crate :: os:: windows:: prelude:: * ;
44use crate :: path:: Path ;
55use crate :: random:: { DefaultRandomSource , Random } ;
6+ use crate :: sync:: atomic:: AtomicUsize ;
7+ use crate :: sync:: atomic:: Ordering :: Relaxed ;
68use crate :: sys:: c;
79use crate :: sys:: fs:: { File , OpenOptions } ;
810use crate :: sys:: handle:: Handle ;
@@ -78,7 +80,7 @@ pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Res
7880 name = format ! (
7981 r"\\.\pipe\__rust_anonymous_pipe1__.{}.{}" ,
8082 c:: GetCurrentProcessId ( ) ,
81- usize :: random ( & mut DefaultRandomSource ) ,
83+ random_number ( ) ,
8284 ) ;
8385 let wide_name = OsStr :: new ( & name) . encode_wide ( ) . chain ( Some ( 0 ) ) . collect :: < Vec < _ > > ( ) ;
8486 let mut flags = c:: FILE_FLAG_FIRST_PIPE_INSTANCE | c:: FILE_FLAG_OVERLAPPED ;
@@ -206,6 +208,17 @@ pub fn spawn_pipe_relay(
206208 Ok ( theirs)
207209}
208210
211+ fn random_number ( ) -> usize {
212+ static N : AtomicUsize = AtomicUsize :: new ( 0 ) ;
213+ loop {
214+ if N . load ( Relaxed ) != 0 {
215+ return N . fetch_add ( 1 , Relaxed ) ;
216+ }
217+
218+ N . store ( usize:: random ( & mut DefaultRandomSource ) , Relaxed ) ;
219+ }
220+ }
221+
209222impl AnonPipe {
210223 pub fn handle ( & self ) -> & Handle {
211224 & self . inner
0 commit comments