Commit 7111b632 authored by Peter Alexander's avatar Peter Alexander Committed by Facebook Github Bot

Add ProducerConsumerQueue::capacity()

Summary: Simple addition. Easy to track externally, but might as well provide it in the class if it is readily available.

Reviewed By: yfeldblum

Differential Revision: D6093826

fbshipit-source-id: 9d8c02891b2cea9ce0d3f6ea78e1e0055b536eb8
parent dce47b8a
......@@ -167,6 +167,11 @@ struct ProducerConsumerQueue {
return ret;
}
// maximum number of items in the queue.
size_t capacity() const {
return size_ - 1;
}
private:
char pad0_[CacheLocality::kFalseSharingRange];
const uint32_t size_;
......
......@@ -288,3 +288,8 @@ TEST(PCQ, EmptyFull) {
EXPECT_FALSE(queue.write(3));
EXPECT_EQ(queue.sizeGuess(), 2);
}
TEST(PCQ, Capacity) {
folly::ProducerConsumerQueue<int> queue(3);
EXPECT_EQ(queue.capacity(), 2); // PCQ max size is buffer size - 1.
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment