CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
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
17namespace CppCommon {
18
20
32template<typename T>
34{
35public:
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
76private:
77 struct Node
78 {
79 Node* next;
80 T value;
81 };
82
83 std::atomic<Node*> _head;
84};
85
86} // namespace CppCommon
87
89
90#endif // CPPCOMMON_THREADS_MPSC_LINKED_BATCHER_H
Multiple producers / single consumer wait-free linked batcher.
MPSCLinkedBatcher & operator=(const MPSCLinkedBatcher &)=delete
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)
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.