allpix::ThreadPool::SafeQueue

Internal thread-safe queuing system. More…

#include <ThreadPool.hpp>

Public Functions

Name
SafeQueue(unsigned int max_standard_size, unsigned int max_priority_size)
Default constructor, initializes empty queue.
~SafeQueue()
Erases the queue and release waiting threads on destruction.
bool pop(T & out, size_t buffer_left =0)
Get the top value from the appropriate queue.
bool push(T value, bool wait =true)
Push a new value onto the standard queue, will block if queue is full.
bool push(uint64_t n, T value, bool wait =true)
Push a new value onto the priority queue.
void complete(uint64_t n)
Mark an identifier as complete.
uint64_t currentId() const
Get current identifier (last uncompleted)
bool valid() const
Return if the queue system in a valid state.
bool empty() const
Return if all related queues are empty or not.
size_t size() const
Return total size of values stored in both queues.
size_t prioritySize() const
Return total size of values stored in both queues.
void invalidate()
Invalidate the queue.

Detailed Description

template <typename T >
class allpix::ThreadPool::SafeQueue;

Internal thread-safe queuing system.

It internally consists of two separate queues

  • A standard queue pushed in order of jobs to process
  • An ordered priority queue for work that need linear processing

The priority queue is popped if the top of the queue can be directly processed. Otherwise work is popped from the default queue unless the priority queue size is too large.

Public Functions Documentation

function SafeQueue

SafeQueue(
    unsigned int max_standard_size,
    unsigned int max_priority_size
)

Default constructor, initializes empty queue.

Parameters:

  • max_standard_size Max size of the default queue
  • max_priority_size Max size of the priority queue

function ~SafeQueue

inline ~SafeQueue()

Erases the queue and release waiting threads on destruction.

function pop

bool pop(
    T & out,
    size_t buffer_left =0
)

Get the top value from the appropriate queue.

Parameters:

  • out Reference where the value at the top of the queue will be written to
  • buffer_left Optional number of jobs that should be left in priority buffer without stall on push

Return: True if a task was acquired or false if pop was exited for another reason

function push

bool push(
    T value,
    bool wait =true
)

Push a new value onto the standard queue, will block if queue is full.

Parameters:

  • value Value to push to the queue
  • wait If the push is allowed to stall if there is no capacity

Return: If the push was successful

function push

bool push(
    uint64_t n,
    T value,
    bool wait =true
)

Push a new value onto the priority queue.

Parameters:

  • n Ordering identifier for the priority
  • value Value to push to the queue
  • wait If the push is allowed to stall if there is no capacity

Return: If the push was successful

function complete

void complete(
    uint64_t n
)

Mark an identifier as complete.

Parameters:

  • n Identifier that is complete

function currentId

uint64_t currentId() const

Get current identifier (last uncompleted)

Return: Current identifier

function valid

bool valid() const

Return if the queue system in a valid state.

Return: True if the queue is valid, false if SafeQueue::invalidate has been called

function empty

bool empty() const

Return if all related queues are empty or not.

Return: True if queues are empty, false otherwise

function size

size_t size() const

Return total size of values stored in both queues.

Return: Size of of the internal queues

function prioritySize

size_t prioritySize() const

Return total size of values stored in both queues.

Return: Size of of the internal queues

function invalidate

void invalidate()

Invalidate the queue.


Updated on 2024-12-13 at 08:31:36 +0000