Files
continuwuity/src/core/utils/stream/mod.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.5 KiB
Rust
Raw Normal View History

2024-11-30 08:27:51 +00:00
mod broadband;
2024-08-08 17:18:30 +00:00
mod cloned;
mod expect;
mod ignore;
mod iter_stream;
mod ready;
2024-09-30 06:46:54 +00:00
mod tools;
2024-12-04 02:11:43 +00:00
mod try_broadband;
2024-08-08 17:18:30 +00:00
mod try_ready;
2024-11-30 08:27:51 +00:00
mod wideband;
2024-08-08 17:18:30 +00:00
2024-11-30 08:27:51 +00:00
pub use broadband::BroadbandExt;
2024-08-08 17:18:30 +00:00
pub use cloned::Cloned;
pub use expect::TryExpect;
pub use ignore::TryIgnore;
pub use iter_stream::IterStream;
pub use ready::ReadyExt;
2024-09-30 06:46:54 +00:00
pub use tools::Tools;
2024-12-04 02:11:43 +00:00
pub use try_broadband::TryBroadbandExt;
2024-08-08 17:18:30 +00:00
pub use try_ready::TryReadyExt;
2024-11-30 08:27:51 +00:00
pub use wideband::WidebandExt;
/// Stream concurrency factor; this is a live value.
static WIDTH: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(32);
/// Practicable limits on the stream width
pub const WIDTH_LIMIT: (usize, usize) = (1, 1024);
/// Sets the live concurrency factor. The first return value is the previous
/// width which was replaced. The second return value is the value which was set
/// after any applied limits.
pub fn set_width(width: usize) -> (usize, usize) {
use std::sync::atomic::Ordering;
let width = width.clamp(WIDTH_LIMIT.0, WIDTH_LIMIT.1);
(WIDTH.swap(width, Ordering::Relaxed), width)
}
/// Used by stream operations where the concurrency factor hasn't been manually
/// supplied by the caller (most uses). Instead we provide a default value which
/// is adjusted at startup for the specific system and also dynamically.
#[inline]
pub fn automatic_width() -> usize {
use std::sync::atomic::Ordering;
let width = WIDTH.load(Ordering::Relaxed);
debug_assert!(width >= WIDTH_LIMIT.0, "WIDTH should not be zero");
debug_assert!(width <= WIDTH_LIMIT.1, "WIDTH is probably too large");
width
}