File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -142,11 +142,11 @@ extern crate std;
142
142
143
143
mod error;
144
144
pub use crate :: error:: Error ;
145
+
145
146
#[ allow( dead_code) ]
146
147
mod util;
147
-
148
- // These targets need weak linkage to libc randomness functions.
149
- #[ cfg( any( target_os = "macos" , target_os = "solaris" , target_os = "illumos" ) ) ]
148
+ #[ cfg( any( unix, target_os = "redox" ) ) ]
149
+ #[ allow( dead_code) ]
150
150
mod util_libc;
151
151
152
152
// System-specific implementations.
Original file line number Diff line number Diff line change @@ -36,3 +36,27 @@ impl Weak {
36
36
NonNull :: new ( addr as * mut _ )
37
37
}
38
38
}
39
+
40
+ pub struct LazyFd ( LazyUsize ) ;
41
+
42
+ impl LazyFd {
43
+ pub const fn new ( ) -> Self {
44
+ Self ( LazyUsize :: new ( ) )
45
+ }
46
+
47
+ pub fn init ( & self , init : impl FnOnce ( ) -> Option < libc:: c_int > ) -> Option < libc:: c_int > {
48
+ let fd = self . 0 . sync_init (
49
+ || match init ( ) {
50
+ Some ( val) => val as usize ,
51
+ None => LazyUsize :: UNINIT ,
52
+ } ,
53
+ || unsafe {
54
+ libc:: usleep ( 1000 ) ;
55
+ } ,
56
+ ) ;
57
+ match fd {
58
+ LazyUsize :: UNINIT => None ,
59
+ val => Some ( val as libc:: c_int ) ,
60
+ }
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments