esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
boostlf.hpp
Go to the documentation of this file.
1#ifndef NDNPH_PORT_QUEUE_BOOSTLF_HPP
2#define NDNPH_PORT_QUEUE_BOOSTLF_HPP
3
4#include "../../core/common.hpp"
5
6#include <boost/lockfree/spsc_queue.hpp>
7
8namespace ndnph {
9namespace port_queue_boostlf {
10
12template<typename T, size_t capacity>
13class SafeQueue {
14public:
15 using Item = T;
16
17 bool push(Item item) {
18 return m_queue.push(item);
19 }
20
21 std::tuple<Item, bool> pop() {
22 Item item;
23 bool ok = m_queue.pop(item);
24 return std::make_tuple(std::move(item), ok);
25 }
26
27private:
28 using Q = typename boost::lockfree::spsc_queue<T, boost::lockfree::capacity<capacity>>;
29 Q m_queue;
30};
31
32} // namespace port_queue_boostlf
33
34#ifdef NDNPH_PORT_QUEUE_BOOSTLF
35namespace port {
36template<typename T, size_t capacity>
37using SafeQueue = port_queue_boostlf::SafeQueue<T, capacity>;
38} // namespace port
39#endif
40
41} // namespace ndnph
42
43#endif // NDNPH_PORT_QUEUE_BOOSTLF_HPP
Generic thread-safe queue, implemented with Boost Lockfree library.
Definition boostlf.hpp:13
std::tuple< Item, bool > pop()
Definition boostlf.hpp:21
bool push(Item item)
Definition boostlf.hpp:17
T Item
Definition boostlf.hpp:15
Definition fs.hpp:33