diff --git a/benchmarks/queue/src/main.rs b/benchmarks/queue/src/main.rs index 5c4e99759..4d19e9e35 100644 --- a/benchmarks/queue/src/main.rs +++ b/benchmarks/queue/src/main.rs @@ -22,7 +22,7 @@ const ITERATIONS: u64 = 10000000; trait PushPop: Send + Sync { fn push(&self, value: usize); - fn pop(&self) -> Option; + fn pop(&self) -> bool; } impl PushPop for Queue { @@ -30,28 +30,28 @@ impl PushPop for Queue { unsafe { self.push(&value) }; } - fn pop(&self) -> Option { - unsafe { self.pop() } + fn pop(&self) -> bool { + unsafe { self.pop().is_some() } } } impl PushPop for FixedSizeIndexQueue { fn push(&self, value: usize) { - unsafe { self.push(value) }; + unsafe { self.push(value as u64) }; } - fn pop(&self) -> Option { - unsafe { self.pop() } + fn pop(&self) -> bool { + unsafe { self.pop().is_some() } } } impl PushPop for FixedSizeSafelyOverflowingIndexQueue { fn push(&self, value: usize) { - unsafe { self.push(value) }; + unsafe { self.push(value as u64) }; } - fn pop(&self) -> Option { - unsafe { self.pop() } + fn pop(&self) -> bool { + unsafe { self.pop().is_some() } } } @@ -78,7 +78,7 @@ fn perform_benchmark( for _ in 0..args.iterations { queue_a2b.push(0); - while queue_b2a.pop().is_none() {} + while !queue_b2a.pop() {} } }); @@ -90,7 +90,7 @@ fn perform_benchmark( start_benchmark_barrier.wait(); for _ in 0..args.iterations { - while queue_a2b.pop().is_none() {} + while !queue_a2b.pop() {} queue_b2a.push(0); } diff --git a/iceoryx2-bb/lock-free/src/spsc/index_queue.rs b/iceoryx2-bb/lock-free/src/spsc/index_queue.rs index 9c1a91e5c..1403faf89 100644 --- a/iceoryx2-bb/lock-free/src/spsc/index_queue.rs +++ b/iceoryx2-bb/lock-free/src/spsc/index_queue.rs @@ -57,7 +57,7 @@ pub struct Producer<'a, PointerType: PointerTrait> + Debug> { queue: &'a details::IndexQueue, } -impl> + Debug> Producer<'_, PointerType> { +impl> + Debug> Producer<'_, PointerType> { /// Adds a new value to the [`IndexQueue`]/[`FixedSizeIndexQueue`]. If the queue is full /// it returns false, otherwise true. pub fn push(&mut self, t: u64) -> bool { @@ -65,7 +65,7 @@ impl> + Debug> Producer<'_, PointerT } } -impl> + Debug> Drop for Producer<'_, PointerType> { +impl> + Debug> Drop for Producer<'_, PointerType> { fn drop(&mut self) { self.queue.has_producer.store(true, Ordering::Relaxed); } @@ -77,7 +77,7 @@ pub struct Consumer<'a, PointerType: PointerTrait> + Debug> { queue: &'a details::IndexQueue, } -impl> + Debug> Consumer<'_, PointerType> { +impl> + Debug> Consumer<'_, PointerType> { /// Acquires a value from the [`IndexQueue`]/[`FixedSizeIndexQueue`]. If the queue is empty /// it returns [`None`] otherwise the value. pub fn pop(&mut self) -> Option { @@ -85,7 +85,7 @@ impl> + Debug> Consumer<'_, PointerT } } -impl> + Debug> Drop for Consumer<'_, PointerType> { +impl> + Debug> Drop for Consumer<'_, PointerType> { fn drop(&mut self) { self.queue.has_consumer.store(true, Ordering::Relaxed); } diff --git a/iceoryx2-cal/src/shm_allocator/pointer_offset.rs b/iceoryx2-cal/src/shm_allocator/pointer_offset.rs index da8eb1b10..692ba38f4 100644 --- a/iceoryx2-cal/src/shm_allocator/pointer_offset.rs +++ b/iceoryx2-cal/src/shm_allocator/pointer_offset.rs @@ -48,8 +48,23 @@ pub struct PointerOffset(u64); impl PointerOffset { /// Creates a new [`PointerOffset`] from the given offset value with the [`SegmentId`] == 0. pub const fn new(offset: usize) -> PointerOffset { - const SEGMENT_ID: u64 = 0; - Self((offset as u64) << (SegmentIdUnderlyingType::BITS) | SEGMENT_ID) + const SEGMENT_ID: u8 = 0; + Self::from_offset_and_segment_id(offset, SegmentId::new(SEGMENT_ID)) + } + + /// Creates a new [`PointerOffset`] from an offset and a [`SegmentId`] + pub const fn from_offset_and_segment_id(offset: usize, segment_id: SegmentId) -> PointerOffset { + Self((offset as u64) << (SegmentIdUnderlyingType::BITS) | segment_id.value() as u64) + } + + /// Creates a new [`PointerOffset`] from a provided raw value. + pub const fn from_value(value: u64) -> PointerOffset { + Self(value) + } + + /// Returns the underlying raw value of the [`PointerOffset`] + pub const fn as_value(&self) -> u64 { + self.0 } /// Sets the [`SegmentId`] of the [`PointerOffset`].