diff --git a/Cargo.toml b/Cargo.toml
index 0fb973214..07df10971 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ log = { version = "0.4", optional = true }
[target.'cfg(unix)'.dependencies]
libc = "0.2.29"
+lazy_static = "1.3.0"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.6", features = ["minwindef", "ntsecapi", "winnt"] }
@@ -32,9 +33,13 @@ cloudabi = "0.0.3"
[target.'cfg(fuchsia)'.dependencies]
fuchsia-cprng = "0.1"
+[target.'cfg(target_os = "redox")'.dependencies]
+lazy_static = "1.3.0"
+
[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.29", optional = true }
stdweb = { version = "0.4.9", optional = true }
+lazy_static = "1.3.0"
[target.wasm32-wasi.dependencies]
libc = "0.2.54"
diff --git a/src/lib.rs b/src/lib.rs
index c92c45aa9..0132c1506 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -132,20 +132,8 @@ macro_rules! error { ($($x:tt)*) => () }
#[cfg(target_arch = "wasm32")]
extern crate std;
-#[cfg(any(
- target_os = "android",
- target_os = "netbsd",
- target_os = "solaris",
- target_os = "illumos",
- target_os = "redox",
- target_os = "dragonfly",
- target_os = "haiku",
- target_os = "linux",
- all(
- target_arch = "wasm32",
- not(target_os = "wasi")
- ),
-))]
+#[cfg(any(unix, target_os = "redox"))]
+#[allow(unused)]
mod utils;
mod error;
pub use crate::error::Error;
diff --git a/src/linux_android.rs b/src/linux_android.rs
index 1b7280df9..40b1f0f04 100644
--- a/src/linux_android.rs
+++ b/src/linux_android.rs
@@ -9,25 +9,30 @@
//! Implementation for Linux / Android
extern crate std;
-use crate::Error;
-use crate::utils::use_init;
-use std::{thread_local, io::{self, Read}, fs::File};
-use core::cell::RefCell;
+use crate::{utils::use_file, Error};
use core::num::NonZeroU32;
-use core::sync::atomic::{AtomicBool, Ordering};
+use std::io;
+use lazy_static::lazy_static;
// This flag tells getrandom() to return EAGAIN instead of blocking.
const GRND_NONBLOCK: libc::c_uint = 0x0001;
-static RNG_INIT: AtomicBool = AtomicBool::new(false);
enum RngSource {
GetRandom,
- Device(File),
+ File,
}
-thread_local!(
- static RNG_SOURCE: RefCell