MCPcopy Create free account
hub / github.com/catboost/catboost / DequeueAllSingleConsumer

Method DequeueAllSingleConsumer

util/thread/lfstack.h:182–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180 // elements are returned in order of dequeue (top to bottom; see example in unittest)
181 template <typename TCollection>
182 void DequeueAllSingleConsumer(TCollection* res) {
183 for (TNode* head = Head.load(std::memory_order_acquire); head;) {
184 if (Head.compare_exchange_weak(head, nullptr)) {
185 for (TNode* x = head; x;) {
186 res->push_back(std::move(x->Value));
187 x = x->Next;
188 }
189 EraseList(head); // with single consumer thread ABA does not happen
190 return;
191 }
192 }
193 }
194 bool IsEmpty() {
195 return Head.load() == nullptr; // without lock, so result is approximate
196 }

Callers 1

DequeuerAllMethod · 0.80

Calls 4

moveFunction · 0.50
EraseListFunction · 0.50
loadMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected