tuwunel_core/utils/stream/
band.rs1use std::sync::atomic::{AtomicUsize, Ordering};
2
3static WIDTH: AtomicUsize = AtomicUsize::new(32);
5
6static AMPLIFICATION: AtomicUsize = AtomicUsize::new(1024);
8
9pub const WIDTH_LIMIT: (usize, usize) = (1, 1024);
11
12pub const AMPLIFICATION_LIMIT: (usize, usize) = (32, 32768);
14
15pub fn set_width(width: usize) -> (usize, usize) {
19 let width = width.clamp(WIDTH_LIMIT.0, WIDTH_LIMIT.1);
20 (WIDTH.swap(width, Ordering::Relaxed), width)
21}
22
23pub fn set_amplification(width: usize) -> (usize, usize) {
27 let width = width.clamp(AMPLIFICATION_LIMIT.0, AMPLIFICATION_LIMIT.1);
28 (AMPLIFICATION.swap(width, Ordering::Relaxed), width)
29}
30
31#[inline]
36pub fn automatic_width() -> usize {
37 let width = WIDTH.load(Ordering::Relaxed);
38 debug_assert!(width >= WIDTH_LIMIT.0, "WIDTH should not be zero");
39 debug_assert!(width <= WIDTH_LIMIT.1, "WIDTH is probably too large");
40 width
41}
42
43#[inline]
46pub fn automatic_amplification() -> usize {
47 let amplification = AMPLIFICATION.load(Ordering::Relaxed);
48 debug_assert!(amplification >= AMPLIFICATION_LIMIT.0, "amplification is too low");
49 debug_assert!(amplification <= AMPLIFICATION_LIMIT.1, "amplification is too high");
50 amplification
51}