Push an item into the queue. Returns true on pushed. May run in parallel with steal(). Never run in parallel with pop() or another push().
| 70 | // May run in parallel with steal(). |
| 71 | // Never run in parallel with pop() or another push(). |
| 72 | bool push(const T& x) { |
| 73 | const size_t b = _bottom.load(butil::memory_order_relaxed); |
| 74 | const size_t t = _top.load(butil::memory_order_acquire); |
| 75 | if (b >= t + _capacity) { // Full queue. |
| 76 | return false; |
| 77 | } |
| 78 | _buffer[b & (_capacity - 1)] = x; |
| 79 | _bottom.store(b + 1, butil::memory_order_release); |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | // Pop an item from the queue. |
| 84 | // Returns true on popped and the item is written to `val'. |