PushBack adds w at the end of the queue. If queue is full returns w, otherwise returns default-constructed Work.
| 84 | // PushBack adds w at the end of the queue. |
| 85 | // If queue is full returns w, otherwise returns default-constructed Work. |
| 86 | Work PushBack(Work w) { |
| 87 | EIGEN_MUTEX_LOCK lock(mutex_); |
| 88 | unsigned back = back_.load(std::memory_order_relaxed); |
| 89 | Elem* e = &array_[(back - 1) & kMask]; |
| 90 | uint8_t s = e->state.load(std::memory_order_relaxed); |
| 91 | if (s != kEmpty || |
| 92 | !e->state.compare_exchange_strong(s, kBusy, std::memory_order_acquire)) |
| 93 | return w; |
| 94 | back = ((back - 1) & kMask2) | (back & ~kMask2); |
| 95 | back_.store(back, std::memory_order_relaxed); |
| 96 | e->w = std::move(w); |
| 97 | e->state.store(kReady, std::memory_order_release); |
| 98 | return Work(); |
| 99 | } |
| 100 | |
| 101 | // PopBack removes and returns the last elements in the queue. |
| 102 | Work PopBack() { |
no test coverage detected