#![deny(unsafe_code)]
#![deny(missing_debug_implementations)]
#![warn(missing_docs)]
pub mod auto_optimizer;
pub mod changeset;
#[cfg(target_os = "linux")]
pub mod cpu_affinity;
#[cfg(not(target_os = "linux"))]
#[path = "cpu_affinity_stub.rs"]
pub mod cpu_affinity;
pub mod extreme_planner;
pub mod global;
pub mod graph;
pub mod runtime;
pub mod supervisor;
pub mod task_channel;
pub use auto_optimizer::{
AdaptiveQos, AutoOptimizer, CacheAccessPattern, CacheWarmupPredictor, LoadHistory,
LoadSample, LoadTrend, QosLevel,
};
pub use cpu_affinity::{AffinityManager, CpuAffinityConfig, CpuAffinityError, CpuId};
pub use extreme_planner::ExtremePlanner;
pub use global::{block_on, global_runtime, handle, init_global, spawn, BlockOnError, GlobalRuntime};
pub use graph::{
AffinityRule, DomainAssignment, DomainSnapshot, ExecutionDomain, GraphError,
NodeStatus, PlannedTopology, QueueDistribution, QueueMapping, QueueStrategy,
ResourceNode, RuntimeGraph, TopologyPlanner, WorkerAssignment,
};
pub use supervisor::{
BackoffConfig, ChildEntry, ChildKind, ChildSet, DomainSupervisor, ExitReason, HealthReport,
NodeSupervisor, QueueSupervisor, RestartStrategy, SupervisorConfig, SupervisorCore,
SupervisorError, SupervisorState,
};
pub use task_channel::{
TaskError, TaskOffloadChannel, TaskOutput, TaskPayload, TaskRequest, TaskResult,
};
#[derive(Debug, Clone, Copy)]
pub struct RuntimeConfig {
pub worker_threads: usize,
pub enable_io: bool,
pub enable_time: bool,
pub stack_size: usize,
}
impl RuntimeConfig {
pub fn new() -> Self {
Self {
worker_threads: num_cpus(),
enable_io: true,
enable_time: true,
stack_size: 2 * 1024 * 1024,
}
}
pub fn with_worker_threads(mut self, n: usize) -> Self {
self.worker_threads = n;
self
}
pub fn with_stack_size(mut self, size: usize) -> Self {
self.stack_size = size;
self
}
}
impl Default for RuntimeConfig {
fn default() -> Self {
Self::new()
}
}
fn num_cpus() -> usize {
std::thread::available_parallelism()
.map(|n| n.get())
.unwrap_or(4)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_runtime_config_default() {
let config = RuntimeConfig::new();
assert!(config.worker_threads >= 1);
assert!(config.enable_io);
assert!(config.enable_time);
assert_eq!(config.stack_size, 2 * 1024 * 1024);
}
#[test]
fn test_runtime_config_custom() {
let config = RuntimeConfig::new()
.with_worker_threads(8)
.with_stack_size(4 * 1024 * 1024);
assert_eq!(config.worker_threads, 8);
assert_eq!(config.stack_size, 4 * 1024 * 1024);
}
#[test]
fn test_num_cpus() {
let cpus = num_cpus();
assert!(cpus >= 1);
}
#[test]
fn test_runtime_config_debug() {
let config = RuntimeConfig::new();
let debug_str = format!("{:?}", config);
assert!(!debug_str.is_empty());
assert!(debug_str.contains("RuntimeConfig"));
}
#[test]
fn test_runtime_config_clone() {
let config = RuntimeConfig::new().with_worker_threads(4);
let cloned = config;
assert_eq!(config.worker_threads, cloned.worker_threads);
assert_eq!(config.stack_size, cloned.stack_size);
}
#[test]
fn test_runtime_config_default_trait() {
let config: RuntimeConfig = Default::default();
assert!(config.worker_threads >= 1);
}
#[test]
fn test_with_worker_threads_zero() {
let config = RuntimeConfig::new().with_worker_threads(0);
assert_eq!(config.worker_threads, 0);
}
#[test]
fn test_with_stack_size_small() {
let config = RuntimeConfig::new().with_stack_size(4096);
assert_eq!(config.stack_size, 4096);
}
#[test]
fn test_runtime_config_enable_flags() {
let mut config = RuntimeConfig::new();
config.enable_io = false;
config.enable_time = false;
assert!(!config.enable_io);
assert!(!config.enable_time);
}
}