Skip to main content

Module work_queue_ws

Module work_queue_ws 

Source
Expand description

Chase-Lev work-stealing work queue for multi-threaded media pipelines.

This module exposes WorkQueue — a thread-safe, work-stealing task distributor backed by crossbeam_deque. Each call to WorkQueue::new creates one injector (global push point) and workers local steal handles.

§Design

  Producer         Injector          Worker 0 deque
  ────────►  push  ──────► steal ───►  pop / steal
                                        │
                          Worker 1 ─────┘  (steals from Worker 0)

Tasks pushed via WorkQueue::push land in the global injector queue. Worker threads call WorkQueue::steal which first drains the injector, then falls back to stealing from sibling workers. WorkQueue::len returns an approximate total count.

§Examples

use oximedia_core::work_queue_ws::WorkQueue;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};

let wq: WorkQueue<u32> = WorkQueue::new(2);
for i in 0..10_u32 {
    wq.push(i);
}
// Any thread can steal.
let _item = wq.steal();
assert!(wq.len() <= 10);

Structs§

WorkQueue
A work-stealing work queue for distributing tasks across multiple workers.