Skip to content

Commit

Permalink
[eclipse-iceoryx#504] RelocatableContainer init is mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Nov 7, 2024
1 parent 9c6b133 commit 64ea511
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion iceoryx2-bb/container/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub mod details {
}

unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
allocator: &Allocator,
) -> Result<(), AllocationError> {
if self
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-bb/container/src/slotmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub mod details {
}

unsafe fn init<Allocator: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &Allocator,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
let msg = "Unable to initialize RelocatableSlotMap";
Expand All @@ -264,6 +264,7 @@ pub mod details {
when self.data_next_free_index.init(allocator),
"{msg} since the underlying data_next_free_index queue could not be initialized.");

self.initialize_data_structures();
Ok(())
}

Expand Down Expand Up @@ -425,7 +426,6 @@ impl<T, const CAPACITY: usize> Default for FixedSizeSlotMap<T, CAPACITY> {
.init(&allocator)
.expect("All required memory is preallocated.")
};
unsafe { new_self.state.initialize_data_structures() };

new_self
}
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/container/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub mod details {
}

unsafe fn init<Allocator: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &Allocator,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
if self.is_initialized.load(Ordering::Relaxed) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/elementary/src/relocatable_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub trait RelocatableContainer {
/// * Shall be only used when the [`RelocatableContainer`] was created with
/// [`RelocatableContainer::new_uninit()`]
///
unsafe fn init<T: BaseAllocator>(&self, allocator: &T) -> Result<(), AllocationError>;
unsafe fn init<T: BaseAllocator>(&mut self, allocator: &T) -> Result<(), AllocationError>;

/// Returns the amount of memory the object requires. The whole memory consumption is
/// `std::mem::size_of::<RelocatableContainer>() + RelocatableContainer::memory_size()`.
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/src/mpmc/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub mod details {
}

unsafe fn init<T: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &T,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/src/mpmc/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<T: Copy + Debug> RelocatableContainer for Container<T> {
}

unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
allocator: &Allocator,
) -> Result<(), AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/src/mpmc/unique_index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl RelocatableContainer for UniqueIndexSet {
}
}

unsafe fn init<T: BaseAllocator>(&self, allocator: &T) -> Result<(), AllocationError> {
unsafe fn init<T: BaseAllocator>(&mut self, allocator: &T) -> Result<(), AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
fatal_panic!(from self, "Memory already initialized. Initializing it twice may lead to undefined behavior.");
}
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/src/spsc/index_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub mod details {
}

unsafe fn init<T: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &T,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub mod details {
}

