Class WorkerQueue

Class Documentation

class WorkerQueue

Per-worker job queue with local and stealable queues.

Workers submit jobs to their local queue. Jobs are migrated to the stealable queue periodically, allowing idle workers to steal them for load balancing.

Public Functions

void submit_job(JobBase::handle_type &job, JobPriority priority)

Submit a single job to the local queue.

Parameters:
  • jobJob handle to enqueue

  • priorityJob priority level

void submit_job_batch(std::span<JobBase::handle_type> jobs, JobPriority priority)

Submit multiple jobs to the local queue.

Parameters:
  • jobs – Span of job handles to enqueue

  • priorityJob priority level

std::optional<JobBase::handle_type> try_pop()

Try to pop a job from the local queue (highest priority first).

Returns:

Job handle if available, nullopt otherwise

size_t try_pop_bulk(JobBase::handle_type *jobs, size_t max_count)

Try to pop multiple jobs from the local queue.

Parameters:
  • jobs – Output buffer for job handles

  • max_count – Maximum number of jobs to pop

Returns:

Number of jobs actually popped

void migrate_jobs_to_stealable()

Move jobs from local queue to stealable queue.

Called periodically to make jobs available for work stealing.

size_t attempt_steal(JobBase::handle_type *jobs, size_t max_count)

Attempt to steal jobs from the stealable queue.

Parameters:
  • jobs – Output buffer for stolen job handles

  • max_count – Maximum number of jobs to steal

Returns:

Number of jobs actually stolen

inline std::array<std::atomic<size_t>, 3> &get_local_count()
inline std::array<std::atomic<size_t>, 3> &get_stealable_count()