3 #ifndef CDSUNIT_STACK_TYPES_H
4 #define CDSUNIT_STACK_TYPES_H
6 #include <cds/container/treiber_stack.h>
7 #include <cds/container/fcstack.h>
8 #include <cds/container/fcdeque.h>
10 #include <cds/gc/hp.h>
11 #include <cds/gc/dhp.h>
14 #include <cds/lock/spinlock.h>
23 template <typename T, typename Traits=cds::container::fcdeque::traits>
24 class FCDequeL: public cds::container::FCDeque<T, std::deque<T>, Traits >
26 typedef cds::container::FCDeque<T, std::deque<T>, Traits > base_class;
32 unsigned int nCompactFactor ///< Flat combining: publication list compacting factor
33 ,unsigned int nCombinePassCount ///< Flat combining: number of combining passes for combiner thread
35 : base_class( nCompactFactor, nCombinePassCount )
38 bool push( T const& v )
40 return base_class::push_front( v );
45 return base_class::pop_front( v );
49 template <typename T, typename Traits=cds::container::fcdeque::traits>
50 class FCDequeR: public cds::container::FCDeque<T, std::deque<T>, Traits >
52 typedef cds::container::FCDeque<T, std::deque<T>, Traits > base_class;
58 unsigned int nCompactFactor ///< Flat combining: publication list compacting factor
59 ,unsigned int nCombinePassCount ///< Flat combining: number of combining passes for combiner thread
61 : base_class( nCompactFactor, nCombinePassCount )
64 bool push( T const& v )
66 return base_class::push_back( v );
71 return base_class::pop_back( v );
75 template < typename T, typename Stack, typename Lock>
80 cds::container::treiber_stack::empty_stat m_stat;
82 typedef std::unique_lock<Lock> unique_lock;
85 bool push( T const& v )
87 unique_lock l( m_Lock );
94 unique_lock l( m_Lock );
95 if ( !m_Impl.empty() ) {
105 unique_lock l( m_Lock );
106 return m_Impl.empty();
109 cds::container::treiber_stack::empty_stat const& statistics() const
116 template <typename T>
120 typedef cds::container::TreiberStack< cds::gc::HP, T > Treiber_HP;
121 typedef cds::container::TreiberStack< cds::gc::DHP, T > Treiber_DHP;
123 struct traits_Treiber_seqcst: public
124 cds::container::treiber_stack::make_traits<
125 cds::opt::memory_model<cds::opt::v::sequential_consistent>
128 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Treiber_seqcst > Treiber_HP_seqcst;
129 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Treiber_seqcst > Treiber_DHP_seqcst;
131 struct traits_Treiber_stat: public
132 cds::container::treiber_stack::make_traits<
133 cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
136 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Treiber_stat > Treiber_HP_stat;
137 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Treiber_stat > Treiber_DHP_stat;
139 struct traits_Treiber_yield: public
140 cds::container::treiber_stack::make_traits<
141 cds::opt::back_off<cds::backoff::yield>
142 , cds::opt::memory_model<cds::opt::v::relaxed_ordering>
145 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Treiber_yield > Treiber_HP_yield;
146 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Treiber_yield > Treiber_DHP_yield;
148 struct traits_Treiber_pause: public
149 cds::container::treiber_stack::make_traits<
150 cds::opt::back_off<cds::backoff::pause>
153 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Treiber_pause > Treiber_HP_pause;
154 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Treiber_pause > Treiber_DHP_pause;
156 struct traits_Treiber_exp: public
157 cds::container::treiber_stack::make_traits<
159 cds::backoff::exponential<
166 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Treiber_exp > Treiber_HP_exp;
167 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Treiber_exp > Treiber_DHP_exp;
171 struct traits_Elimination_on : public
172 cds::container::treiber_stack::make_traits <
173 cds::opt::enable_elimination<true>
176 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_on > Elimination_HP;
177 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_on > Elimination_DHP;
179 struct traits_Elimination_stat : public
180 cds::container::treiber_stack::make_traits <
181 cds::opt::enable_elimination<true>
182 ,cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
185 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_stat > Elimination_HP_stat;
186 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_stat > Elimination_DHP_stat;
188 struct traits_Elimination_2ms: public
189 cds::container::treiber_stack::make_traits <
190 cds::opt::enable_elimination<true>
191 ,cds::opt::elimination_backoff< cds::backoff::delay_of<2> >
194 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_2ms > Elimination_HP_2ms;
195 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_2ms > Elimination_DHP_2ms;
197 struct traits_Elimination_2ms_stat : public
198 cds::container::treiber_stack::make_traits <
199 cds::opt::enable_elimination<true>
200 , cds::opt::elimination_backoff< cds::backoff::delay_of<2> >
201 , cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
204 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_2ms_stat > Elimination_HP_2ms_stat;
205 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_2ms_stat > Elimination_DHP_2ms_stat;
207 struct traits_Elimination_5ms : public
208 cds::container::treiber_stack::make_traits <
209 cds::opt::enable_elimination<true>
210 , cds::opt::elimination_backoff< cds::backoff::delay_of<5> >
213 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_5ms > Elimination_HP_5ms;
214 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_5ms > Elimination_DHP_5ms;
216 struct traits_Elimination_5ms_stat : public
217 cds::container::treiber_stack::make_traits <
218 cds::opt::enable_elimination<true>
219 , cds::opt::elimination_backoff< cds::backoff::delay_of<5> >
220 , cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
223 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_5ms_stat > Elimination_HP_5ms_stat;
224 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_5ms_stat > Elimination_DHP_5ms_stat;
226 struct traits_Elimination_10ms : public
227 cds::container::treiber_stack::make_traits <
228 cds::opt::enable_elimination<true>
229 , cds::opt::elimination_backoff< cds::backoff::delay_of<10> >
232 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_10ms > Elimination_HP_10ms;
233 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_10ms > Elimination_DHP_10ms;
235 struct traits_Elimination_10ms_stat : public
236 cds::container::treiber_stack::make_traits <
237 cds::opt::enable_elimination<true>
238 , cds::opt::elimination_backoff< cds::backoff::delay_of<10> >
239 , cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
242 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_10ms_stat > Elimination_HP_10ms_stat;
243 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_10ms_stat > Elimination_DHP_10ms_stat;
245 struct traits_Elimination_dyn: public
246 cds::container::treiber_stack::make_traits <
247 cds::opt::enable_elimination<true>
248 , cds::opt::buffer< cds::opt::v::dynamic_buffer<int> >
251 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_dyn > Elimination_HP_dyn;
252 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_dyn > Elimination_DHP_dyn;
254 struct traits_Elimination_seqcst: public
255 cds::container::treiber_stack::make_traits <
256 cds::opt::enable_elimination<true>
257 , cds::opt::memory_model<cds::opt::v::sequential_consistent>
260 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_seqcst > Elimination_HP_seqcst;
261 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_seqcst > Elimination_DHP_seqcst;
263 struct traits_Elimination_dyn_stat: public
264 cds::container::treiber_stack::make_traits <
265 cds::opt::enable_elimination<true>
266 , cds::opt::stat<cds::intrusive::treiber_stack::stat<> >
267 , cds::opt::buffer< cds::opt::v::dynamic_buffer<int> >
270 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_dyn_stat > Elimination_HP_dyn_stat;
271 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_dyn_stat > Elimination_DHP_dyn_stat;
273 struct traits_Elimination_yield: public
274 cds::container::treiber_stack::make_traits <
275 cds::opt::enable_elimination<true>
276 , cds::opt::back_off<cds::backoff::yield>
277 , cds::opt::memory_model<cds::opt::v::relaxed_ordering>
280 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_yield > Elimination_HP_yield;
281 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_yield > Elimination_DHP_yield;
283 struct traits_Elimination_pause: public
284 cds::container::treiber_stack::make_traits <
285 cds::opt::enable_elimination<true>
286 , cds::opt::back_off<cds::backoff::pause>
289 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_pause > Elimination_HP_pause;
290 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_pause > Elimination_DHP_pause;
292 struct traits_Elimination_exp: public
293 cds::container::treiber_stack::make_traits <
294 cds::opt::enable_elimination<true>
296 cds::backoff::exponential<
303 typedef cds::container::TreiberStack< cds::gc::HP, T, traits_Elimination_exp > Elimination_HP_exp;
304 typedef cds::container::TreiberStack< cds::gc::DHP, T, traits_Elimination_exp > Elimination_DHP_exp;
308 typedef cds::container::FCStack< T > FCStack_deque;
310 struct traits_FCStack_stat:
311 public cds::container::fcstack::make_traits<
312 cds::opt::stat< cds::container::fcstack::stat<> >
315 struct traits_FCStack_elimination:
316 public cds::container::fcstack::make_traits<
317 cds::opt::enable_elimination< true >
320 struct traits_FCStack_elimination_stat:
321 public cds::container::fcstack::make_traits<
322 cds::opt::stat< cds::container::fcstack::stat<> >,
323 cds::opt::enable_elimination< true >
326 struct traits_FCStack_mutex:
327 public cds::container::fcstack::make_traits<
328 cds::opt::lock_type< std::mutex >
332 typedef cds::container::FCStack< T, std::stack<T, std::deque<T> >, traits_FCStack_mutex > FCStack_deque_mutex;
333 typedef cds::container::FCStack< T, std::stack<T, std::deque<T> >, traits_FCStack_stat > FCStack_deque_stat;
334 typedef cds::container::FCStack< T, std::stack<T, std::deque<T> >, traits_FCStack_elimination > FCStack_deque_elimination;
335 typedef cds::container::FCStack< T, std::stack<T, std::deque<T> >, traits_FCStack_elimination_stat > FCStack_deque_elimination_stat;
336 typedef cds::container::FCStack< T, std::stack<T, std::vector<T> > > FCStack_vector;
337 typedef cds::container::FCStack< T, std::stack<T, std::vector<T> >, traits_FCStack_mutex > FCStack_vector_mutex;
338 typedef cds::container::FCStack< T, std::stack<T, std::vector<T> >, traits_FCStack_stat > FCStack_vector_stat;
339 typedef cds::container::FCStack< T, std::stack<T, std::vector<T> >, traits_FCStack_elimination > FCStack_vector_elimination;
340 typedef cds::container::FCStack< T, std::stack<T, std::vector<T> >, traits_FCStack_elimination_stat > FCStack_vector_elimination_stat;
341 typedef cds::container::FCStack< T, std::stack<T, std::list<T> > > FCStack_list;
342 typedef cds::container::FCStack< T, std::stack<T, std::list<T> >, traits_FCStack_mutex > FCStack_list_mutex;
343 typedef cds::container::FCStack< T, std::stack<T, std::list<T> >, traits_FCStack_stat > FCStack_list_stat;
344 typedef cds::container::FCStack< T, std::stack<T, std::list<T> >, traits_FCStack_elimination > FCStack_list_elimination;
345 typedef cds::container::FCStack< T, std::stack<T, std::list<T> >, traits_FCStack_elimination_stat > FCStack_list_elimination_stat;
348 struct traits_FCDeque_stat:
349 public cds::container::fcdeque::make_traits<
350 cds::opt::stat< cds::container::fcdeque::stat<> >
353 struct traits_FCDeque_elimination:
354 public cds::container::fcdeque::make_traits<
355 cds::opt::enable_elimination< true >
358 struct traits_FCDeque_elimination_stat:
359 public cds::container::fcdeque::make_traits<
360 cds::opt::stat< cds::container::fcdeque::stat<> >,
361 cds::opt::enable_elimination< true >
364 struct traits_FCDeque_mutex:
365 public cds::container::fcdeque::make_traits<
366 cds::opt::lock_type< std::mutex >
371 typedef details::FCDequeL< T > FCDequeL_default;
372 typedef details::FCDequeL< T, traits_FCDeque_mutex > FCDequeL_mutex;
373 typedef details::FCDequeL< T, traits_FCDeque_stat > FCDequeL_stat;
374 typedef details::FCDequeL< T, traits_FCDeque_elimination > FCDequeL_elimination;
375 typedef details::FCDequeL< T, traits_FCDeque_elimination_stat > FCDequeL_elimination_stat;
377 typedef details::FCDequeR< T > FCDequeR_default;
378 typedef details::FCDequeR< T, traits_FCDeque_mutex > FCDequeR_mutex;
379 typedef details::FCDequeR< T, traits_FCDeque_stat > FCDequeR_stat;
380 typedef details::FCDequeR< T, traits_FCDeque_elimination > FCDequeR_elimination;
381 typedef details::FCDequeR< T, traits_FCDeque_elimination_stat > FCDequeR_elimination_stat;
385 typedef details::StdStack< T, std::stack< T >, std::mutex > StdStack_Deque_Mutex;
386 typedef details::StdStack< T, std::stack< T >, cds::lock::Spin > StdStack_Deque_Spin;
387 typedef details::StdStack< T, std::stack< T, std::vector<T> >, std::mutex > StdStack_Vector_Mutex;
388 typedef details::StdStack< T, std::stack< T, std::vector<T> >, cds::lock::Spin > StdStack_Vector_Spin;
389 typedef details::StdStack< T, std::stack< T, std::list<T> >, std::mutex > StdStack_List_Mutex;
390 typedef details::StdStack< T, std::stack< T, std::list<T> >, cds::lock::Spin > StdStack_List_Spin;
396 static inline ostream& operator <<( ostream& o, cds::container::treiber_stack::stat<> const& s )
398 return o << "\tStatistics:\n"
399 << "\t Push: " << s.m_PushCount.get() << "\n"
400 << "\t Pop: " << s.m_PopCount.get() << "\n"
401 << "\t Push contention: " << s.m_PushRace.get() << "\n"
402 << "\t Pop contention: " << s.m_PopRace.get() << "\n"
403 << "\t m_ActivePushCollision: " << s.m_ActivePushCollision.get() << "\n"
404 << "\t m_PassivePopCollision: " << s.m_PassivePopCollision.get() << "\n"
405 << "\t m_ActivePopCollision: " << s.m_ActivePopCollision.get() << "\n"
406 << "\t m_PassivePushCollision: " << s.m_PassivePushCollision.get() << "\n"
407 << "\t m_EliminationFailed: " << s.m_EliminationFailed.get() << "\n";
410 static inline ostream& operator <<(ostream& o, cds::container::treiber_stack::empty_stat const& /*s*/)
415 static inline ostream& operator <<( ostream& o, cds::container::fcstack::empty_stat const& /*s*/ )
420 static inline ostream& operator <<( ostream& o, cds::container::fcstack::stat<> const& s )
422 return o << "\tStatistics:\n"
423 << "\t Push: " << s.m_nPush.get() << "\n"
424 << "\t PushMove: " << s.m_nPushMove.get() << "\n"
425 << "\t Pop: " << s.m_nPop.get() << "\n"
426 << "\t FailedPop: " << s.m_nFailedPop.get() << "\n"
427 << "\t Collided push/pop pair: " << s.m_nCollided.get() << "\n"
428 << "\tFlat combining statistics:\n"
429 << "\t Combining factor: " << s.combining_factor() << "\n"
430 << "\t Operation count: " << s.m_nOperationCount.get() << "\n"
431 << "\t Combine call count: " << s.m_nCombiningCount.get() << "\n"
432 << "\t Compact pub-list: " << s.m_nCompactPublicationList.get() << "\n"
433 << "\t Deactivate pub-record: " << s.m_nDeactivatePubRecord.get() << "\n"
434 << "\t Activate pub-record: " << s.m_nActivatePubRecord.get() << "\n"
435 << "\t Create pub-record: " << s.m_nPubRecordCreated.get() << "\n"
436 << "\t Delete pub-record: " << s.m_nPubRecordDeteted.get() << "\n"
437 << "\t Acquire pub-record: " << s.m_nAcquirePubRecCount.get()<< "\n"
438 << "\t Release pub-record: " << s.m_nReleasePubRecCount.get()<< "\n";
441 static inline ostream& operator <<( ostream& o, cds::container::fcdeque::empty_stat const& /*s*/ )
446 static inline ostream& operator <<( ostream& o, cds::container::fcdeque::stat<> const& s )
448 return o << "\tStatistics:\n"
449 << "\t Push front: " << s.m_nPushFront.get() << "\n"
450 << "\t Push front move: " << s.m_nPushFrontMove.get() << "\n"
451 << "\t Push back: " << s.m_nPushBack.get() << "\n"
452 << "\t Push back move: " << s.m_nPushBackMove.get() << "\n"
453 << "\t Pop front: " << s.m_nPopFront.get() << "\n"
454 << "\t Failed pop front: " << s.m_nFailedPopFront.get() << "\n"
455 << "\t Pop back: " << s.m_nPopBack.get() << "\n"
456 << "\t Failed pop back: " << s.m_nFailedPopBack.get() << "\n"
457 << "\t Collided push/pop pair: " << s.m_nCollided.get() << "\n"
458 << "\tFlat combining statistics:\n"
459 << "\t Combining factor: " << s.combining_factor() << "\n"
460 << "\t Operation count: " << s.m_nOperationCount.get() << "\n"
461 << "\t Combine call count: " << s.m_nCombiningCount.get() << "\n"
462 << "\t Compact pub-list: " << s.m_nCompactPublicationList.get() << "\n"
463 << "\t Deactivate pub-record: " << s.m_nDeactivatePubRecord.get() << "\n"
464 << "\t Activate pub-record: " << s.m_nActivatePubRecord.get() << "\n"
465 << "\t Create pub-record: " << s.m_nPubRecordCreated.get() << "\n"
466 << "\t Delete pub-record: " << s.m_nPubRecordDeteted.get() << "\n"
467 << "\t Acquire pub-record: " << s.m_nAcquirePubRecCount.get()<< "\n"
468 << "\t Release pub-record: " << s.m_nReleasePubRecCount.get()<< "\n";
473 #endif // #ifndef CDSUNIT_STACK_TYPES_H