carb::container::BufferedObject
Defined in carb/container/BufferedObject.h
-
template<typename T>
class BufferedObject Lock-Free Asynchronous Buffer Supports only 1 producer, 1 consumer.
BufferedObject is used when you have 1 producer and 1 consumer and both the producer and consumer are operating at different frequencies. The consumer only ever cares to see the latest data available.
Examples:
BufferedObject<int> b; assert(b.front() == 0); b.emplace_back(42); assert(b.front() == 0); b.pop_front(); assert(b.front() == 42);
BufferedObject<uint32_t> b{ in_place, 1U, 2U, 3U }; assert(b.front() == 3U); b.pop_front(); // do nothing, as nothing was pushed assert(b.front() == 3U); b.push_back(42U); assert(b.front() == 3U); b.pop_front(); assert(b.front() == 42U);
Public Functions
-
inline BufferedObject()
Create an async buffer from an array of 3 items using default ctors.
-
template<typename ...TArgs>
inline explicit constexpr BufferedObject(carb::cpp::in_place_t, TArgs&&... args) Create an async buffer from an array of 3 items.
- Parameters
args – arguments to forward to construct the elements of the buffer
-
inline ~BufferedObject()
Destroy async buffer.
-
template<typename ...TArgs>
inline void emplace_back(TArgs&&... args) Insert a new item into the container constructed in-place with the given args.
- Parameters
args – arguments to forward to construct newly produced value and move it onto the buffer
-
inline void push_back(T &&item)
Insert a new item into the container by moving item.
- Parameters
item – item to insert/move
-
inline void push_back(T const &item)
Insert a new item into the container by copying item.
- Parameters
item – item to copy
-
inline void pop_front()
Attempt to replace the front element of the container with a newly produced value.
If no new value was pushed/emplaced, this function does nothing.
-
inline BufferedObject()