Callisto Engine
cl::threading::blocking_queue< T > Class Template Reference

A thread-safe blocking concurrent queue. More...

#include <blocking_queue.h>

Public Member Functions

void push (T &&item)
 Pushes a new item to the queue, under a lock. More...
 
cl::api_status pop (T *next)
 Pops an item from the queue. More...
 
size_t workload_count () const
 Returns the current workload count. More...
 
void close ()
 close the queue More...
 

Detailed Description

template<typename T>
class cl::threading::blocking_queue< T >

A thread-safe blocking concurrent queue.

The queue will acquire a mutex internally while pushing to it, and likewise while popping (hence, no synchronization needs to happen when pushing/popping to the queue itself).

Popping values from the queue will block the thread it's running on if the queue is empty. The queue is unbounded in terms of how many items can be pushed to it.

Template Parameters
TThe type of work objects this queue holds

Member Function Documentation

◆ close()

template<typename T >
void cl::threading::blocking_queue< T >::close ( )
inline

close the queue

This essentially marks the queue as consumed/done and it will stop processing values. If a thread is waiting on a pop(), it will be unblocked and flagged to return without producing a result.

◆ pop()

template<typename T >
cl::api_status cl::threading::blocking_queue< T >::pop ( T *  next)
inline

Pops an item from the queue.

If the queue is empty, this function will block the calling thread. The thread will only wake up if from this state if:

  1. Another thread calls push()
  2. Another thread calls close()
Parameters
nextA pointer that will hold the next item on success
Returns
api_status::ok on successful pop, api_status::no_result if closed

◆ push()

template<typename T >
void cl::threading::blocking_queue< T >::push ( T &&  item)
inline

Pushes a new item to the queue, under a lock.

Parameters
itemThe item to push to the queue

◆ workload_count()

template<typename T >
size_t cl::threading::blocking_queue< T >::workload_count ( ) const
inline

Returns the current workload count.

Returns
the current number of items in the queue

The documentation for this class was generated from the following file: