Apollo 10.0
自动驾驶开放平台
apollo::cyber::base::ArenaQueue< T > 模板类 参考

#include <arena_queue.h>

apollo::cyber::base::ArenaQueue< T > 的协作图:

Public 类型

using value_type = T
 
using size_type = uint64_t
 

Public 成员函数

 ArenaQueue ()
 
ArenaQueueoperator= (const ArenaQueue &other)=delete
 
 ArenaQueue (const ArenaQueue &other)=delete
 
 ~ArenaQueue ()
 
bool Init (uint64_t size)
 
bool Init (uint64_t size, google::protobuf::Arena *arena)
 
T * AddBack ()
 
T * PopFront ()
 
T * GetBack ()
 
T * GetFront ()
 
uint64_t Size ()
 
bool Empty ()
 
uint64_t Head ()
 
uint64_t Tail ()
 
uint64_t Commit ()
 
bool NextIndex (uint64_t &index)
 
bool GetHeadIndex (uint64_t &index)
 
bool GetTailIndex (uint64_t &index)
 
bool GetEleByIndex (uint64_t i, T *&ptr)
 
bool IsArenaEnable ()
 

详细描述

template<typename T>
class apollo::cyber::base::ArenaQueue< T >

在文件 arena_queue.h42 行定义.

成员类型定义说明

◆ size_type

template<typename T >
using apollo::cyber::base::ArenaQueue< T >::size_type = uint64_t

在文件 arena_queue.h45 行定义.

◆ value_type

template<typename T >
using apollo::cyber::base::ArenaQueue< T >::value_type = T

在文件 arena_queue.h44 行定义.

构造及析构函数说明

◆ ArenaQueue() [1/2]

template<typename T >
apollo::cyber::base::ArenaQueue< T >::ArenaQueue ( )
inline

在文件 arena_queue.h48 行定义.

48{}

◆ ArenaQueue() [2/2]

template<typename T >
apollo::cyber::base::ArenaQueue< T >::ArenaQueue ( const ArenaQueue< T > &  other)
delete

◆ ~ArenaQueue()

template<typename T >
apollo::cyber::base::ArenaQueue< T >::~ArenaQueue ( )

在文件 arena_queue.h138 行定义.

138{}

成员函数说明

◆ AddBack()

template<typename T >
T * apollo::cyber::base::ArenaQueue< T >::AddBack ( )

在文件 arena_queue.h185 行定义.

185 {
186 if (arena_) {
187 uint64_t new_tail = 0;
188 uint64_t old_commit = 0;
189 uint64_t old_tail = tail_.load(std::memory_order_acquire);
190 do {
191 new_tail = old_tail + 1;
192 if (GetIndex(new_tail) ==
193 GetIndex(head_.load(std::memory_order_acquire))) {
194 return nullptr;
195 }
196 } while (!tail_.compare_exchange_weak(old_tail, new_tail,
197 std::memory_order_acq_rel,
198 std::memory_order_relaxed));
199 do {
200 old_commit = old_tail;
201 } while (cyber_unlikely(!commit_.compare_exchange_weak(
202 old_commit, new_tail, std::memory_order_acq_rel,
203 std::memory_order_relaxed)));
204 return pool_[GetIndex(old_tail)];
205 } else {
206 T instance;
207 normal_queue.push_back(instance);
208 return &normal_queue.back();
209 }
210}
#define cyber_unlikely(x)
Definition macros.h:30

◆ Commit()

template<typename T >
uint64_t apollo::cyber::base::ArenaQueue< T >::Commit ( )
inline

在文件 arena_queue.h64 行定义.

64{ return commit_.load(); }

◆ Empty()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::Empty ( )
inline

在文件 arena_queue.h245 行定义.

245 {
246 if (arena_) {
247 return Size() == 0;
248 } else {
249 return normal_queue.empty();
250 }
251}

◆ GetBack()

template<typename T >
T * apollo::cyber::base::ArenaQueue< T >::GetBack ( )

在文件 arena_queue.h161 行定义.

161 {
162 if (Empty()) {
163 return nullptr;
164 }
165 if (arena_) {
166 return pool_[GetIndex(tail_ - 1)];
167 } else {
168 return &normal_queue.back();
169 }
170}

◆ GetEleByIndex()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::GetEleByIndex ( uint64_t  i,
T *&  ptr 
)
inline

在文件 arena_queue.h107 行定义.

