| 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 | } |
no test coverage detected