From 239a07662bb220468a7a7a2dc8460b87b7dd7033 Mon Sep 17 00:00:00 2001 From: james7132 Date: Sun, 5 Jun 2022 17:50:21 -0700 Subject: [PATCH 01/11] Swap out lazy_static for once_cell --- Cargo.toml | 2 +- src/sync.rs | 14 -------------- src/tid.rs | 15 +++++++-------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b3d627..b933c3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ name = "bench" harness = false [dependencies] -lazy_static = "1" +once_cell = "1.12" [dev-dependencies] loom = { version = "0.5", features = ["checkpoint"] } diff --git a/src/sync.rs b/src/sync.rs index 64a31dc..2d8e4f0 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -62,8 +62,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, @@ -123,18 +121,6 @@ mod inner { pub fn get_ref(&self) -> &T { &self.value } - - /// Get a mutable reference to the value - #[inline(always)] - pub fn get_mut(&mut self) -> &mut T { - &mut self.value - } - - /// Stop tracking the value for leaks - #[inline(always)] - pub fn into_inner(self) -> T { - self.value - } } } } diff --git a/src/tid.rs b/src/tid.rs index 57d64f9..3abcac9 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, }; @@ -14,6 +14,7 @@ use std::{ marker::PhantomData, sync::PoisonError, }; +use once_cell::sync::Lazy; /// Uniquely identifies a thread. pub(crate) struct Tid { @@ -27,15 +28,13 @@ struct Registration(Cell>); struct Registry { next: AtomicUsize, - free: Mutex>, + free: Lazy>>, } -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: Lazy::new(|| Mutex::new(VecDeque::new())), +}; thread_local! { static REGISTRATION: Registration = Registration::new(); From dba2ff451830b1fbed7cd4196a8c4eab9db7606e Mon Sep 17 00:00:00 2001 From: james7132 Date: Tue, 10 Jan 2023 10:09:16 -0800 Subject: [PATCH 02/11] Formatting --- src/tid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tid.rs b/src/tid.rs index 3abcac9..937e08b 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -7,6 +7,7 @@ use crate::{ }, Pack, }; +use once_cell::sync::Lazy; use std::{ cell::{Cell, UnsafeCell}, collections::VecDeque, @@ -14,7 +15,6 @@ use std::{ marker::PhantomData, sync::PoisonError, }; -use once_cell::sync::Lazy; /// Uniquely identifies a thread. pub(crate) struct Tid { From 0b4114380f75e99eb085a7e59ade0fc7a631c85d Mon Sep 17 00:00:00 2001 From: james7132 Date: Sat, 18 Mar 2023 02:41:06 -0700 Subject: [PATCH 03/11] Bump MSRV to 1.56 --- .github/workflows/ci.yml | 2 +- Cargo.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2002095..8351b38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: rust: - stable - nightly - - 1.42.0 + - 1.56.0 steps: - uses: actions/checkout@master - name: Install toolchain diff --git a/Cargo.toml b/Cargo.toml index b933c3f..78fb17a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "sharded-slab" version = "0.1.4" authors = ["Eliza Weisman "] edition = "2018" +rust_version = "1.56" documentation = "https://docs.rs/sharded-slab/0.1.4/sharded_slab" homepage = "https://github.com/hawkw/sharded-slab" repository = "https://github.com/hawkw/sharded-slab" @@ -22,7 +23,7 @@ name = "bench" harness = false [dependencies] -once_cell = "1.12" +once_cell = "1.17" [dev-dependencies] loom = { version = "0.5", features = ["checkpoint"] } From 38c2070c45716cbba687497d36e60e3ca4d59369 Mon Sep 17 00:00:00 2001 From: james7132 Date: Sat, 18 Mar 2023 02:43:03 -0700 Subject: [PATCH 04/11] Updated edition to 2021 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 78fb17a..d3d95ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "sharded-slab" version = "0.1.4" authors = ["Eliza Weisman "] -edition = "2018" +edition = "2021" rust_version = "1.56" documentation = "https://docs.rs/sharded-slab/0.1.4/sharded_slab" homepage = "https://github.com/hawkw/sharded-slab" From 6e94f76508fe65de72eb58f049c16e1b49aa0e38 Mon Sep 17 00:00:00 2001 From: james7132 Date: Sat, 18 Mar 2023 02:53:31 -0700 Subject: [PATCH 05/11] Cleanup loom tests --- src/sync.rs | 2 +- src/tid.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index 2d8e4f0..ea07598 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -7,7 +7,7 @@ mod inner { pub use std::sync::atomic::Ordering; } pub(crate) use loom::{ - cell::UnsafeCell, hint, lazy_static, sync::Mutex, thread::yield_now, thread_local, + cell::UnsafeCell, hint, sync::Mutex, thread::yield_now, thread_local, }; pub(crate) mod alloc { diff --git a/src/tid.rs b/src/tid.rs index 937e08b..b78ee5c 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -28,13 +28,13 @@ struct Registration(Cell>); struct Registry { next: AtomicUsize, - free: Lazy>>, + free: Mutex>, } -static REGISTRY: Registry = Registry { +static REGISTRY: Lazy = Lazy::new(|| Registry { next: AtomicUsize::new(0), - free: Lazy::new(|| Mutex::new(VecDeque::new())), -}; + free: Mutex::new(VecDeque::new()), +}); thread_local! { static REGISTRATION: Registration = Registration::new(); From b90ade3a9e40a7213a1563f55d7ad8e6bdae68f1 Mon Sep 17 00:00:00 2001 From: james7132 Date: Sat, 18 Mar 2023 02:54:12 -0700 Subject: [PATCH 06/11] Formatting --- src/sync.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index ea07598..39d5eb3 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, 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)] From fb55548e9dc29e9a317bf0cf59800f760cb86d66 Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 22 Apr 2024 23:31:37 -0700 Subject: [PATCH 07/11] Use const initialization instead. --- Cargo.toml | 3 +-- src/tid.rs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3d95ed..eb08cc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "sharded-slab" version = "0.1.4" authors = ["Eliza Weisman "] edition = "2021" -rust_version = "1.56" +rust_version = "1.68" documentation = "https://docs.rs/sharded-slab/0.1.4/sharded_slab" homepage = "https://github.com/hawkw/sharded-slab" repository = "https://github.com/hawkw/sharded-slab" @@ -23,7 +23,6 @@ name = "bench" harness = false [dependencies] -once_cell = "1.17" [dev-dependencies] loom = { version = "0.5", features = ["checkpoint"] } diff --git a/src/tid.rs b/src/tid.rs index b78ee5c..16b64e4 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -7,7 +7,6 @@ use crate::{ }, Pack, }; -use once_cell::sync::Lazy; use std::{ cell::{Cell, UnsafeCell}, collections::VecDeque, @@ -31,10 +30,10 @@ struct Registry { free: Mutex>, } -static REGISTRY: Lazy = Lazy::new(|| Registry { +static REGISTRY: Registry = Registry { next: AtomicUsize::new(0), free: Mutex::new(VecDeque::new()), -}); +}; thread_local! { static REGISTRATION: Registration = Registration::new(); From 27c92ea9db92eac55bef1e8b5ed6161357455813 Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 22 Apr 2024 23:35:40 -0700 Subject: [PATCH 08/11] Fix CI failures --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d6edcb..beaacfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,12 +3,11 @@ name = "sharded-slab" version = "0.1.7" authors = ["Eliza Weisman "] edition = "2021" -rust_version = "1.68" 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"] From abf9b598471a1a1f966c83ff5adbc8fb8012995f Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 22 Apr 2024 23:36:49 -0700 Subject: [PATCH 09/11] Update MSRV in CI --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 525d9fe..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: @@ -16,10 +16,6 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: - - stable - - nightly - - 1.56.0 target: - x86_64-unknown-linux-gnu - i686-unknown-linux-musl From 07f92a1f1e9b1c299fdec775d584334e731449da Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 22 Apr 2024 23:42:31 -0700 Subject: [PATCH 10/11] Fix loom tests --- Cargo.toml | 1 + src/tid.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index beaacfb..3d94aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ indexmap = "1" # newer versions lead to "candidate versions found which didn't m [target.'cfg(loom)'.dependencies] loom = { version = "0.5", features = ["checkpoint"], optional = true } +once_cell = "1.0" [target.'cfg(loom)'.dev-dependencies] loom = { version = "0.5", features = ["checkpoint"] } diff --git a/src/tid.rs b/src/tid.rs index a3483fe..50d77f6 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -29,10 +29,16 @@ struct Registry { free: Mutex>, } +#[cfg(not(loom))] static REGISTRY: Registry = Registry { next: AtomicUsize::new(0), free: Mutex::new(VecDeque::new()), }; +#[cfg(loom)] +static REGISTRY: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| Registry { + next: AtomicUsize::new(0), + free: Mutex::new(VecDeque::new()), +}); thread_local! { static REGISTRATION: Registration = Registration::new(); From 6a14cf083206bc120f2cb5d0f0b58f8b652ce30e Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 22 Apr 2024 23:47:22 -0700 Subject: [PATCH 11/11] Use more appropriate cfg checks --- src/tid.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tid.rs b/src/tid.rs index 50d77f6..6d79eba 100644 --- a/src/tid.rs +++ b/src/tid.rs @@ -29,12 +29,13 @@ struct Registry { free: Mutex>, } -#[cfg(not(loom))] +// Loom's AtomicUsize and Mutex are not const initializable yet. +#[cfg(not(all(loom, any(test, feature = "loom"))))] static REGISTRY: Registry = Registry { next: AtomicUsize::new(0), free: Mutex::new(VecDeque::new()), }; -#[cfg(loom)] +#[cfg(all(loom, any(test, feature = "loom")))] static REGISTRY: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| Registry { next: AtomicUsize::new(0), free: Mutex::new(VecDeque::new()),