@@ -3,6 +3,8 @@ use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
3
3
use crate :: os:: windows:: prelude:: * ;
4
4
use crate :: path:: Path ;
5
5
use crate :: random:: { DefaultRandomSource , Random } ;
6
+ use crate :: sync:: atomic:: AtomicUsize ;
7
+ use crate :: sync:: atomic:: Ordering :: Relaxed ;
6
8
use crate :: sys:: c;
7
9
use crate :: sys:: fs:: { File , OpenOptions } ;
8
10
use crate :: sys:: handle:: Handle ;
@@ -78,7 +80,7 @@ pub fn anon_pipe(ours_readable: bool, their_handle_inheritable: bool) -> io::Res
78
80
name = format ! (
79
81
r"\\.\pipe\__rust_anonymous_pipe1__.{}.{}" ,
80
82
c:: GetCurrentProcessId ( ) ,
81
- usize :: random ( & mut DefaultRandomSource ) ,
83
+ random_number ( ) ,
82
84
) ;
83
85
let wide_name = OsStr :: new ( & name) . encode_wide ( ) . chain ( Some ( 0 ) ) . collect :: < Vec < _ > > ( ) ;
84
86
let mut flags = c:: FILE_FLAG_FIRST_PIPE_INSTANCE | c:: FILE_FLAG_OVERLAPPED ;
@@ -206,6 +208,17 @@ pub fn spawn_pipe_relay(
206
208
Ok ( theirs)
207
209
}
208
210
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
+
209
222
impl AnonPipe {
210
223
pub fn handle ( & self ) -> & Handle {
211
224
& self . inner
0 commit comments