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]
35pub fn automatic_width() -> usize {
36 let width = WIDTH.load(Ordering::Relaxed);
37 debug_assert!(width >= WIDTH_LIMIT.0, "WIDTH should not be zero");
38 debug_assert!(width <= WIDTH_LIMIT.1, "WIDTH is probably too large");
39 width
40}
41
42#[inline]
45pub fn automatic_amplification() -> usize {
46 let amplification = AMPLIFICATION.load(Ordering::Relaxed);
47 debug_assert!(amplification >= AMPLIFICATION_LIMIT.0, "amplification is too low");
48 debug_assert!(amplification <= AMPLIFICATION_LIMIT.1, "amplification is too high");
49 amplification
50}