@@ -67,31 +67,6 @@ extern "system" {
67
67
fn WaitForSingleObject ( hHandle : HANDLE , dwMilliseconds : DWORD ) -> DWORD ;
68
68
}
69
69
70
- #[ link( name = "advapi32" ) ]
71
- extern "system" {
72
- #[ link_name = "SystemFunction036" ]
73
- fn RtlGenRandom ( RandomBuffer : * mut u8 , RandomBufferLength : u32 ) -> u8 ;
74
- }
75
-
76
- // Note that we ideally would use the `getrandom` crate, but unfortunately
77
- // that causes build issues when this crate is used in rust-lang/rust (see
78
- // rust-lang/rust#65014 for more information). As a result we just inline
79
- // the pretty simple Windows-specific implementation of generating
80
- // randomness.
81
- fn getrandom ( dest : & mut [ u8 ] ) -> io:: Result < ( ) > {
82
- // Prevent overflow of u32
83
- for chunk in dest. chunks_mut ( u32:: MAX as usize ) {
84
- let ret = unsafe { RtlGenRandom ( chunk. as_mut_ptr ( ) , chunk. len ( ) as u32 ) } ;
85
- if ret == 0 {
86
- return Err ( io:: Error :: new (
87
- io:: ErrorKind :: Other ,
88
- "failed to generate random bytes" ,
89
- ) ) ;
90
- }
91
- }
92
- Ok ( ( ) )
93
- }
94
-
95
70
impl Client {
96
71
pub fn new ( limit : usize ) -> io:: Result < Client > {
97
72
// Try a bunch of random semaphore names until we get a unique one,
@@ -103,9 +78,8 @@ impl Client {
103
78
// slot and then immediately acquire it (without ever releaseing it
104
79
// back).
105
80
for _ in 0 ..100 {
106
- let mut bytes = [ 0 ; 4 ] ;
107
- getrandom ( & mut bytes) ?;
108
- let mut name = format ! ( "__rust_jobserver_semaphore_{}\0 " , u32 :: from_ne_bytes( bytes) ) ;
81
+ let bytes = getrandom:: u32 ( ) ?;
82
+ let mut name = format ! ( "__rust_jobserver_semaphore_{}\0 " , bytes) ;
109
83
unsafe {
110
84
let create_limit = if limit == 0 { 1 } else { limit } ;
111
85
let r = CreateSemaphoreA (
0 commit comments