Skip to main content

Context

Struct Context 

Source
pub struct Context {
Show 17 fields pub inputs: Vec<Option<Packet>>, pub input_batches: Vec<Vec<Packet>>, pub staging: Vec<Vec<Packet>>, pub next_bounds: Vec<Option<Timestamp>>, pub input_ts: Timestamp, pub node_name: String, pub kernel_name: String, pub in_ports: Arc<PortTable>, pub out_ports: Arc<PortTable>, pub options: Arc<Options>, pub side_packets: Arc<BTreeMap<String, Packet>>, pub shared: Arc<GraphShared>, pub inputs_done: Vec<bool>, pub error_msg: Option<String>, pub close_reason: i32, pub source_done: bool, pub source_yield: Option<Duration>, /* private fields */
}
Expand description

一次算子调用的上下文。

Fields§

§inputs: Vec<Option<Packet>>

本次的输入。None 表示已被 take_input 取走(CoW 省拷贝的前提)。

§input_batches: Vec<Vec<Packet>>

批处理(batch 策略)时本口的多个包;单包策略下恒空、走 inputs。见 input_count/input_at。

§staging: Vec<Vec<Packet>>

每个输出口的暂存队列;process 返回后由引擎分发。

§next_bounds: Vec<Option<Timestamp>>

算子显式推进的时间戳边界(不产出时用它告知下游)。

§input_ts: Timestamp§node_name: String§kernel_name: String§in_ports: Arc<PortTable>§out_ports: Arc<PortTable>§options: Arc<Options>§side_packets: Arc<BTreeMap<String, Packet>>§shared: Arc<GraphShared>§inputs_done: Vec<bool>

输入口是否已终结(上游关闭且排空)。

§error_msg: Option<String>

算子经 set_error 提供的失败原因。

§close_reason: i32

供 lmflow_ctx_close_reason 返回;进入 close 前由引擎写入。

§source_done: bool

源算子经 source_done() 自报「已产完」;引擎在 process 返回后读取。

§source_yield: Option<Duration>

源算子协作式让出 worker,并请求引擎在指定延迟后再次调度。

Implementations§

Source§

impl Context

Source

pub fn new( node_name: String, kernel_name: String, in_ports: Arc<PortTable>, out_ports: Arc<PortTable>, options: Arc<Options>, side_packets: Arc<BTreeMap<String, Packet>>, shared: Arc<GraphShared>, ) -> Self

Source

pub fn reset(&mut self)

每次调用前复位(输入由调用方填充)。

Source

pub fn clear_inputs(&mut self)

处理结束后立即释放本次输入的引用。

这条至关重要:若把输入留到下次 reset 才清,上游节点就会一直持有已处理完的包, 于是下游 take_input 看到的引用数 ≥ 2,CoW 必然复制 —— 「线性管线零拷贝」 这条不变量(docs/design.md §3.4)会对任何多节点管线静默失效。 顺带也避免大帧被无谓地多留一个周期。

Source

pub fn discard_staging(&mut self)

失败时丢弃暂存,不把半成品输出传播下去(docs/design.md §7.7)。

Source

pub fn node_name_cstr(&self) -> *const c_char

Source

pub fn kernel_name_cstr(&self) -> *const c_char

Source

pub fn intern(&self, s: &str) -> *const c_char

Source

pub fn input(&self, idx: usize) -> Option<&Packet>

Source

pub fn input_count(&self, idx: usize) -> usize

本次调用某输入口的包数(单包策略恒 0/1;batch 策略为该批实际大小)。

Source

pub fn input_at(&self, idx: usize, k: usize) -> Option<&Packet>

借用某输入口的第 k 个包(单包策略仅 k==0 有效)。统一单包 / 批两种交付。

Source

pub fn take_input(&mut self, idx: usize) -> Packet

取走输入包:所有权移交算子,槽位变空。这是 CoW 零拷贝的前提 —— 不取走的话上下文仍持一份引用,make_mutable 必然复制。

Source

pub fn emit(&mut self, out_idx: usize, pkt: Packet) -> Result<()>

Source

pub fn forward(&mut self, in_idx: usize, out_idx: usize) -> Result<()>

零拷贝直通:只克隆引用计数。

Source

pub fn set_next_bound(&mut self, out_idx: usize, bound: Timestamp)

Source

pub fn log(&self, level: i32, msg: &str)

Source

pub fn set_error(&mut self, msg: &str)

Source

pub fn take_error(&mut self, code: i32) -> Error

组合出带节点名前缀的错误。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.