Skip to content

Commit cdd0a1b

Browse files
committed
Linux/Android: Use once_cell::race::OnceBool.
After this, `lazy` is only used by netbsd. (`once_cell::race` doesn't have a `OncePtr`.)
1 parent e14e26e commit cdd0a1b

File tree

4 files changed

+6
-18
lines changed

4 files changed

+6
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude = [".*"]
1515
cfg-if = "1"
1616
once_cell = { version = "1.19.0", default-features = false, optional = true }
1717

18-
[target.'cfg(all(target_arch = "x86_64", target_env = "sgx"))'.dependencies]
18+
[target.'cfg(any(target_os = "android", target_os = "linux", all(target_arch = "x86_64", target_env = "sgx")))'.dependencies]
1919
once_cell = { version = "1.19.0", default-features = false, features = ["race"] }
2020

2121
# When built as part of libstd

src/lazy.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,6 @@ impl LazyUsize {
5555
}
5656
}
5757

58-
// Identical to LazyUsize except with bool instead of usize.
59-
pub(crate) struct LazyBool(LazyUsize);
60-
61-
impl LazyBool {
62-
pub const fn new() -> Self {
63-
Self(LazyUsize::new())
64-
}
65-
66-
pub fn unsync_init(&self, init: impl FnOnce() -> bool) -> bool {
67-
self.0.unsync_init(|| usize::from(init())) != 0
68-
}
69-
}
70-
7158
// This structure represents a lazily initialized static pointer value.
7259
///
7360
/// It's intended to be used for weak linking of a C function that may

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ use crate::util::{slice_as_uninit_mut, slice_assume_init_mut};
216216
use core::mem::MaybeUninit;
217217

218218
mod error;
219-
mod lazy;
220219
mod util;
221220
// To prevent a breaking change when targets are added, we always export the
222221
// register_custom_getrandom macro, so old Custom RNG crates continue to build.
@@ -308,6 +307,7 @@ cfg_if! {
308307
mod util_libc;
309308
#[path = "solaris.rs"] mod imp;
310309
} else if #[cfg(target_os = "netbsd")] {
310+
mod lazy;
311311
mod util_libc;
312312
#[path = "netbsd.rs"] mod imp;
313313
} else if #[cfg(target_os = "fuchsia")] {

src/linux_android_with_fallback.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Implementation for Linux / Android with `/dev/urandom` fallback
2-
use crate::{lazy::LazyBool, linux_android, use_file, util_libc::last_os_error, Error};
2+
use crate::{linux_android, use_file, util_libc::last_os_error, Error};
33
use core::mem::MaybeUninit;
4+
use once_cell::race::OnceBool;
45

56
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
67
// getrandom(2) was introduced in Linux 3.17
7-
static HAS_GETRANDOM: LazyBool = LazyBool::new();
8-
if HAS_GETRANDOM.unsync_init(is_getrandom_available) {
8+
static HAS_GETRANDOM: OnceBool = OnceBool::new();
9+
if HAS_GETRANDOM.get_or_init(is_getrandom_available) {
910
linux_android::getrandom_inner(dest)
1011
} else {
1112
use_file::getrandom_inner(dest)

0 commit comments

Comments
 (0)