PushFront inserts w at the beginning of the queue. If queue is full returns w, otherwise returns default-constructed Work.
| 53 | // PushFront inserts w at the beginning of the queue. |
| 54 | // If queue is full returns w, otherwise returns default-constructed Work. |
| 55 | Work PushFront(Work w) { |
| 56 | unsigned front = front_.load(std::memory_order_relaxed); |
| 57 | Elem* e = &array_[front & kMask]; |
| 58 | uint8_t s = e->state.load(std::memory_order_relaxed); |
| 59 | if (s != kEmpty || |
| 60 | !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) |
| 61 | return w; |
| 62 | front_.store(front + 1 + (kSize << 1), std::memory_order_relaxed); |
| 63 | e->w = std::move(w); |
| 64 | e->state.store(kReady, std::memory_order_release); |
| 65 | return Work(); |
| 66 | } |
| 67 | |
| 68 | // PopFront removes and returns the first element in the queue. |
| 69 | // If the queue was empty returns default-constructed Work. |
no test coverage detected