Skip to content

Commit

Permalink
[#525] Rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 1, 2024
1 parent 5bbb43b commit 4b58bec
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
22 changes: 11 additions & 11 deletions benchmarks/queue/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ const ITERATIONS: u64 = 10000000;

trait PushPop: Send + Sync {
fn push(&self, value: usize);
fn pop(&self) -> Option<usize>;
fn pop(&self) -> bool;
}

impl<const CAPACITY: usize> PushPop for Queue<usize, CAPACITY> {
fn push(&self, value: usize) {
unsafe { self.push(&value) };
}

fn pop(&self) -> Option<usize> {
unsafe { self.pop() }
fn pop(&self) -> bool {
unsafe { self.pop().is_some() }
}
}

impl<const CAPACITY: usize> PushPop for FixedSizeIndexQueue<CAPACITY> {
fn push(&self, value: usize) {
unsafe { self.push(value) };
unsafe { self.push(value as u64) };
}

fn pop(&self) -> Option<usize> {
unsafe { self.pop() }
fn pop(&self) -> bool {
unsafe { self.pop().is_some() }
}
}

impl<const CAPACITY: usize> PushPop for FixedSizeSafelyOverflowingIndexQueue<CAPACITY> {
fn push(&self, value: usize) {
unsafe { self.push(value) };
unsafe { self.push(value as u64) };
}

fn pop(&self) -> Option<usize> {
unsafe { self.pop() }
fn pop(&self) -> bool {
unsafe { self.pop().is_some() }
}
}

Expand All @@ -78,7 +78,7 @@ fn perform_benchmark<Q: PushPop>(

for _ in 0..args.iterations {
queue_a2b.push(0);
while queue_b2a.pop().is_none() {}
while !queue_b2a.pop() {}
}
});

Expand All @@ -90,7 +90,7 @@ fn perform_benchmark<Q: PushPop>(
start_benchmark_barrier.wait();

for _ in 0..args.iterations {
while queue_a2b.pop().is_none() {}
while !queue_a2b.pop() {}

queue_b2a.push(0);
}
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2-bb/lock-free/src/spsc/index_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ pub struct Producer<'a, PointerType: PointerTrait<UnsafeCell<u64>> + Debug> {
queue: &'a details::IndexQueue<PointerType>,
}

impl<PointerType: PointerTrait<UnsafeCell<usize>> + Debug> Producer<'_, PointerType> {
impl<PointerType: PointerTrait<UnsafeCell<u64>> + 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 {
unsafe { self.queue.push(t) }
}
}

impl<PointerType: PointerTrait<UnsafeCell<usize>> + Debug> Drop for Producer<'_, PointerType> {
impl<PointerType: PointerTrait<UnsafeCell<u64>> + Debug> Drop for Producer<'_, PointerType> {
fn drop(&mut self) {
self.queue.has_producer.store(true, Ordering::Relaxed);
}
Expand All @@ -77,15 +77,15 @@ pub struct Consumer<'a, PointerType: PointerTrait<UnsafeCell<u64>> + Debug> {
queue: &'a details::IndexQueue<PointerType>,
}

impl<PointerType: PointerTrait<UnsafeCell<usize>> + Debug> Consumer<'_, PointerType> {
impl<PointerType: PointerTrait<UnsafeCell<u64>> + 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<u64> {
unsafe { self.queue.pop() }
}
}

impl<PointerType: PointerTrait<UnsafeCell<usize>> + Debug> Drop for Consumer<'_, PointerType> {
impl<PointerType: PointerTrait<UnsafeCell<u64>> + Debug> Drop for Consumer<'_, PointerType> {
fn drop(&mut self) {
self.queue.has_consumer.store(true, Ordering::Relaxed);
}
Expand Down
19 changes: 17 additions & 2 deletions iceoryx2-cal/src/shm_allocator/pointer_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down

0 comments on commit 4b58bec

Please sign in to comment.