Skip to content

Commit

Permalink
Eliminate the lazy_static dev dependency (#2107)
Browse files Browse the repository at this point in the history
It's no longer needed, because for several versions now AtomicBool::new
and parking_lot::Mutex::new are const functions.

Fixes #1791
  • Loading branch information
asomers authored Aug 27, 2023
1 parent 56e1277 commit d59d235
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ zerocopy = ["fs", "uio"]

[dev-dependencies]
assert-impl = "0.1"
lazy_static = "1.4"
parking_lot = "0.12"
rand = "0.8"
tempfile = "3.7.1"
Expand Down
5 changes: 1 addition & 4 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,14 +1142,11 @@ pub fn aio_suspend(
/// # use std::sync::atomic::{AtomicBool, Ordering};
/// # use std::thread;
/// # use std::time;
/// # use lazy_static::lazy_static;
/// # use nix::errno::Errno;
/// # use nix::sys::aio::*;
/// # use nix::sys::signal::*;
/// # use tempfile::tempfile;
/// lazy_static! {
/// pub static ref SIGNALED: AtomicBool = AtomicBool::new(false);
/// }
/// pub static SIGNALED: AtomicBool = AtomicBool::new(false);
///
/// extern fn sigfunc(_: c_int) {
/// SIGNALED.store(true, Ordering::Relaxed);
Expand Down
5 changes: 1 addition & 4 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,10 @@ pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result<SigActi
/// Use a signal handler to set a flag variable:
///
/// ```no_run
/// # #[macro_use] extern crate lazy_static;
/// # use std::convert::TryFrom;
/// # use std::sync::atomic::{AtomicBool, Ordering};
/// # use nix::sys::signal::{self, Signal, SigHandler};
/// lazy_static! {
/// static ref SIGNALED: AtomicBool = AtomicBool::new(false);
/// }
/// static SIGNALED: AtomicBool = AtomicBool::new(false);
///
/// extern fn handle_sigint(signal: libc::c_int) {
/// let signal = Signal::try_from(signal).unwrap();
Expand Down
4 changes: 1 addition & 3 deletions test/sys/test_aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ use nix::{
};
use tempfile::tempfile;

lazy_static! {
pub static ref SIGNALED: AtomicBool = AtomicBool::new(false);
}
pub static SIGNALED: AtomicBool = AtomicBool::new(false);

extern "C" fn sigfunc(_: c_int) {
SIGNALED.store(true, Ordering::Relaxed);
Expand Down
4 changes: 1 addition & 3 deletions test/sys/test_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ fn test_sigprocmask() {
.expect("expect to be able to block signals");
}

lazy_static! {
static ref SIGNALED: AtomicBool = AtomicBool::new(false);
}
static SIGNALED: AtomicBool = AtomicBool::new(false);

extern "C" fn test_sigaction_handler(signal: libc::c_int) {
let signal = Signal::try_from(signal).unwrap();
Expand Down
36 changes: 16 additions & 20 deletions test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
extern crate cfg_if;
#[cfg_attr(not(any(target_os = "redox", target_os = "haiku")), macro_use)]
extern crate nix;
#[macro_use]
extern crate lazy_static;

mod common;
mod sys;
Expand Down Expand Up @@ -79,24 +77,22 @@ fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
}
}

lazy_static! {
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
/// working directory must grab it shared.
pub static ref CWD_LOCK: RwLock<()> = RwLock::new(());
/// Any test that creates child processes must grab this mutex, regardless
/// of what it does with those children.
pub static ref FORK_MTX: Mutex<()> = Mutex::new(());
/// Any test that changes the process's supplementary groups must grab this
/// mutex
pub static ref GROUPS_MTX: Mutex<()> = Mutex::new(());
/// Any tests that loads or unloads kernel modules must grab this mutex
pub static ref KMOD_MTX: Mutex<()> = Mutex::new(());
/// Any test that calls ptsname(3) must grab this mutex.
pub static ref PTSNAME_MTX: Mutex<()> = Mutex::new(());
/// Any test that alters signal handling must grab this mutex.
pub static ref SIGNAL_MTX: Mutex<()> = Mutex::new(());
}
/// Any test that creates child processes must grab this mutex, regardless
/// of what it does with those children.
pub static FORK_MTX: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
/// working directory must grab it shared.
pub static CWD_LOCK: RwLock<()> = RwLock::new(());
/// Any test that changes the process's supplementary groups must grab this
/// mutex
pub static GROUPS_MTX: Mutex<()> = Mutex::new(());
/// Any tests that loads or unloads kernel modules must grab this mutex
pub static KMOD_MTX: Mutex<()> = Mutex::new(());
/// Any test that calls ptsname(3) must grab this mutex.
pub static PTSNAME_MTX: Mutex<()> = Mutex::new(());
/// Any test that alters signal handling must grab this mutex.
pub static SIGNAL_MTX: Mutex<()> = Mutex::new(());

/// RAII object that restores a test's original directory on drop
struct DirRestore<'a> {
Expand Down

0 comments on commit d59d235

Please sign in to comment.