use super::Runtime;
use crate::Result;
#[derive(Clone)]
pub(crate) struct Config {
pub(crate) qlen: usize,
pub(crate) nth: usize,
pub(crate) max_cache: usize,
pub(crate) id: u8,
pub(crate) name: &'static str,
}
pub(crate) const THREADS_MAX: usize = 1024;
pub(crate) const THREADS_MASK: usize = THREADS_MAX - 1;
pub struct Builder {
conf: Config,
}
impl Config {
pub(crate) const fn new(id: u8) -> Self {
Self {
qlen: 0,
nth: 0,
max_cache: 0,
id,
name: "",
}
}
}
impl Builder {
pub const fn new() -> Self {
Self {
conf: Config::new(0),
}
}
pub fn id(&mut self, id: u8) -> &mut Self {
self.conf.id = id;
self
}
pub fn name(&mut self, name: &'static str) -> &mut Self {
self.conf.name = name;
self
}
pub fn max_cache(&mut self, max_cache: usize) -> &mut Self {
self.conf.max_cache = max_cache;
self
}
pub fn qlen(&mut self, len: usize) -> &mut Self {
self.conf.qlen = len;
self
}
pub fn nth(&mut self, nth: usize) -> &mut Self {
if nth < THREADS_MAX {
self.conf.nth = nth;
} else {
self.conf.nth = THREADS_MAX;
}
self
}
pub fn build(&mut self) -> Result<()> {
Runtime::build(&self.conf)
}
}