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 tests on 32 bit #17

Merged
merged 19 commits into from
Sep 11, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install rust 1.58
- name: Install rust 1.63
run: |
rustup toolchain install 1.58 --no-self-update --profile minimal
rustup default 1.58
rustup toolchain install 1.63 nightly --no-self-update --profile minimal
rustup default 1.63

- name: Use minimal versions
run: cargo +nightly update -Zminimal-versions

- uses: Swatinem/rust-cache@v2
- name: Check msrv
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
- uses: actions/checkout@v4
- name: Check format
run: cargo fmt --all -- --check
Run_clippy:

run_clippy:
runs-on: ubuntu-latest

steps:
Expand All @@ -38,6 +39,22 @@ jobs:
- name: Run clippy
run: cargo clippy --all --all-features --no-deps

test-32bit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: taiki-e/install-action@v2
with:
tool: nextest
- run: rustup target add i686-unknown-linux-musl

- uses: Swatinem/rust-cache@v2
- run: |
cargo nextest run --target i686-unknown-linux-musl
cargo test --doc --target i686-unknown-linux-musl

test:
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "concurrent_arena"
version = "0.1.8"
edition = "2018"
rust-version = "1.58"
rust-version = "1.63"

license = "MIT"
description = "u32 concurrent insertion/removal arena that returns ArenaArc"
Expand Down
7 changes: 4 additions & 3 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,18 @@ impl<T: Send + Sync, const BITARRAY_LEN: usize, const LEN: usize> Arena<T, BITAR
#[cfg(test)]
mod tests {
use crate::*;
const LEN: usize = usize::BITS as usize;

#[test]
fn test_new() {
let arena: Arena<_, 1, 64> = Arena::new();
let arena: Arena<_, 1, { LEN }> = Arena::new();
let slot = ArenaArc::slot(&arena.insert(()));
assert_eq!(ArenaArc::slot(&arena.remove(slot).unwrap()), slot);
}

#[test]
fn test_with_capacity() {
let arena: Arena<_, 1, 64> = Arena::with_capacity(0);
let arena: Arena<_, 1, { LEN }> = Arena::with_capacity(0);
let slot = ArenaArc::slot(&arena.insert(()));
assert_eq!(ArenaArc::slot(&arena.remove(slot).unwrap()), slot);
}
Expand All @@ -285,7 +286,7 @@ mod tests {
use rayon::spawn;
use std::sync::Arc;

let arena: Arc<Arena<Mutex<u32>, 1, 64>> = Arc::new(Arena::with_capacity(0));
let arena: Arc<Arena<Mutex<u32>, 1, { LEN }>> = Arc::new(Arena::with_capacity(0));

(0..u16::MAX).into_par_iter().for_each(|i| {
let i = i as u32;
Expand Down
35 changes: 17 additions & 18 deletions src/bucket.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{bitmap::BitMap, Arc, OptionExt, SliceExt};

use core::{cell::UnsafeCell, hint::spin_loop, ops::Deref};
use core::{array, cell::UnsafeCell, hint::spin_loop, ops::Deref};
use std::sync::atomic::{fence, AtomicU8, Ordering};

const REMOVED_MASK: u8 = 1 << (u8::BITS - 1);
Expand All @@ -14,8 +14,6 @@ struct Entry<T> {
}

impl<T> Entry<T> {
const EMPTY: Entry<T> = Entry::new();

const fn new() -> Self {
Self {
counter: AtomicU8::new(0),
Expand Down Expand Up @@ -72,7 +70,7 @@ impl<T: Send + Sync, const BITARRAY_LEN: usize, const LEN: usize> Bucket<T, BITA
pub(crate) fn new() -> Self {
Self {
bitset: BitMap::new(),
entries: [Entry::EMPTY; LEN],
entries: array::from_fn(|_| Entry::new()),
}
}

Expand Down Expand Up @@ -367,13 +365,14 @@ mod tests {

use rayon::prelude::*;

type Bucket<T> = super::Bucket<T, 1, 64>;
const LEN: u32 = usize::BITS;
type Bucket<T> = super::Bucket<T, 1, { LEN as usize }>;

#[test]
fn test_basic() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let arcs: Vec<_> = (0..64)
let arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand Down Expand Up @@ -413,7 +412,7 @@ mod tests {
fn test_clone() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let arcs: Vec<_> = (0..64)
let arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand Down Expand Up @@ -450,7 +449,7 @@ mod tests {
fn test_reuse() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let mut arcs: Vec<_> = (0..64)
let mut arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -473,7 +472,7 @@ mod tests {
assert_eq!(ArenaArc::strong_count(&arc), 1);
}

let new_arcs: Vec<_> = (64..64 + 32)
let new_arcs: Vec<_> = (LEN..LEN + LEN / 2)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -494,9 +493,9 @@ mod tests {
let handle2 = spawn(move || {
new_arcs
.into_par_iter()
.zip(64..64 + 32)
.zip(LEN..LEN + LEN / 2)
.for_each(|(each, i)| {
assert_eq!((*each) as usize, i);
assert_eq!(*each, i);
});
});

Expand All @@ -508,7 +507,7 @@ mod tests {
fn test_reuse2() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let mut arcs: Vec<_> = (0..64)
let mut arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -527,7 +526,7 @@ mod tests {
assert_eq!(ArenaArc::strong_count(&arc), 1);
}

let new_arcs: Vec<_> = (64..64 + 32)
let new_arcs: Vec<_> = (LEN..LEN + LEN / 2)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -548,9 +547,9 @@ mod tests {
let handle2 = spawn(move || {
new_arcs
.into_par_iter()
.zip(64..64 + 32)
.zip(LEN..LEN + LEN / 2)
.for_each(|(each, i)| {
assert_eq!((*each) as usize, i);
assert_eq!(*each, i);
});
});

Expand All @@ -562,7 +561,7 @@ mod tests {
fn test_concurrent_remove() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let arcs: Vec<_> = (0..64)
let arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -589,7 +588,7 @@ mod tests {
fn test_concurrent_remove2() {
let bucket: Arc<Bucket<u32>> = Arc::new(Bucket::new());

let arcs: Vec<_> = (0..64)
let arcs: Vec<_> = (0..LEN)
.into_par_iter()
.map(|i| {
let arc = Bucket::try_insert(&bucket, 0, i).unwrap();
Expand All @@ -613,7 +612,7 @@ mod tests {
fn realworld_test() {
let bucket: Arc<Bucket<Mutex<u32>>> = Arc::new(Bucket::new());

(0..64).into_par_iter().for_each(|i| {
(0..LEN).into_par_iter().for_each(|i| {
let arc = Bucket::try_insert(&bucket, 0, Mutex::new(i)).unwrap();

assert_eq!(ArenaArc::strong_count(&arc), 2);
Expand Down