bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
producer_consumer::ConcurrentQueue< T > Class Template Reference

A first-in first-out queue that several threads can push to and pop from. More...

#include <concurrent_queue.h>

Public Types

using value_type = T

Public Member Functions

bool push (T value)
 Add an item at the back of the queue.
std::optional< T > try_pop ()
 Take the item at the front of the queue, if there is one, without waiting.
template<typename Rep, typename Period>
std::optional< T > pop_for (std::chrono::duration< Rep, Period > timeout)
 Take the item at the front of the queue, waiting at most timeout for one.
std::optional< T > pop ()
 Take the item at the front of the queue, waiting until there is one.
void close ()
 Stop accepting items and wake every thread that waits for one.
bool is_closed () const
 Whether close() was called.
std::size_t size () const
 The number of items in the queue.
bool empty () const
 Whether the queue has no items.

Detailed Description

template<typename T>
class producer_consumer::ConcurrentQueue< T >

A first-in first-out queue that several threads can push to and pop from.

The thread pool keeps its tasks in one, and the MQTT subscriber the messages that the client's thread receives. pop() waits for an item; pop_for() waits at most a given time, and try_pop() does not wait. close() wakes every thread that waits: they get what is still in the queue, and then std::nullopt. push() on a closed queue drops the item and returns false.

Member Typedef Documentation

◆ value_type

template<typename T>
using bitsim::utils::concurrency::ConcurrentQueue< T >::value_type = T

Member Function Documentation

◆ close()

template<typename T>
void bitsim::utils::concurrency::ConcurrentQueue< T >::close ( )

Stop accepting items and wake every thread that waits for one.

◆ empty()

template<typename T>
bool bitsim::utils::concurrency::ConcurrentQueue< T >::empty ( ) const

Whether the queue has no items.

◆ is_closed()

template<typename T>
bool bitsim::utils::concurrency::ConcurrentQueue< T >::is_closed ( ) const

Whether close() was called.

◆ pop()

template<typename T>
std::optional< T > bitsim::utils::concurrency::ConcurrentQueue< T >::pop ( )

Take the item at the front of the queue, waiting until there is one.

Returns
std::nullopt only once the queue is closed and empty

◆ pop_for()

template<typename T>
template<typename Rep, typename Period>
std::optional< T > bitsim::utils::concurrency::ConcurrentQueue< T >::pop_for ( std::chrono::duration< Rep, Period > timeout)

Take the item at the front of the queue, waiting at most timeout for one.

Returns
std::nullopt if no item came in time, or the queue is closed and empty

◆ push()

template<typename T>
bool bitsim::utils::concurrency::ConcurrentQueue< T >::push ( T value)

Add an item at the back of the queue.

Returns
false if the queue is closed, and the item was dropped

◆ size()

template<typename T>
std::size_t bitsim::utils::concurrency::ConcurrentQueue< T >::size ( ) const

The number of items in the queue.

◆ try_pop()

template<typename T>
std::optional< T > bitsim::utils::concurrency::ConcurrentQueue< T >::try_pop ( )

Take the item at the front of the queue, if there is one, without waiting.


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