35 void forEach(std::function<
void(T)> f)
const;
56 char pad0[UTL_CACHE_LINE_SIZE];
58 char pad1[UTL_CACHE_LINE_SIZE -
sizeof(Node*)];
59 std::atomic_bool _consumerLock;
60 char pad2[UTL_CACHE_LINE_SIZE -
sizeof(bool)];
62 char pad3[UTL_CACHE_LINE_SIZE -
sizeof(Node*)];
63 std::atomic_bool _producerLock;
64 char pad4[UTL_CACHE_LINE_SIZE -
sizeof(bool)];
71 : _consumerLock(false)
72 , _producerLock(false)
74 _head = _tail =
new Node();
82 while (_head !=
nullptr)
96 Node* node =
new Node(value);
100 while (!_producerLock.compare_exchange_weak(cur,
true, std::memory_order_acquire,
101 std::memory_order_relaxed))
111 _producerLock.store(
false, std::memory_order_release);
116 template <
typename T>
122 while (!_consumerLock.compare_exchange_weak(cur,
true, std::memory_order_acquire,
123 std::memory_order_relaxed))
130 Node* next = _head->next;
135 _consumerLock.store(
false, std::memory_order_relaxed);
144 _consumerLock.store(
false, std::memory_order_release);
154 template <
typename T>
162 if (node ==
nullptr)
break;
void forEach(std::function< void(T)> f) const
Execute the given function on each contained item (not thread-safe!).
~ConcurrentQueue()
Destructor.
Thread-safe queue structure.
bool deQ(T &value)
Dequeue an object.
void enQ(T value)
Queue an object.