unsafe fn init<T: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &T,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/tests/mpmc_container_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod mpmc_container {
// case - hack required since `T` cannot be used in const operations
let mut memory = [0u8; Container::<crate::TestType>::const_memory_size(129_usize)];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
let sut = unsafe { Container::<T>::new_uninit(CAPACITY) };
let mut sut = unsafe { Container::<T>::new_uninit(CAPACITY) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

let mut stored_indices = vec![];
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/lock-free/tests/mpmc_unique_index_set_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn mpmc_unique_index_set_borrowed_indices_works() {
fn mpmc_unique_index_set_acquire_and_release_works_with_uninitialized_memory() {
let mut memory = [0u8; UniqueIndexSet::const_memory_size(128)];
let allocator = BumpAllocator::new(memory.as_mut_ptr() as usize);
let sut = unsafe { UniqueIndexSet::new_uninit(CAPACITY) };
let mut sut = unsafe { UniqueIndexSet::new_uninit(CAPACITY) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };

let mut ids = vec![];
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/memory/src/pool_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl PoolAllocator {
/// * must be called exactly once before any other method can be called
///
pub unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
allocator: &Allocator,
) -> Result<(), AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/memory/tests/pool_allocator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn pool_allocator_relocatable_acquire_all_memory_works() {
const CHUNK_SIZE: usize = 100;
let start_ptr = NonNull::new(test.get_mut_memory()).unwrap();

let sut =
let mut sut =
unsafe { PoolAllocator::new_uninit(BUCKET_LAYOUT, start_ptr, TestFixture::memory_size()) };

let mgmt_memory_size = PoolAllocator::memory_size(BUCKET_LAYOUT, TestFixture::memory_size());
Expand Down
6 changes: 3 additions & 3 deletions iceoryx2-bb/trait-tests/tests/relocatable_container_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod relocatable_container {
let mut memory = memory();
let allocator = allocator(&mut *memory);

let sut = unsafe { T::new_uninit(capacity) };
let mut sut = unsafe { T::new_uninit(capacity) };
let require_memory_size = T::memory_size(capacity);

assert_that!(unsafe { sut.init(&allocator) }, is_ok);
Expand All @@ -66,7 +66,7 @@ mod relocatable_container {

let mut current_size = 0;
for capacity in 1..MAX_CAPACITY {
let sut = unsafe { T::new_uninit(capacity) };
let mut sut = unsafe { T::new_uninit(capacity) };
let require_memory_size = T::memory_size(capacity);

assert_that!(unsafe { sut.init(&allocator) }, is_ok);
Expand All @@ -83,7 +83,7 @@ mod relocatable_container {
let mut memory = memory();
let allocator = allocator(&mut *memory);

let sut = unsafe { T::new_uninit(MAX_CAPACITY) };
let mut sut = unsafe { T::new_uninit(MAX_CAPACITY) };

assert_that!(unsafe { sut.init(&allocator) }, is_ok);

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/shared_memory/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub mod details {
Allocator::new_uninit(SystemInfo::PageSize.value(), memory, allocator_config)
});

if let Err(e) = unsafe { details.allocator.assume_init_ref().init(init_allocator) } {
if let Err(e) = unsafe { details.allocator.assume_init_mut().init(init_allocator) } {
debug!(from self, "{} since the management memory for the allocator could not be initialized ({:?}).", msg, e);
false
} else {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/shm_allocator/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl ShmAllocator for BumpAllocator {
}

unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
_mgmt_allocator: &Allocator,
) -> Result<(), ShmAllocatorInitError> {
let msg = "Unable to initialize allocator";
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/shm_allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait ShmAllocator: Send + Sync + 'static {
/// * must be called before any other method is called
///
unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
mgmt_allocator: &Allocator,
) -> Result<(), ShmAllocatorInitError>;

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/shm_allocator/pool_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ShmAllocator for PoolAllocator {
}

unsafe fn init<Allocator: BaseAllocator>(
&self,
&mut self,
mgmt_allocator: &Allocator,
) -> Result<(), ShmAllocatorInitError> {
let msg = "Unable to initialize allocator";
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/src/zero_copy_connection/used_chunk_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod details {
}

unsafe fn init<T: iceoryx2_bb_elementary::allocator::BaseAllocator>(
&self,
&mut self,
allocator: &T,
) -> Result<(), iceoryx2_bb_elementary::allocator::AllocationError> {
if self.is_memory_initialized.load(Ordering::Relaxed) {
Expand Down
12 changes: 6 additions & 6 deletions iceoryx2-cal/tests/event_id_tracker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod event_id_tracker {
const CAPACITY: usize = 5234;
let mut memory = memory();

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);
assert_that!(sut.trigger_id_max().as_value(), lt CAPACITY);
}
Expand All @@ -49,7 +49,7 @@ mod event_id_tracker {
let mut memory = memory();
const CAPACITY: usize = 1234;

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);

assert_that!(unsafe { sut.acquire() }, eq None);
Expand All @@ -66,7 +66,7 @@ mod event_id_tracker {
let mut memory = memory();
const CAPACITY: usize = 1234;

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);

for i in 0..CAPACITY {
Expand All @@ -89,7 +89,7 @@ mod event_id_tracker {
let mut memory = memory();
const CAPACITY: usize = 3234;

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);

for i in 0..CAPACITY {
Expand Down Expand Up @@ -117,7 +117,7 @@ mod event_id_tracker {
let mut memory = memory();
const CAPACITY: usize = 234;

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);

for i in 0..CAPACITY {
Expand Down Expand Up @@ -147,7 +147,7 @@ mod event_id_tracker {
let mut memory = memory();
const CAPACITY: usize = 1234;

let sut = unsafe { Sut::new_uninit(CAPACITY) };
let mut sut = unsafe { Sut::new_uninit(CAPACITY) };
assert_that!(unsafe { sut.init(&allocator(&mut *memory)) }, is_ok);

assert_that!(unsafe { sut.acquire() }, eq None);
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/tests/shm_allocator_pool_allocator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod shm_allocator_pool_allocator {
MEM_SIZE,
);
let config = &Config { bucket_layout };
let sut = Box::new(unsafe {
let mut sut = Box::new(unsafe {
PoolAllocator::new_uninit(MAX_SUPPORTED_ALIGNMENT, base_address, config)
});

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-cal/tests/shm_allocator_trait_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mod shm_allocator {
let mut test = TestFixture::<Sut>::new();
test.prepare();

let sut = unsafe {
let mut sut = unsafe {
Sut::new_uninit(
1,
NonNull::new_unchecked(test.memory.as_mut_slice()),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/service/dynamic_config/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl DynamicConfig {
}
}

pub(crate) unsafe fn init(&self, allocator: &BumpAllocator) {
pub(crate) unsafe fn init(&mut self, allocator: &BumpAllocator) {
fatal_panic!(from "event::DynamicConfig::init",
when self.listeners.init(allocator),
"This should never happen! Unable to initialize listener port id container.");
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2/src/service/dynamic_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ impl DynamicConfig {
Container::<NodeId>::memory_size(max_number_of_nodes)
}

pub(crate) unsafe fn init(&self, allocator: &BumpAllocator) {
pub(crate) unsafe fn init(&mut self, allocator: &BumpAllocator) {
fatal_panic!(from self, when self.nodes.init(allocator),
"This should never happen! Unable to initialize NodeId container.");
match &self.messaging_pattern {
MessagingPattern::PublishSubscribe(ref v) => v.init(allocator),
MessagingPattern::Event(ref v) => v.init(allocator),
match &mut self.messaging_pattern {
MessagingPattern::PublishSubscribe(ref mut v) => v.init(allocator),
MessagingPattern::Event(ref mut v) => v.init(allocator),
}
}

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/service/dynamic_config/publish_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl DynamicConfig {
}
}

pub(crate) unsafe fn init(&self, allocator: &BumpAllocator) {
pub(crate) unsafe fn init(&mut self, allocator: &BumpAllocator) {
fatal_panic!(from self,
when self.subscribers.init(allocator),
"This should never happen! Unable to initialize subscriber port id container.");
Expand Down

0 comments on commit 64ea511

Please sign in to comment.