diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9804dee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: Rust + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + toolchain: ["stable"] + features: ["", "--features serde"] + + steps: + - uses: actions/checkout@v4 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain }} + + - name: Install 32bit target + run: rustup target add i686-unknown-linux-musl + - name: Install wasm target + run: rustup target add wasm32v1-none + - name: Install miri + run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu miri + - name: Install no-std-check + run: cargo install cargo-no-std-check + + - name: Build + run: cargo build --verbose ${{ matrix.features }} + - name: Build-32bit + run: cargo build --verbose --target i686-unknown-linux-musl ${{ matrix.features }} + - name: Build-wasm + run: cargo build --verbose --target wasm32v1-none ${{ matrix.features }} + + - name: Test + run: cargo test --verbose ${{ matrix.features }} + - name: Test-32bit + run: cargo test --verbose --target i686-unknown-linux-musl ${{ matrix.features }} + - name: Check-wasm + run: cargo check --verbose --target wasm32v1-none ${{ matrix.features }} + + - name: Clippy + run: cargo clippy ${{ matrix.features }} -- -D warnings --verbose + + - name: Miri + run: cargo +nightly miri test --verbose ${{ matrix.features }} + + - name: NoStd + run: cargo +nightly no-std-check ${{ matrix.features }} diff --git a/Cargo.toml b/Cargo.toml index 2333605..503133b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "orx-concurrent-vec" -version = "3.5.0" -edition = "2021" +version = "3.6.0" +edition = "2024" authors = ["orxfun "] description = "A thread-safe, efficient and lock-free vector allowing concurrent grow, read and update operations." license = "MIT OR Apache-2.0" @@ -10,24 +10,24 @@ keywords = ["concurrency", "vec", "data-structures", "atomic", "lock-free"] categories = ["data-structures", "concurrency", "rust-patterns", "no-std"] [dependencies] -orx-pseudo-default = { version = "2.0.0", default-features = false } -orx-pinned-vec = "3.15" -orx-fixed-vec = "3.15" -orx-split-vec = "3.15" -orx-pinned-concurrent-col = "2.12" -orx-concurrent-option = "1.4" -serde = { version = "1.0.217", optional = true, default-features = false } +orx-pseudo-default = { version = "2.1.0", default-features = false } +orx-pinned-vec = "3.16.0" +orx-fixed-vec = "3.16.0" +orx-split-vec = "3.16.0" +orx-pinned-concurrent-col = "2.13.0" +orx-concurrent-option = "1.5.0" +serde = { version = "1.0.219", optional = true, default-features = false } [dev-dependencies] append-only-vec = "0.1.7" -boxcar = "0.2.8" -clap = { version = "4.5.28", features = ["derive"] } +boxcar = "0.2.11" +clap = { version = "4.5.35", features = ["derive"] } criterion = "0.5.1" -orx-iterable = "1.2.0" +orx-iterable = { version = "1.3.0", default-features = false } rand = "0.9.0" rand_chacha = "0.9.0" rayon = "1.10.0" -serde_json = { version = "1.0.138", default-features = false, features = [ +serde_json = { version = "1.0.140", default-features = false, features = [ "std", ] } test-case = "3.3.1" diff --git a/src/concurrent_slice/unsafe_api.rs b/src/concurrent_slice/unsafe_api.rs index 8b1878e..f4c3308 100644 --- a/src/concurrent_slice/unsafe_api.rs +++ b/src/concurrent_slice/unsafe_api.rs @@ -146,7 +146,7 @@ where /// assert_eq!(averages.len(), 10); /// ``` pub unsafe fn get_ref(&self, i: usize) -> Option<&T> { - self.idx(i).and_then(|i| self.vec.get_ref(i)) + self.idx(i).and_then(|i| unsafe { self.vec.get_ref(i) }) } /// Returns an iterator to references of elements of the vec. @@ -345,7 +345,7 @@ where /// assert_eq!(&vec, &['a', 'x', 'c', 'd']); /// ``` pub unsafe fn get_mut(&self, i: usize) -> Option<&mut T> { - self.idx(i).and_then(|i| self.vec.get_mut(i)) + self.idx(i).and_then(|i| unsafe { self.vec.get_mut(i) }) } /// Returns an iterator to mutable references of elements of the vec. @@ -401,6 +401,6 @@ where pub unsafe fn iter_mut(&self) -> impl Iterator { let b = self.a + self.len; unsafe { self.vec.core.iter_over_range(self.a..b) } - .flat_map(|x| x.0.get_raw_mut().map(|p| &mut *p)) + .flat_map(|x| x.0.get_raw_mut().map(|p| unsafe { &mut *p })) } } diff --git a/src/new.rs b/src/new.rs index 02eec97..c71273b 100644 --- a/src/new.rs +++ b/src/new.rs @@ -18,7 +18,7 @@ impl ConcurrentVec, Doubling>> { /// Creates a new concurrent bag by creating and wrapping up a new [`SplitVec`](https://docs.rs/orx-split-vec/latest/orx_split_vec/struct.Doubling.html) as the underlying storage. pub fn with_doubling_growth() -> Self { - Self::new_from_pinned(SplitVec::with_doubling_growth_and_fragments_capacity(32)) + Self::new_from_pinned(SplitVec::with_doubling_growth_and_max_concurrent_capacity()) } } diff --git a/src/unsafe_api.rs b/src/unsafe_api.rs index 24c4f29..1392f80 100644 --- a/src/unsafe_api.rs +++ b/src/unsafe_api.rs @@ -158,8 +158,8 @@ where pub unsafe fn get_ref(&self, i: usize) -> Option<&T> { match i < self.reserved_len() { true => { - let maybe = self.core.get(i); - maybe.and_then(|x| x.0.as_ref_with_order(Ordering::SeqCst)) + let maybe = unsafe { self.core.get(i) }; + maybe.and_then(|x| unsafe { x.0.as_ref_with_order(Ordering::SeqCst) }) } false => None, } @@ -269,7 +269,7 @@ where /// assert_eq!(averages.len(), 10); /// ``` pub unsafe fn iter_ref(&self) -> impl Iterator { - let x = self.core.iter(self.reserved_len()); + let x = unsafe { self.core.iter(self.reserved_len()) }; x.flat_map(|x| unsafe { x.0.as_ref_with_order(Ordering::SeqCst) }) } @@ -363,8 +363,8 @@ where pub unsafe fn get_mut(&self, i: usize) -> Option<&mut T> { match i < self.reserved_len() { true => { - let elem = self.core.get(i); - elem.and_then(|option| option.0.get_raw_mut().map(|p| &mut *p)) + let elem = unsafe { self.core.get(i) }; + elem.and_then(|option| option.0.get_raw_mut().map(|p| unsafe { &mut *p })) } false => None, } @@ -419,7 +419,7 @@ where /// assert_eq!(&vec, &[0, 2, 4, 6]); /// ``` pub unsafe fn iter_mut(&self) -> impl Iterator { - let x = self.core.iter(self.reserved_len()); - x.flat_map(|x| x.0.get_raw_mut().map(|p| &mut *p)) + let x = unsafe { self.core.iter(self.reserved_len()) }; + x.flat_map(|x| x.0.get_raw_mut().map(|p| unsafe { &mut *p })) } } diff --git a/tests/concurrent_read_write.rs b/tests/concurrent_read_write.rs index c4dbce8..6391594 100644 --- a/tests/concurrent_read_write.rs +++ b/tests/concurrent_read_write.rs @@ -218,12 +218,12 @@ where #[cfg(not(miri))] #[test_matrix([500, 1_000, 10_000])] fn concurrent_read_write(num_items_per_thread: usize) { - let pinned = SplitVec::with_doubling_growth_and_fragments_capacity(32); + let pinned = SplitVec::with_doubling_growth_and_max_concurrent_capacity(); spawn(pinned, NUM_GROWERS, NUM_USERS, num_items_per_thread); } -#[test_matrix([250])] +#[test_matrix([100])] fn miri_concurrent_read_write(num_items_per_thread: usize) { - let pinned = SplitVec::with_doubling_growth_and_fragments_capacity(32); + let pinned = SplitVec::with_doubling_growth_and_max_concurrent_capacity(); spawn(pinned, NUM_GROWERS, NUM_USERS, num_items_per_thread); }