Class nebula::ros::SingleConsumerProcessor
template <typename T>
ClassList > nebula > ros > SingleConsumerProcessor
A thread-safe single-consumer queue processor that runs a callback function on items in a separate thread. The queue has a maximum size, so insertions block or are rejected if the consumer is slower than the producer. More...
#include <single_consumer_processor.hpp>
Public Types
Type | Name |
---|---|
typedef std::function< void(T &&)> | callback_t |
Public Functions
Type | Name |
---|---|
SingleConsumerProcessor (callback_t callback, size_t max_queue_size) Constructor. |
|
SingleConsumerProcessor (const SingleConsumerProcessor &) = delete |
|
SingleConsumerProcessor (SingleConsumerProcessor &&) = default |
|
bool | is_stopping () const Check if the processor is in stopping state. |
SingleConsumerProcessor & | operator= (const SingleConsumerProcessor &) = delete |
SingleConsumerProcessor & | operator= (SingleConsumerProcessor &&) = default |
void | push (T && item) Add an item to the queue for processing. Blocks until the item has been queued. |
void | stop () Stop the consumer thread. |
bool | try_push (T && item) Try to add an item to the queue for processing without blocking. |
~SingleConsumerProcessor () Destructor - stops the processing thread. |
Detailed Description
Template parameters:
T
The type of items to process
Public Types Documentation
typedef callback_t
using nebula::ros::SingleConsumerProcessor< T >::callback_t = std::function<void(T &&)>;
Public Functions Documentation
function SingleConsumerProcessor [1/3]
Constructor.
inline explicit nebula::ros::SingleConsumerProcessor::SingleConsumerProcessor (
callback_t callback,
size_t max_queue_size
)
Parameters:
callback
The callback function to execute on each itemmax_queue_size
The maximum size of the queue
function SingleConsumerProcessor [2/3]
nebula::ros::SingleConsumerProcessor::SingleConsumerProcessor (
const SingleConsumerProcessor &
) = delete
function SingleConsumerProcessor [3/3]
nebula::ros::SingleConsumerProcessor::SingleConsumerProcessor (
SingleConsumerProcessor &&
) = default
function is_stopping
Check if the processor is in stopping state.
inline bool nebula::ros::SingleConsumerProcessor::is_stopping () const
Returns:
True if stop() has been called, false otherwise
function operator=
SingleConsumerProcessor & nebula::ros::SingleConsumerProcessor::operator= (
const SingleConsumerProcessor &
) = delete
function operator=
SingleConsumerProcessor & nebula::ros::SingleConsumerProcessor::operator= (
SingleConsumerProcessor &&
) = default
function push
Add an item to the queue for processing. Blocks until the item has been queued.
inline void nebula::ros::SingleConsumerProcessor::push (
T && item
)
Parameters:
item
The item to process
function stop
Stop the consumer thread.
inline void nebula::ros::SingleConsumerProcessor::stop ()
function try_push
Try to add an item to the queue for processing without blocking.
inline bool nebula::ros::SingleConsumerProcessor::try_push (
T && item
)
Parameters:
item
The item to process
Returns:
True if the item was added, false if the queue is full
function ~SingleConsumerProcessor
Destructor - stops the processing thread.
inline nebula::ros::SingleConsumerProcessor::~SingleConsumerProcessor ()
The documentation for this class was generated from the following file nebula_ros/include/nebula_ros/common/single_consumer_processor.hpp