Skip to content

Commit

Permalink
Merge pull request #517 from elfenpiff/iox2-497-resizable-shared-memory
Browse files Browse the repository at this point in the history
[#497] resizable shared memory
  • Loading branch information
elfenpiff authored Dec 1, 2024
2 parents da99662 + 1982cc6 commit 949d2e0
Show file tree
Hide file tree
Showing 24 changed files with 2,538 additions and 53 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Support for slices in the C++ bindings [#490](https://github.com/eclipse-iceoryx/iceoryx2/issues/490)
* Add API to retrieve string description of error enums [$491](https://github.com/eclipse-iceoryx/iceoryx2/issues/491)
* Add relocatable `SlotMap` [#504](https://github.com/eclipse-iceoryx/iceoryx2/issues/504)
* Add `ResizableSharedMemory` [#497](https://github.com/eclipse-iceoryx/iceoryx2/issues/497)
* Make signal handling optional in `WaitSet` and `Node` [#528](https://github.com/eclipse-iceoryx/iceoryx2/issues/528)
* Add benchmark for iceoryx2 queues [#535](https://github.com/eclipse-iceoryx/iceoryx2/issues/535)

Expand Down
12 changes: 12 additions & 0 deletions iceoryx2-bb/container/src/semantic_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ pub trait SemanticString<const CAPACITY: usize>:
self.as_string().capacity()
}

/// Finds the first occurrence of a byte string in the given string. If the byte string was
/// found the start position of the byte string is returned, otherwise [`None`].
fn find(&self, bytes: &[u8]) -> Option<usize> {
self.as_string().find(bytes)
}

/// Finds the last occurrence of a byte string in the given string. If the byte string was
/// found the start position of the byte string is returned, otherwise [`None`].
fn rfind(&self, bytes: &[u8]) -> Option<usize> {
self.as_string().find(bytes)
}

/// Returns true when the string is full, otherwise false
fn is_full(&self) -> bool {
self.as_string().is_full()
Expand Down
31 changes: 31 additions & 0 deletions iceoryx2-bb/container/src/slotmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ pub mod details {
}
}

pub(crate) unsafe fn next_free_key_impl(&self) -> Option<SlotMapKey> {
if self.idx_to_data_free_list_head == INVALID {
return None;
}

Some(SlotMapKey::new(self.idx_to_data_free_list_head))
}

pub(crate) fn len_impl(&self) -> usize {
self.len
}
Expand Down Expand Up @@ -394,6 +402,12 @@ pub mod details {
unsafe { self.remove_impl(key) }
}

/// Returns the [`SlotMapKey`] that will be used when the user calls
/// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
pub fn next_free_key(&self) -> Option<SlotMapKey> {
unsafe { self.next_free_key_impl() }
}

/// Returns the number of stored values.
pub fn len(&self) -> usize {
self.len_impl()
Expand Down Expand Up @@ -501,6 +515,17 @@ pub mod details {
self.remove_impl(key)
}

/// Returns the [`SlotMapKey`] that will be used when the user calls
/// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
///
/// # Safety
///
/// * [`RelocatableSlotMap::init()`] must be called once before
///
pub unsafe fn next_free_key(&self) -> Option<SlotMapKey> {
self.next_free_key_impl()
}

/// Returns the number of stored values.
pub fn len(&self) -> usize {
self.len_impl()
Expand Down Expand Up @@ -615,6 +640,12 @@ impl<T, const CAPACITY: usize> FixedSizeSlotMap<T, CAPACITY> {
unsafe { self.state.remove_impl(key) }
}

/// Returns the [`SlotMapKey`] that will be used when the user calls
/// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
pub fn next_free_key(&self) -> Option<SlotMapKey> {
unsafe { self.state.next_free_key_impl() }
}

/// Returns the number of stored values.
pub fn len(&self) -> usize {
self.state.len_impl()
Expand Down
27 changes: 27 additions & 0 deletions iceoryx2-bb/container/tests/slotmap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,31 @@ mod slot_map {
}
}
}

#[test]
fn next_free_key_returns_key_used_for_insert() {
let mut sut = FixedSizeSut::new();
let mut keys = vec![];

for _ in 0..SUT_CAPACITY / 2 {
keys.push(sut.insert(0).unwrap());
}

let next_key = sut.next_free_key();
assert_that!(next_key, is_some);
assert_that!(sut.insert(0), eq next_key);
}

#[test]
fn next_free_key_returns_none_when_full() {
let mut sut = FixedSizeSut::new();
let mut keys = vec![];

for _ in 0..SUT_CAPACITY {
keys.push(sut.insert(0).unwrap());
}

let next_key = sut.next_free_key();
assert_that!(next_key, is_none);
}
}
1 change: 1 addition & 0 deletions iceoryx2-cal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod hash;
pub mod monitoring;
pub mod named_concept;
pub mod reactor;
pub mod resizable_shared_memory;
pub mod serialize;
pub mod shared_memory;
pub mod shared_memory_directory;
Expand Down
Loading

0 comments on commit 949d2e0

Please sign in to comment.