zero_pool/lib.rs
1//! # Zero-Pool
2//!
3//! High-performance thread pool with:
4//! - Lock-free MPMC queue with epoch-based memory reclamation
5//! - Function pointer dispatch (no trait objects / virtual dispatch)
6//! - Zero external dependencies
7//!
8//! ```rust
9//! use zero_pool::ZeroPool;
10//!
11//! struct Params { value: u64, result: *mut u64 }
12//!
13//! fn task(p: &Params) { unsafe { *p.result = p.value * 2; } }
14//!
15//! let pool = ZeroPool::new();
16//! let mut result = 0;
17//! pool.run(task, &[Params { value: 42, result: &raw mut result }]);
18//! assert_eq!(result, 84);
19//! ```
20
21mod pool;
22mod queue;
23mod retired_list;
24mod scope;
25mod task_batch;
26mod worker;
27
28use std::ptr::NonNull;
29use std::sync::OnceLock;
30
31pub use pool::ZeroPool;
32pub use scope::Scope;
33
34static GLOBAL_ZP: OnceLock<ZeroPool> = OnceLock::new();
35
36/// Returns a reference to the lazily initialized global pool.
37#[inline]
38pub fn global_pool() -> &'static ZeroPool {
39 GLOBAL_ZP.get_or_init(ZeroPool::new)
40}
41
42pub(crate) type TaskParamPointer = NonNull<u8>;
43pub(crate) type TaskFnPointer = fn(TaskParamPointer);
44
45#[repr(align(64))]
46pub(crate) struct PaddedType<T>(pub T);
47
48impl<T> std::ops::Deref for PaddedType<T> {
49 type Target = T;
50 fn deref(&self) -> &Self::Target {
51 &self.0
52 }
53}