File tree 1 file changed +10
-11
lines changed 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -97,25 +97,24 @@ mod imp {
97
97
target_arch = "powerpc" ) ) ) ]
98
98
fn is_getrandom_available ( ) -> bool {
99
99
use sync:: atomic:: { AtomicBool , ATOMIC_BOOL_INIT , Ordering } ;
100
+ use sync:: { Once , ONCE_INIT } ;
100
101
101
- static GETRANDOM_CHECKED : AtomicBool = ATOMIC_BOOL_INIT ;
102
- static GETRANDOM_AVAILABLE : AtomicBool = ATOMIC_BOOL_INIT ;
102
+ static CHECKER : Once = ONCE_INIT ;
103
+ static AVAILABLE : AtomicBool = ATOMIC_BOOL_INIT ;
103
104
104
- if ! GETRANDOM_CHECKED . load ( Ordering :: Relaxed ) {
105
+ CHECKER . call_once ( || {
105
106
let mut buf: [ u8 ; 0 ] = [ ] ;
106
107
let result = getrandom ( & mut buf) ;
107
108
let available = if result == -1 {
108
- let err = errno ( ) as libc :: c_int ;
109
- err != libc:: ENOSYS
109
+ let err = io :: Error :: last_os_error ( ) . raw_os_error ( ) ;
110
+ err != Some ( libc:: ENOSYS )
110
111
} else {
111
112
true
112
113
} ;
113
- GETRANDOM_AVAILABLE . store ( available, Ordering :: Relaxed ) ;
114
- GETRANDOM_CHECKED . store ( true , Ordering :: Relaxed ) ;
115
- available
116
- } else {
117
- GETRANDOM_AVAILABLE . load ( Ordering :: Relaxed )
118
- }
114
+ AVAILABLE . store ( available, Ordering :: Relaxed ) ;
115
+ } ) ;
116
+
117
+ AVAILABLE . load ( Ordering :: Relaxed )
119
118
}
120
119
121
120
#[ cfg( not( all( target_os = "linux" ,
You can’t perform that action at this time.
0 commit comments