Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warnings for atomics initialization #739

Merged
merged 1 commit into from Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion rand_jitter/src/lib.rs
Expand Up @@ -75,7 +75,10 @@ pub use error::TimerError;

use core::{fmt, mem, ptr};
#[cfg(feature = "std")]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
#[cfg(feature = "std")]
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use std::sync::atomic::ATOMIC_USIZE_INIT;

const MEMORY_BLOCKS: usize = 64;
const MEMORY_BLOCKSIZE: usize = 32;
Expand Down Expand Up @@ -167,6 +170,7 @@ impl Clone for JitterRng {

// Initialise to zero; must be positive
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
#[allow(deprecated)]
static JITTER_ROUNDS: AtomicUsize = ATOMIC_USIZE_INIT;

impl JitterRng {
Expand Down
6 changes: 5 additions & 1 deletion rand_os/src/linux_android.rs
Expand Up @@ -18,7 +18,9 @@ use std::io;
use std::io::Read;
use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use std::sync::atomic::{AtomicBool, Ordering};
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use std::sync::atomic::ATOMIC_BOOL_INIT;
use std::sync::{Once, ONCE_INIT};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -53,6 +55,7 @@ impl OsRngImpl for OsRng {
fn test_initialized(&mut self, dest: &mut [u8], blocking: bool)
-> Result<usize, Error>
{
#[allow(deprecated)]
static OS_RNG_INITIALIZED: AtomicBool = ATOMIC_BOOL_INIT;
if !self.initialized {
self.initialized = OS_RNG_INITIALIZED.load(Ordering::Relaxed);
Expand Down Expand Up @@ -160,6 +163,7 @@ fn getrandom_try_fill(dest: &mut [u8], blocking: bool) -> Result<(), Error> {

fn is_getrandom_available() -> bool {
static CHECKER: Once = ONCE_INIT;
#[allow(deprecated)]
static AVAILABLE: AtomicBool = ATOMIC_BOOL_INIT;

if NR_GETRANDOM == 0 { return false };
Expand Down
5 changes: 4 additions & 1 deletion rand_os/src/netbsd.rs
Expand Up @@ -14,7 +14,9 @@ use super::OsRngImpl;

use std::fs::File;
use std::io::Read;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use std::sync::atomic::{AtomicBool, Ordering};
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use std::sync::atomic::ATOMIC_BOOL_INIT;

#[derive(Clone, Debug)]
pub struct OsRng { initialized: bool }
Expand All @@ -34,6 +36,7 @@ impl OsRngImpl for OsRng {
fn test_initialized(&mut self, dest: &mut [u8], _blocking: bool)
-> Result<usize, Error>
{
#[allow(deprecated)]
static OS_RNG_INITIALIZED: AtomicBool = ATOMIC_BOOL_INIT;
if !self.initialized {
self.initialized = OS_RNG_INITIALIZED.load(Ordering::Relaxed);
Expand Down
5 changes: 4 additions & 1 deletion rand_os/src/solarish.rs
Expand Up @@ -28,7 +28,9 @@ use std::io;
use std::io::Read;
use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering, AtomicUsize};
use std::sync::atomic::{AtomicBool, Ordering, AtomicUsize};
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use std::sync::atomic::ATOMIC_BOOL_INIT;
use std::cmp;
use std::mem;

Expand Down Expand Up @@ -68,6 +70,7 @@ impl OsRngImpl for OsRng {
fn test_initialized(&mut self, dest: &mut [u8], blocking: bool)
-> Result<usize, Error>
{
#[allow(deprecated)]
static OS_RNG_INITIALIZED: AtomicBool = ATOMIC_BOOL_INIT;
if !self.initialized {
self.initialized = OS_RNG_INITIALIZED.load(Ordering::Relaxed);
Expand Down
7 changes: 5 additions & 2 deletions src/rngs/adapter/reseeding.rs
Expand Up @@ -286,8 +286,9 @@ where R: BlockRngCore + SeedableRng + CryptoRng,
mod fork {
extern crate libc;

use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use core::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT};
use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
use core::sync::atomic::{ATOMIC_USIZE_INIT, ATOMIC_BOOL_INIT};

// Fork protection
//
Expand All @@ -301,12 +302,14 @@ mod fork {
// don't update `fork_counter`, so a reseed is attempted as soon as
// possible.

#[allow(deprecated)]
static RESEEDING_RNG_FORK_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;

pub fn get_fork_counter() -> usize {
RESEEDING_RNG_FORK_COUNTER.load(Ordering::Relaxed)
}

#[allow(deprecated)]
static FORK_HANDLER_REGISTERED: AtomicBool = ATOMIC_BOOL_INIT;

extern fn fork_handler() {
Expand Down