Jobrocket
jobrocket::detail::FixedWorkStealingQueue Class Reference

#include <FixedWorkStealingQueue.hpp>

Overview

A lock-free work-stealing queue of a fixed, pre-allocated size. The queue is designed to act as a circular queue with no upper-bound, instead overwriting older elements when the capacity is reached - this is because the queue is intended to be used with short-running jobs and it's unlikely the queue will reach capacity while active jobs must be dequeued.

Public Member Functions

 FixedWorkStealingQueue ()=default
 
 FixedWorkStealingQueue (const size_t capacity)
 Initializes the queue with capacity max number of jobs. More...
 
 FixedWorkStealingQueue (const FixedWorkStealingQueue &other)=delete
 
FixedWorkStealingQueueoperator= (const FixedWorkStealingQueue &other)=delete
 
 FixedWorkStealingQueue (FixedWorkStealingQueue &&other) noexcept
 
FixedWorkStealingQueueoperator= (FixedWorkStealingQueue &&other) noexcept
 
void push (Job *job)
 
bool pop (Job *&target)
 
bool steal (Job *&target)
 
bool empty () const noexcept
 

Constructor & Destructor Documentation

◆ FixedWorkStealingQueue() [1/4]

jobrocket::detail::FixedWorkStealingQueue::FixedWorkStealingQueue ( )
default

◆ FixedWorkStealingQueue() [2/4]

jobrocket::detail::FixedWorkStealingQueue::FixedWorkStealingQueue ( const size_t  capacity)
inlineexplicit

Initializes the queue with capacity max number of jobs.

◆ FixedWorkStealingQueue() [3/4]

jobrocket::detail::FixedWorkStealingQueue::FixedWorkStealingQueue ( const FixedWorkStealingQueue other)
delete

◆ FixedWorkStealingQueue() [4/4]

jobrocket::detail::FixedWorkStealingQueue::FixedWorkStealingQueue ( FixedWorkStealingQueue &&  other)
inlinenoexcept

Member Function Documentation

◆ empty()

bool jobrocket::detail::FixedWorkStealingQueue::empty ( ) const
inlinenoexcept

Checks if the queue is empty - note: not guaranteed to be accurate in concurrent environments for all threads

◆ operator=() [1/2]

FixedWorkStealingQueue& jobrocket::detail::FixedWorkStealingQueue::operator= ( const FixedWorkStealingQueue other)
delete

◆ operator=() [2/2]

FixedWorkStealingQueue& jobrocket::detail::FixedWorkStealingQueue::operator= ( FixedWorkStealingQueue &&  other)
inlinenoexcept

◆ pop()

bool jobrocket::detail::FixedWorkStealingQueue::pop ( Job *&  target)
inline

Pops the next job from the bottom of the queue - must be called from the queues owning thread. Returns false if the pop operation failed.

◆ push()

void jobrocket::detail::FixedWorkStealingQueue::push ( Job job)
inline

Pushes a new job onto the bottom of the queue - must be called from the queues owning thread

◆ steal()

bool jobrocket::detail::FixedWorkStealingQueue::steal ( Job *&  target)
inline

Steals a job from the top of the queue - can be called from any thread. Returns false if the steal operation failed.