From 080f7775e3b6fdc41f3563b1fca01fdae88939a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 28 Dec 2023 15:27:12 +0000 Subject: [PATCH] Remove lazy_static, requires raising MSRV to 1.68 --- .github/workflows/ci.yml | 2 +- Cargo.toml | 5 +---- src/macros.rs | 8 +------- src/sync.rs | 5 +---- src/tid.rs | 18 +++++------------- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d15cd6a..4da97d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: env: RUSTFLAGS: -Dwarnings RUST_BACKTRACE: 1 - MSRV: 1.42.0 + MSRV: 1.68.0 jobs: build: diff --git a/Cargo.toml b/Cargo.toml index a43d3b9..e2ef8ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ documentation = "https://docs.rs/sharded-slab/" homepage = "https://github.com/hawkw/sharded-slab" repository = "https://github.com/hawkw/sharded-slab" readme = "README.md" -rust-version = "1.42.0" +rust-version = "1.68.0" license = "MIT" keywords = ["slab", "allocator", "lock-free", "atomic"] categories = ["memory-management", "data-structures", "concurrency"] @@ -32,9 +32,6 @@ maintenance = { status = "experimental" } name = "bench" harness = false -[dependencies] -lazy_static = "1" - [dev-dependencies] proptest = "1" criterion = "0.3" diff --git a/src/macros.rs b/src/macros.rs index e431f64..816a5d5 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,13 +1,7 @@ macro_rules! test_println { ($($arg:tt)*) => { if cfg!(test) && cfg!(slab_print) { - if std::thread::panicking() { - // getting the thread ID while panicking doesn't seem to play super nicely with loom's - // mock lazy_static... - println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*)) - } else { - println!("[{:?} {:>17}:{:<3}] {}", crate::Tid::::current(), file!(), line!(), format_args!($($arg)*)) - } + println!("[{:?} {:>17}:{:<3}] {}", crate::Tid::::current(), file!(), line!(), format_args!($($arg)*)) } } } diff --git a/src/sync.rs b/src/sync.rs index 64a31dc..ddb88a2 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -6,9 +6,7 @@ mod inner { pub use loom::sync::atomic::*; pub use std::sync::atomic::Ordering; } - pub(crate) use loom::{ - cell::UnsafeCell, hint, lazy_static, sync::Mutex, thread::yield_now, thread_local, - }; + pub(crate) use loom::{cell::UnsafeCell, hint, sync::Mutex, thread::yield_now, thread_local}; pub(crate) mod alloc { #![allow(dead_code)] @@ -63,7 +61,6 @@ mod inner { #[cfg(not(all(loom, any(feature = "loom", test))))] mod inner { #![allow(dead_code)] - pub(crate) use lazy_static::lazy_static; pub(crate) use std::{ sync::{atomic, Mutex}, thread::yield_now, diff --git a/src/tid.rs b/src/tid.rs index f2cb7e0..49d77d6 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -3,7 +3,7 @@ use crate::{ page, sync::{ atomic::{AtomicUsize, Ordering}, - lazy_static, thread_local, Mutex, + thread_local, Mutex, }, Pack, }; @@ -29,12 +29,10 @@ struct Registry { free: Mutex>, } -lazy_static! { - static ref REGISTRY: Registry = Registry { - next: AtomicUsize::new(0), - free: Mutex::new(VecDeque::new()), - }; -} +static REGISTRY: Registry = Registry { + next: AtomicUsize::new(0), + free: Mutex::new(VecDeque::new()), +}; thread_local! { static REGISTRATION: Registration = Registration::new(); @@ -177,12 +175,6 @@ impl Registration { } } -// Reusing thread IDs doesn't work under loom, since this `Drop` impl results in -// an access to a `loom` lazy_static while the test is shutting down, which -// panics. T_T -// Just skip TID reuse and use loom's lazy_static macro to ensure we have a -// clean initial TID on every iteration, instead. -#[cfg(not(all(loom, any(feature = "loom", test))))] impl Drop for Registration { fn drop(&mut self) { use std::sync::PoisonError;