52 bool Init(uint64_t size);
53 bool Init(uint64_t size, google::protobuf::Arena* arena);
62 uint64_t
Head() {
return head_.load(); }
63 uint64_t
Tail() {
return tail_.load(); }
64 uint64_t
Commit() {
return commit_.load(); }
70 if (GetIndex(index) <
Tail() - 1) {
71 index = GetIndex(index + 1);
76 if (index <
Size() - 1) {
88 index = GetIndex(head_ + 1);
100 index = GetIndex(tail_ - 1);
112 ptr = pool_[GetIndex(i)];
115 if (i >
Size() - 1) {
118 ptr = &normal_queue[i];
125 uint64_t GetIndex(uint64_t num);
131 uint64_t pool_size_ = 0;
132 std::vector<T*> pool_;
134 std::deque<T> normal_queue;
187 uint64_t new_tail = 0;
188 uint64_t old_commit = 0;
189 uint64_t old_tail = tail_.load(std::memory_order_acquire);
191 new_tail = old_tail + 1;
192 if (GetIndex(new_tail) ==
193 GetIndex(head_.load(std::memory_order_acquire))) {
196 }
while (!tail_.compare_exchange_weak(old_tail, new_tail,
197 std::memory_order_acq_rel,
198 std::memory_order_relaxed));
200 old_commit = old_tail;
202 old_commit, new_tail, std::memory_order_acq_rel,
203 std::memory_order_relaxed)));
204 return pool_[GetIndex(old_tail)];
207 normal_queue.push_back(instance);
208 return &normal_queue.back();
218 uint64_t new_head = 0;
219 uint64_t old_head = head_.load(std::memory_order_acquire);
221 new_head = old_head + 1;
222 if (new_head == commit_.load(std::memory_order_acquire)) {
225 }
while (!head_.compare_exchange_weak(old_head, new_head,
226 std::memory_order_acq_rel,
227 std::memory_order_relaxed));
228 return pool_[GetIndex(new_head)];
230 normal_queue.pop_front();