Skip to content

Commit

Permalink
Linux/Android: Use once_cell::race::OnceBool.
Browse files Browse the repository at this point in the history
Now lazy.rs is no longer needed.
  • Loading branch information
briansmith committed Jun 19, 2024
1 parent da4b092 commit de49003
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude = [".*"]
cfg-if = "1"
once_cell = { version = "1.19.0", default-features = false, optional = true }

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

# When built as part of libstd
Expand Down
66 changes: 0 additions & 66 deletions src/lazy.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ use crate::util::{slice_as_uninit_mut, slice_assume_init_mut};
use core::mem::MaybeUninit;

mod error;
mod lazy;
mod util;
// To prevent a breaking change when targets are added, we always export the
// register_custom_getrandom macro, so old Custom RNG crates continue to build.
Expand Down
7 changes: 4 additions & 3 deletions src/linux_android_with_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Implementation for Linux / Android with `/dev/urandom` fallback
use crate::{lazy::LazyBool, linux_android, use_file, util_libc::last_os_error, Error};
use crate::{linux_android, use_file, util_libc::last_os_error, Error};
use core::mem::MaybeUninit;
use once_cell::race::OnceBool;

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

0 comments on commit de49003

Please sign in to comment.