1use std::sync::Arc;
2use std::sync::atomic::{AtomicUsize, Ordering};
3
4#[derive(Debug, Clone, Default)]
6#[non_exhaustive]
7pub enum DispatchStrategy {
8 #[default]
10 RoundRobin,
11 LeastLoaded,
13}
14
15#[derive(Clone)]
17pub struct RoundRobinDispatcher {
18 counter: Arc<AtomicUsize>,
19 slots: usize,
20}
21
22impl RoundRobinDispatcher {
23 pub fn new(slots: usize) -> Self {
25 Self {
26 counter: Arc::new(AtomicUsize::new(0)),
27 slots,
28 }
29 }
30
31 pub fn next(&self) -> usize {
33 if self.slots == 0 {
34 return 0;
35 }
36 self.counter.fetch_add(1, Ordering::Relaxed) % self.slots
37 }
38}