Template Class SafeQueue

Class Documentation

template<typename T>
class SafeQueue

Thread Safe Queue for CANOpen Data Exchange.

This class is a wrapper around boost::lockfree::queue to provide thread safe data exchange between threads using the queue.

Template Parameters:

T – Type of the data to be exchanged

Public Functions

inline explicit SafeQueue(std::size_t capacity = 10)

Constructor for the SafeQueue.

Parameters:

capacity – Capacity of the queue

inline void push(T value)

Push a value to the queue.

Parameters:

value – Value to be pushed

inline std::optional<T> try_pop()

Try to pop a value from the queue.

Returns:

Value if available, boost::none otherwise

inline bool try_pop(T &value)

Try to pop a value from the queue.

Parameters:

value – Value to be returned

inline boost::optional<T> wait_and_pop()

Wait for a value to be available in the queue.

Returns:

Value if available, boost::none otherwise

inline void wait_and_pop(T &value)

Wait for a value to be available in the queue for a given timeout.

Parameters:

value – Value to be returned

inline boost::optional<T> wait_and_pop_for(const std::chrono::milliseconds &timeout)

Wait for a value to be available in the queue for a given timeout.

Parameters:

timeout – Timeout in milliseconds

Returns:

Value if available, boost::none otherwise

inline bool wait_and_pop_for(const std::chrono::milliseconds &timeout, T &value)

Wait for a value to be available in the queue for a given timeout.

Parameters:
  • timeout – Timeout in milliseconds

  • value – Value to be returned

inline bool empty() const