PopFront removes and returns the first element in the queue. If the queue was empty returns default-constructed Work.
| 68 | // PopFront removes and returns the first element in the queue. |
| 69 | // If the queue was empty returns default-constructed Work. |
| 70 | Work PopFront() { |
| 71 | unsigned front = front_.load(std::memory_order_relaxed); |
| 72 | Elem* e = &array_[(front - 1) & kMask]; |
| 73 | uint8_t s = e->state.load(std::memory_order_relaxed); |
| 74 | if (s != kReady || |
| 75 | !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) |
| 76 | return Work(); |
| 77 | Work w = std::move(e->w); |
| 78 | e->state.store(kEmpty, std::memory_order_release); |
| 79 | front = ((front - 1) & kMask2) | (front & ~kMask2); |
| 80 | front_.store(front, std::memory_order_relaxed); |
| 81 | return w; |
| 82 | } |
| 83 | |
| 84 | // PushBack adds w at the end of the queue. |
| 85 | // If queue is full returns w, otherwise returns default-constructed Work. |
no test coverage detected