pub struct MpmcDisruptor;Expand description
Builder + constructor. Use MpmcDisruptor::with_consumers.
Implementations§
Source§impl MpmcDisruptor
impl MpmcDisruptor
Sourcepub fn with_consumers<T: Send + 'static>(
requested_capacity: usize,
consumer_count: usize,
) -> (DisruptorProducer<T>, Vec<DisruptorConsumer<T>>)
pub fn with_consumers<T: Send + 'static>( requested_capacity: usize, consumer_count: usize, ) -> (DisruptorProducer<T>, Vec<DisruptorConsumer<T>>)
Build a disruptor with consumer_count consumers and at least
requested_capacity slots (rounded up to power of two, floor 2).
All consumers see every published item (broadcast); for work-stealing
semantics use MpscFanIn with a single consumer per producer instead.
Examples found in repository?
More examples
examples/sample_app.rs (line 231)
226fn broadcast_to_strategy_and_risk() {
227 use subms_spsc_ring_buffer::MpmcDisruptor;
228
229 println!("\n== mpmc-disruptor: broadcast to strategy + risk ==");
230 let n = 8u64;
231 let (producer, mut consumers) = MpmcDisruptor::with_consumers::<Tick>(16, 2);
232 let (strategy, rest) = consumers.split_at_mut(1);
233 let strategy = &mut strategy[0];
234 let risk = &mut rest[0];
235
236 // Small and single-threaded so the tour self-verifies; the threaded
237 // broadcast path is pinned in the tests.
238 let mut published = 0u64;
239 let mut strat_seen = Vec::new();
240 let mut risk_seen = Vec::new();
241 while published < n {
242 while published < n
243 && producer
244 .try_publish(Tick {
245 seq: published,
246 price_cents: 50_000,
247 })
248 .is_ok()
249 {
250 published += 1;
251 }
252 while let Some(t) = strategy.try_consume() {
253 strat_seen.push(t.seq);
254 }
255 while let Some(t) = risk.try_consume() {
256 risk_seen.push(t.seq);
257 }
258 }
259 println!(
260 " published {published}; strategy saw {}, risk saw {}",
261 strat_seen.len(),
262 risk_seen.len()
263 );
264 let expected: Vec<u64> = (0..n).collect();
265 assert_eq!(strat_seen, expected, "strategy sees every tick");
266 assert_eq!(risk_seen, expected, "risk monitor sees every tick too");
267}Auto Trait Implementations§
impl Freeze for MpmcDisruptor
impl RefUnwindSafe for MpmcDisruptor
impl Send for MpmcDisruptor
impl Sync for MpmcDisruptor
impl Unpin for MpmcDisruptor
impl UnsafeUnpin for MpmcDisruptor
impl UnwindSafe for MpmcDisruptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more