18 #include <boost/lockfree/queue.hpp>
19 #include <boost/optional.hpp>
20 #include <boost/thread.hpp>
51 std::size_t capacity_;
52 std::unique_ptr<boost::lockfree::queue<T>> queue_;
60 : capacity_(capacity), queue_(new boost::lockfree::queue<T>(capacity_))
68 void push(T value) { queue_->push(std::move(value)); }
77 if (queue_->pop(value))
return std::optional<T>(std::move(value));
78 return std::optional<T>();
87 if (queue_->pop(value))
return true;
98 while (!queue_->pop(value)) boost::this_thread::yield();
108 while (!queue_->pop(value)) boost::this_thread::yield();
119 auto start_time = std::chrono::steady_clock::now();
120 while (!queue_->pop(value))
123 timeout != std::chrono::milliseconds::zero() &&
124 std::chrono::steady_clock::now() - start_time >= timeout)
126 boost::this_thread::yield();
138 auto start_time = std::chrono::steady_clock::now();
139 while (!queue_->pop(value))
142 timeout != std::chrono::milliseconds::zero() &&
143 std::chrono::steady_clock::now() - start_time >= timeout)
145 boost::this_thread::yield();
150 bool empty()
const {
return queue_->empty(); }
Thread Safe Queue for CANOpen Data Exchange.
Definition: exchange.hpp:49
bool try_pop(T &value)
Try to pop a value from the queue.
Definition: exchange.hpp:85
void wait_and_pop(T &value)
Wait for a value to be available in the queue for a given timeout.
Definition: exchange.hpp:106
std::optional< T > try_pop()
Try to pop a value from the queue.
Definition: exchange.hpp:74
SafeQueue(std::size_t capacity=10)
Constructor for the SafeQueue.
Definition: exchange.hpp:59
boost::optional< T > wait_and_pop()
Wait for a value to be available in the queue.
Definition: exchange.hpp:95
bool empty() const
Definition: exchange.hpp:150
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.
Definition: exchange.hpp:116
void push(T value)
Push a value to the queue.
Definition: exchange.hpp:68
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.
Definition: exchange.hpp:136
Definition: configuration_manager.hpp:28
Definition: exchange.hpp:26
uint32_t data_
Definition: exchange.hpp:30
uint8_t subindex_
Definition: exchange.hpp:29
uint16_t index_
Definition: exchange.hpp:28
Definition: exchange.hpp:34
uint16_t eec
Definition: exchange.hpp:36
uint8_t er
Definition: exchange.hpp:37
uint8_t msef[5]
Definition: exchange.hpp:38