15 #ifndef RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_
16 #define RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_
23 #include "rclcpp/experimental/buffers/buffer_implementation_base.hpp"
24 #include "rclcpp/logger.hpp"
25 #include "rclcpp/logging.hpp"
26 #include "rclcpp/macros.hpp"
27 #include "rclcpp/visibility_control.hpp"
31 namespace experimental
40 template<
typename BufferT>
45 : capacity_(capacity),
46 ring_buffer_(capacity),
47 write_index_(capacity_ - 1),
52 throw std::invalid_argument(
"capacity must be a positive, non-zero value");
66 std::lock_guard<std::mutex> lock(mutex_);
68 write_index_ = next_(write_index_);
69 ring_buffer_[write_index_] = std::move(request);
72 read_index_ = next_(read_index_);
86 std::lock_guard<std::mutex> lock(mutex_);
92 auto request = std::move(ring_buffer_[read_index_]);
93 read_index_ = next_(read_index_);
109 std::lock_guard<std::mutex> lock(mutex_);
121 std::lock_guard<std::mutex> lock(mutex_);
134 std::lock_guard<std::mutex> lock(mutex_);
148 inline size_t next_(
size_t val)
150 return (val + 1) % capacity_;
159 inline bool has_data_()
const
171 inline bool is_full_()
const
173 return size_ == capacity_;
178 std::vector<BufferT> ring_buffer_;
184 mutable std::mutex mutex_;
Store elements in a fixed-size, FIFO buffer.
bool has_data() const
Get if the ring buffer has at least one element stored.
bool is_full() const
Get if the size of the buffer is equal to its capacity.
BufferT dequeue()
Remove the oldest element from ring buffer.
size_t next(size_t val)
Get the next index value for the ring buffer.
void enqueue(BufferT request)
Add a new element to store in the ring buffer.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.