CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
mpsc_linked_queue.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_THREADS_MPSC_LINKED_QUEUE_H
10#define CPPCOMMON_THREADS_MPSC_LINKED_QUEUE_H
11
12#include <atomic>
13#include <cstring>
14#include <utility>
15
16namespace CppCommon {
17
19
31template<typename T>
33{
34public:
39
42
44
52 bool Enqueue(const T& item);
54
62 bool Enqueue(T&& item);
63
65
73 bool Dequeue(T& item);
74
75private:
76 struct Node
77 {
78 std::atomic<Node*> next;
79 T value;
80 };
81
82 typedef char cache_line_pad[128];
83
84 cache_line_pad _pad0;
85 std::atomic<Node*> _head;
86 cache_line_pad _pad1;
87 std::atomic<Node*> _tail;
88 cache_line_pad _pad2;
89};
90
93} // namespace CppCommon
94
95#include "mpsc_linked_queue.inl"
96
97#endif // CPPCOMMON_THREADS_MPSC_LINKED_QUEUE_H
Multiple producers / single consumer wait-free linked queue.
bool Enqueue(const T &item)
Enqueue an item into the linked queue (multiple producers threads method)
bool Dequeue(T &item)
Dequeue an item from the linked queue (single consumer thread method)
MPSCLinkedQueue(const MPSCLinkedQueue &)=delete
MPSCLinkedQueue(MPSCLinkedQueue &&)=delete
MPSCLinkedQueue & operator=(const MPSCLinkedQueue &)=delete
MPSCLinkedQueue & operator=(MPSCLinkedQueue &&)=delete
Multiple producers / single consumer wait-free linked queue inline implementation.
C++ Common project definitions.