use super::*;
#[repr(align(128))]
#[derive(Debug, Default)]
pub struct AlignedAtomicUsize {
pub(crate) value: AtomicUsize,
}
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
#[derive(Debug, Default)]
pub(crate) struct EngineWorkerSlot {
pub(crate) epoch: AtomicUsize,
pub(crate) parked: AtomicUsize,
pub(crate) lock: Mutex<()>,
pub(crate) wake: Condvar,
}
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
#[derive(Debug, Default)]
pub(crate) struct EnginePoolShared {
pub(crate) active_job: AtomicUsize,
pub(crate) active_workers: AtomicUsize,
pub(crate) spin_limit: AtomicUsize,
pub(crate) shutdown: AtomicUsize,
pub(crate) caller_parked: AlignedAtomicUsize,
pub(crate) caller_lock: Mutex<()>,
pub(crate) wake_caller: Condvar,
pub(crate) slots: Vec<EngineWorkerSlot>,
}
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
pub(crate) struct EngineDispatchJob {
pub(crate) payload_ptr: usize,
pub(crate) invoke: unsafe fn(usize, usize),
pub(crate) workers_done: AlignedAtomicUsize,
}
#[cfg(not(target_arch = "wasm32"))]
pub(crate) struct ParallelChunksState<'a, WorkFn>
where
WorkFn: Fn(usize, usize, usize) + Sync,
{
pub(crate) total_items: usize,
pub(crate) grain_size: usize,
pub(crate) chunk_count: usize,
pub(crate) next_chunk: AlignedAtomicUsize,
pub(crate) work_fn: &'a WorkFn,
}
#[cfg(not(target_arch = "wasm32"))]
pub(crate) struct ParallelStealState<'a, ItemType, WorkFn>
where
ItemType: Sync,
WorkFn: Fn(usize, &ItemType, usize) + Sync,
{
pub(crate) items: &'a [ItemType],
pub(crate) next_index: AlignedAtomicUsize,
pub(crate) work_fn: &'a WorkFn,
}
#[derive(Debug)]
pub struct EngineWorkerPool {
pub(crate) worker_count: usize,
#[cfg(not(target_arch = "wasm32"))]
pub(crate) dispatch_guard: Mutex<()>,
#[cfg(not(target_arch = "wasm32"))]
pub(crate) shared: Arc<EnginePoolShared>,
#[cfg(not(target_arch = "wasm32"))]
pub(crate) handles: Vec<JoinHandle<()>>,
}