17 #ifndef CARTOGRAPHER_COMMON_LOCKLESS_QUEUE_H_ 18 #define CARTOGRAPHER_COMMON_LOCKLESS_QUEUE_H_ 24 #include "glog/logging.h" 51 void Push(std::unique_ptr<T> t) {
54 free_node->
data = std::move(t);
60 std::unique_ptr<T>
Pop() {
65 std::unique_ptr<T> data = std::move(node->
data);
67 return std::move(data);
89 while (node !=
nullptr) {
102 list_head_ptr = list_head->load();
103 node->
next = list_head_ptr;
104 }
while (!std::atomic_compare_exchange_strong_explicit(
105 list_head, &list_head_ptr, node, std::memory_order_release,
106 std::memory_order_relaxed));
113 Node* list_head_next_ptr;
116 if (list_head_ptr ==
nullptr) {
119 list_head_next_ptr = list_head_ptr->
next.load();
120 }
while (!std::atomic_compare_exchange_strong_explicit(
122 std::memory_order_relaxed, std::memory_order_relaxed));
123 return list_head_ptr;
130 if (node_itr ==
nullptr) {
136 Node*
const data_list_tail = node_itr;
140 Node* prev_node_itr =
nullptr;
141 while (node_itr !=
nullptr) {
142 Node*
const next_node_ptr = node_itr->
next;
143 node_itr->
next = prev_node_itr;
144 prev_node_itr = node_itr;
145 node_itr = next_node_ptr;
174 #endif // CARTOGRAPHER_COMMON_LOCKLESS_QUEUE_H_ std::unique_ptr< T > data
Node * PopNodeFromFreeList()
std::atomic< Node * > next
std::atomic< Node * > free_list_head_
void FreeNodes(Node *node)
std::unique_ptr< T > Pop()
void PushNodeToList(std::atomic< Node *> *list_head, Node *node)
void Push(std::unique_ptr< T > t)
std::atomic< Node * > incoming_data_list_head_