From b7cd8727b18917e44df9106b673337bbebed5dcf Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 26 Nov 2025 23:04:17 +0100 Subject: [PATCH 1/2] Implement sync for AtomicSharedVector --- src/lib.rs | 2 +- src/raw.rs | 6 ++++-- src/shared.rs | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f80b9ae..243a1be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,7 @@ macro_rules! arc_vector { #[test] fn vector_macro() { - pub use allocator_api2::alloc::{Allocator, Global}; + pub use allocator_api2::alloc::Global; let v1: Vector = vector![0, 1, 2, 3, 4, 5]; let v2: Vector = vector![2; 4]; diff --git a/src/raw.rs b/src/raw.rs index 74cdeb2..6490f24 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -8,7 +8,7 @@ use core::sync::atomic::{ Ordering::{Relaxed, Release}, }; -pub use crate::alloc::{AllocError, Allocator, Global}; +pub use crate::alloc::{AllocError, Allocator}; pub type BufferSize = u32; @@ -224,7 +224,7 @@ pub unsafe fn extend_within_capacity>(data: *mut T, vec if let Some(item) = iter.next() { ptr::write(ptr, item); ptr = ptr.add(1); - count += 1; + count += 1; } else { finished = true; break; @@ -298,6 +298,8 @@ pub unsafe fn header_from_data_ptr(data_ptr: NonNull) -> NonNull { #[test] fn buffer_layout_alignemnt() { + pub use crate::alloc::Global; + type B = Box; let layout = buffer_layout::, B>(2).unwrap(); assert_eq!(layout.align(), mem::size_of::()); diff --git a/src/shared.rs b/src/shared.rs index 73d0444..f28f3bf 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -238,7 +238,7 @@ impl RefCountedVector { // SAFETY: call this only if the vector is unique. pub(crate) unsafe fn vec_header_mut(&mut self) -> &mut raw::VecHeader { &mut self.inner.as_mut().vec - } + } pub(crate) fn vec_header(&self) -> &raw::VecHeader { unsafe { &self.inner.as_ref().vec } @@ -634,7 +634,7 @@ impl Drop for RefCountedVector { // we only need it for the atomic reference counted version but I don't expect // this to make a measurable difference. core::sync::atomic::fence(Ordering::Acquire); - + raw::drop_items(self.data_ptr(), header.len); raw::dealloc::(self.inner.header, header.cap); } @@ -645,6 +645,8 @@ impl Drop for RefCountedVector { unsafe impl Send for AtomicSharedVector {} +unsafe impl Sync for AtomicSharedVector {} + impl Clone for RefCountedVector { fn clone(&self) -> Self { self.new_ref() From 0217f5b89d1413e137e5483a2761049df4d9f66c Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 26 Nov 2025 23:06:58 +0100 Subject: [PATCH 2/2] Version 0.4.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 95f328e..02a5832 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shared_vector" -version = "0.4.4" +version = "0.4.5" edition = "2021" authors = ["Nicolas Silva "] repository = "https://github.com/nical/shared_vector"