-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation and structure.
- Hide structs and traits not part of the api.
- Loading branch information
1 parent
de88b74
commit bb92914
Showing
8 changed files
with
340 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
use std::{sync::Arc, thread::JoinHandle}; | ||
use crate::{barrier::Barrier, cursor::Cursor, Sequence}; | ||
|
||
#[doc(hidden)] | ||
pub struct Consumer { | ||
join_handle: Option<JoinHandle<()>>, | ||
} | ||
|
||
impl Consumer { | ||
pub(crate) fn new(join_handle: JoinHandle<()>) -> Self { | ||
Self { | ||
join_handle: Some(join_handle), | ||
} | ||
} | ||
|
||
pub(crate) fn join(&mut self) { | ||
if let Some(h) = self.join_handle.take() { h.join().expect("Consumer should not panic.") } | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
pub struct ConsumerBarrier { | ||
cursors: Vec<Arc<Cursor>> | ||
} | ||
|
||
impl ConsumerBarrier { | ||
pub(crate) fn new() -> Self { | ||
Self { | ||
cursors: vec![] | ||
} | ||
} | ||
|
||
pub(crate) fn add(&mut self, cursor: Arc<Cursor>) { | ||
self.cursors.push(cursor); | ||
} | ||
} | ||
|
||
impl Barrier for ConsumerBarrier { | ||
fn new(_size: usize) -> Self { | ||
Self { | ||
cursors: vec![] | ||
} | ||
/// Gets the available `Sequence` of the slowest consumer. | ||
/// | ||
/// Note, to establish proper happens-before relationships (and thus proper synchronization), | ||
/// the caller must issue a [`std::sync::atomic::fence`] with | ||
/// [`Ordering::Acquire`](std::sync::atomic::Ordering::Acquire). | ||
pub(crate) fn get(&self) -> Sequence { | ||
self.get_after(0) | ||
} | ||
} | ||
|
||
impl Barrier for ConsumerBarrier { | ||
/// Gets the available `Sequence` of the slowest consumer. | ||
fn get_relaxed(&self, _lower_bound: Sequence) -> Sequence { | ||
fn get_after(&self, _lower_bound: Sequence) -> Sequence { | ||
self.cursors.iter().fold(i64::MAX, |min_sequence, cursor| { | ||
let sequence = cursor.relaxed_value(); | ||
std::cmp::min(sequence, min_sequence) | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) struct Consumer { | ||
join_handle: Option<JoinHandle<()>>, | ||
} | ||
|
||
impl Consumer { | ||
pub(crate) fn new(join_handle: JoinHandle<()>) -> Self { | ||
Self { | ||
join_handle: Some(join_handle), | ||
} | ||
} | ||
|
||
pub(crate) fn join(&mut self) { | ||
if let Some(h) = self.join_handle.take() { h.join().expect("Consumer should not panic.") } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.