byteor_pipeline_exec/thread_init.rs
1//! Thread init hook types.
2//!
3//! Motivation: latency-sensitive deployments often want to apply per-thread operations
4//! (CPU pinning, priority, tracing spans, etc.) at the start of each executor thread,
5//! before entering any hot loops.
6//!
7//! This module provides an executor-owned hook contract so higher layers (enterprise runtime,
8//! benches, etc.) can plug in platform-specific tuning without forking runner logic.
9
10use crate::ExecError;
11
12use std::sync::Arc;
13
14/// Role kind for thread init context.
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16#[non_exhaustive]
17pub enum RoleKind {
18 /// A stage hot-loop thread.
19 Stage,
20 /// A bridge role thread.
21 Bridge,
22 /// A router role thread.
23 Router,
24 /// A merge role thread.
25 Merge,
26}
27
28/// Context passed to the thread init hook.
29#[derive(Clone, Debug, PartialEq, Eq)]
30pub struct ThreadInitContext {
31 /// Stable role name (also used as the OS thread name when set).
32 pub role_name: String,
33 /// Role kind.
34 pub role_kind: RoleKind,
35}
36
37impl ThreadInitContext {
38 /// Create a new context.
39 pub fn new(role_name: String, role_kind: RoleKind) -> Self {
40 Self {
41 role_name,
42 role_kind,
43 }
44 }
45}
46
47/// Hook invoked at the start of an executor thread.
48///
49/// If the hook returns an error, role execution fails.
50pub type ThreadInitHook =
51 Arc<dyn Fn(&ThreadInitContext) -> Result<(), ExecError> + Send + Sync + 'static>;