Returns the approximate number of items currently in the queue. Safe to call from both the producer and consumer threads.
| 491 | // Returns the approximate number of items currently in the queue. |
| 492 | // Safe to call from both the producer and consumer threads. |
| 493 | inline size_t size_approx() const AE_NO_TSAN |
| 494 | { |
| 495 | size_t result = 0; |
| 496 | Block* frontBlock_ = frontBlock.load(); |
| 497 | Block* block = frontBlock_; |
| 498 | do { |
| 499 | fence(memory_order_acquire); |
| 500 | size_t blockFront = block->front.load(); |
| 501 | size_t blockTail = block->tail.load(); |
| 502 | result += (blockTail - blockFront) & block->sizeMask; |
| 503 | block = block->next.load(); |
| 504 | } while (block != frontBlock_); |
| 505 | return result; |
| 506 | } |
| 507 | |
| 508 | // Returns the total number of items that could be enqueued without incurring |
| 509 | // an allocation when this queue is empty. |