oxideav_core/execution.rs
1//! Runtime hints passed from the executor to codecs and filters.
2//!
3//! An [`ExecutionContext`] carries advisory information — today only a
4//! thread budget — that codecs can use to tune their internal
5//! parallelism. Codecs that don't care can ignore it; the default trait
6//! method on [`Decoder`](../../oxideav_codec/trait.Decoder.html) /
7//! [`Encoder`](../../oxideav_codec/trait.Encoder.html) is a no-op.
8
9/// Advisory runtime information handed to a codec after construction.
10///
11/// The struct is deliberately tiny for now. New fields can be added
12/// without breaking API consumers that already construct the value via
13/// [`ExecutionContext::serial`] or [`ExecutionContext::with_threads`].
14#[derive(Clone, Debug)]
15pub struct ExecutionContext {
16 /// Advisory cap on how many threads a codec may use for its own
17 /// internal parallelism (slice-parallel decode, GOP-parallel decode,
18 /// etc.). Always `≥ 1`. `1` means "caller requests serial execution
19 /// from this codec" — obey it unless you have a very good reason.
20 pub threads: usize,
21}
22
23impl ExecutionContext {
24 /// Ask the codec to run strictly single-threaded.
25 pub const fn serial() -> Self {
26 Self { threads: 1 }
27 }
28
29 /// Budget the codec to at most `threads` internal workers. Values
30 /// below 1 are clamped up to 1.
31 pub fn with_threads(threads: usize) -> Self {
32 Self {
33 threads: threads.max(1),
34 }
35 }
36}
37
38impl Default for ExecutionContext {
39 fn default() -> Self {
40 Self::serial()
41 }
42}