107 {
108 if (Empty()) {
109 return false;
110 }
111 if (arena_) {
112 ptr = pool_[GetIndex(i)];
113 return true;
114 } else {
115 if (i > Size() - 1) {
116 return false;
117 }
118 ptr = &normal_queue[i];
119 return true;
120 }
121 }

◆ GetFront()

template<typename T >
T * apollo::cyber::base::ArenaQueue< T >::GetFront ( )

在文件 arena_queue.h173 行定义.

173 {
174 if (Empty()) {
175 return nullptr;
176 }
177 if (arena_) {
178 return pool_[GetIndex(head_ + 1)];
179 } else {
180 return &normal_queue.front();
181 }
182}

◆ GetHeadIndex()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::GetHeadIndex ( uint64_t &  index)
inline

在文件 arena_queue.h83 行定义.

83 {
84 if (Empty()) {
85 return false;
86 }
87 if (arena_) {
88 index = GetIndex(head_ + 1);
89 return true;
90 } else {
91 index = 0;
92 return true;
93 }
94 }

◆ GetTailIndex()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::GetTailIndex ( uint64_t &  index)
inline

在文件 arena_queue.h95 行定义.

95 {
96 if (Empty()) {
97 return false;
98 }
99 if (arena_) {
100 index = GetIndex(tail_ - 1);
101 return true;
102 } else {
103 index = Size() - 1;
104 return true;
105 }
106 }

◆ Head()

template<typename T >
uint64_t apollo::cyber::base::ArenaQueue< T >::Head ( )
inline

在文件 arena_queue.h62 行定义.

62{ return head_.load(); }

◆ Init() [1/2]

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::Init ( uint64_t  size)
inline

在文件 arena_queue.h141 行定义.

141 {
142 arena_ = false;
143 return true;
144}

◆ Init() [2/2]

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::Init ( uint64_t  size,
google::protobuf::Arena *  arena 
)
inline

在文件 arena_queue.h147 行定义.

147 {
148 pool_size_ = size + 2;
149 if (pool_.size() == pool_size_) {
150 return true;
151 }
152 pool_.clear();
153 for (uint64_t i = 0; i < pool_size_; ++i) {
154 pool_.push_back(google::protobuf::Arena::CreateMessage<T>(arena));
155 }
156 arena_ = true;
157 return true;
158}

◆ IsArenaEnable()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::IsArenaEnable ( )
inline

在文件 arena_queue.h122 行定义.

122{ return arena_; }

◆ NextIndex()

template<typename T >
bool apollo::cyber::base::ArenaQueue< T >::NextIndex ( uint64_t &  index)
inline

在文件 arena_queue.h65 行定义.

65 {
66 if (Empty()) {
67 return false;
68 }
69 if (arena_) {
70 if (GetIndex(index) < Tail() - 1) {
71 index = GetIndex(index + 1);
72 return true;
73 }
74 return false;
75 } else {
76 if (index < Size() - 1) {
77 index = index + 1;
78 return true;
79 }
80 return false;
81 }
82 }

◆ operator=()

template<typename T >
ArenaQueue & apollo::cyber::base::ArenaQueue< T >::operator= ( const ArenaQueue< T > &  other)
delete

◆ PopFront()

template<typename T >
T * apollo::cyber::base::ArenaQueue< T >::PopFront ( )

在文件 arena_queue.h213 行定义.

213 {
214 if (Empty()) {
215 return nullptr;
216 }
217 if (arena_) {
218 uint64_t new_head = 0;
219 uint64_t old_head = head_.load(std::memory_order_acquire);
220 do {
221 new_head = old_head + 1;
222 if (new_head == commit_.load(std::memory_order_acquire)) {
223 return nullptr;
224 }
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)];
229 } else {
230 normal_queue.pop_front();
231 return nullptr;
232 }
233}

◆ Size()

template<typename T >
uint64_t apollo::cyber::base::ArenaQueue< T >::Size ( )
inline

在文件 arena_queue.h236 行定义.

236 {
237 if (arena_) {
238 return tail_ - head_ - 1;
239 } else {
240 return normal_queue.size();
241 }
242}

◆ Tail()

template<typename T >
uint64_t apollo::cyber::base::ArenaQueue< T >::Tail ( )
inline

在文件 arena_queue.h63 行定义.

63{ return tail_.load(); }

该类的文档由以下文件生成: