Skip to content

Commit

Permalink
Rename param in Barrier#get_after and add tests of MultiProducerBarrier.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholassm committed Aug 9, 2024
1 parent 568f810 commit 9a17c1d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ pub const NONE: Sequence = -1;
#[doc(hidden)]
pub trait Barrier: Send + Sync {
/// Gets the sequence number of the barrier with relaxed memory ordering.
/// `prev` must be the last sequence returned from this barrier.
///
/// Note, to establish proper happens-before relationships (and thus proper synchronization),
/// the caller must issue a [`std::sync::atomic::fence`] with [`Ordering::Acquire`].
fn get_after(&self, lower_bound: Sequence) -> Sequence;
fn get_after(&self, prev: Sequence) -> Sequence;
}
47 changes: 46 additions & 1 deletion src/producer/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,57 @@ mod tests {
use super::*;

#[test]
fn test_log2() {
fn log2() {
assert_eq!(1, MultiProducerBarrier::log2(2));
assert_eq!(1, MultiProducerBarrier::log2(3));
assert_eq!(3, MultiProducerBarrier::log2(8));
assert_eq!(3, MultiProducerBarrier::log2(9));
assert_eq!(3, MultiProducerBarrier::log2(10));
assert_eq!(3, MultiProducerBarrier::log2(11));
}

#[test]
fn publication_of_single_event_for_small_barrier() {
let barrier = MultiProducerBarrier::new(64);

barrier.publish_range_relaxed(0, 1);

Check failure on line 336 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(0), 0);
}

#[test]
fn publication_of_range_for_small_barrier() {
let barrier = MultiProducerBarrier::new(64);

barrier.publish_range_relaxed(0, 10);

Check failure on line 345 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(0), 9);
}

#[test]
fn publication_of_range_wrapping_ringbuffer_for_small_barrier() {
let barrier = MultiProducerBarrier::new(64);

barrier.publish_range_relaxed(0, 50);

Check failure on line 354 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(0), 49);

barrier.publish_range_relaxed(50, 50);

Check failure on line 358 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(49), 99);
}

#[test]
fn publication_of_range_wrapping_ringbuffer_for_barrier() {
let barrier = MultiProducerBarrier::new(128);

barrier.publish_range_relaxed(0, 100);

Check failure on line 367 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(0), 99);
// Verify not published:

barrier.publish_range_relaxed(100, 100);

Check failure on line 372 in src/producer/multi.rs

View workflow job for this annotation

GitHub Actions / Test Coverage

no method named `publish_range_relaxed` found for struct `producer::multi::MultiProducerBarrier` in the current scope
// Verify published:
assert_eq!(barrier.get_after(99), 199);
}
}
2 changes: 1 addition & 1 deletion src/producer/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl SingleProducerBarrier {
impl Barrier for SingleProducerBarrier {
/// Gets the `Sequence` of the last published event.
#[inline]
fn get_after(&self, _lower_bound: Sequence) -> Sequence {
fn get_after(&self, _prev: Sequence) -> Sequence {
self.cursor.relaxed_value()
}
}
Expand Down

0 comments on commit 9a17c1d

Please sign in to comment.