CppCommon  1.0.4.1
C++ Common Library
mpsc_linked_batcher.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_THREADS_MPSC_LINKED_BATCHER_H
10 #define CPPCOMMON_THREADS_MPSC_LINKED_BATCHER_H
11 
12 #include <atomic>
13 #include <cassert>
14 #include <functional>
15 #include <utility>
16 
17 namespace CppCommon {
18 
20 
32 template<typename T>
34 {
35 public:
40 
43 
45 
53  bool Enqueue(const T& item);
55 
63  bool Enqueue(T&& item);
64 
66 
74  bool Dequeue(const std::function<void(const T&)>& handler = [](const int&){});
75 
76 private:
77  struct Node
78  {
79  Node* next;
80  T value;
81  };
82 
83  std::atomic<Node*> _head;
84 };
85 
86 } // namespace CppCommon
87 
88 #include "mpsc_linked_batcher.inl"
89 
90 #endif // CPPCOMMON_THREADS_MPSC_LINKED_BATCHER_H
Multiple producers / single consumer wait-free linked batcher.
MPSCLinkedBatcher(const MPSCLinkedBatcher &)=delete
bool Dequeue(const std::function< void(const T &)> &handler=[](const int &){})
Dequeue all items from the linked queue (single consumer thread method)
MPSCLinkedBatcher & operator=(const MPSCLinkedBatcher &)=delete
bool Enqueue(const T &item)
Enqueue an item into the linked batcher (multiple producers threads method)
MPSCLinkedBatcher(MPSCLinkedBatcher &&)=delete
MPSCLinkedBatcher & operator=(MPSCLinkedBatcher &&)=delete
Multiple producers / single consumer wait-free linked batcher inline implementation.
C++ Common project definitions.
Definition: token_bucket.h:15