split_iterable_hp.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // Copyright (c) 2006-2018 Maxim Khizhinsky
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include "test_split_iterable_hp.h"
  6. #include <cds/container/iterable_list_hp.h>
  7. #include <cds/container/split_list_set.h>
  8. #include <cds/intrusive/free_list.h>
  9. namespace {
  10. namespace cc = cds::container;
  11. typedef cds::gc::HP gc_type;
  12. class SplitListIterableSet_HP : public cds_test::split_iterable_set_hp
  13. {
  14. protected:
  15. typedef cds_test::split_iterable_set_hp base_class;
  16. void SetUp()
  17. {
  18. struct set_traits: public cc::split_list::traits {
  19. typedef cc::iterable_list_tag ordered_list;
  20. typedef hash_int hash;
  21. struct ordered_list_traits: public cc::iterable_list::traits
  22. {
  23. typedef cmp compare;
  24. };
  25. };
  26. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  27. // +3 - for guarded_ptr
  28. cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 3, 1, 16 );
  29. cds::threading::Manager::attachThread();
  30. }
  31. void TearDown()
  32. {
  33. cds::threading::Manager::detachThread();
  34. cds::gc::hp::GarbageCollector::Destruct( true );
  35. }
  36. };
  37. TEST_F( SplitListIterableSet_HP, compare )
  38. {
  39. typedef cc::SplitListSet< gc_type, int_item,
  40. typename cc::split_list::make_traits<
  41. cc::split_list::ordered_list< cc::iterable_list_tag >
  42. , cds::opt::hash< hash_int >
  43. , cc::split_list::ordered_list_traits<
  44. typename cc::iterable_list::make_traits<
  45. cds::opt::compare< cmp >
  46. >::type
  47. >
  48. >::type
  49. > set_type;
  50. set_type s( kSize, 2 );
  51. test( s );
  52. }
  53. TEST_F( SplitListIterableSet_HP, less )
  54. {
  55. typedef cc::SplitListSet< gc_type, int_item,
  56. typename cc::split_list::make_traits<
  57. cc::split_list::ordered_list< cc::iterable_list_tag >
  58. , cds::opt::hash< hash_int >
  59. , cc::split_list::ordered_list_traits<
  60. typename cc::iterable_list::make_traits<
  61. cds::opt::less< less >
  62. >::type
  63. >
  64. >::type
  65. > set_type;
  66. set_type s( kSize, 2 );
  67. test( s );
  68. }
  69. TEST_F( SplitListIterableSet_HP, cmpmix )
  70. {
  71. typedef cc::SplitListSet< gc_type, int_item,
  72. typename cc::split_list::make_traits<
  73. cc::split_list::ordered_list< cc::iterable_list_tag >
  74. , cds::opt::hash< hash_int >
  75. , cc::split_list::ordered_list_traits<
  76. typename cc::iterable_list::make_traits<
  77. cds::opt::less< less >
  78. , cds::opt::compare< cmp >
  79. >::type
  80. >
  81. >::type
  82. > set_type;
  83. set_type s( kSize, 2 );
  84. test( s );
  85. }
  86. TEST_F( SplitListIterableSet_HP, item_counting )
  87. {
  88. struct set_traits: public cc::split_list::traits
  89. {
  90. typedef cc::iterable_list_tag ordered_list;
  91. typedef hash_int hash;
  92. typedef cds::atomicity::item_counter item_counter;
  93. struct ordered_list_traits: public cc::iterable_list::traits
  94. {
  95. typedef cmp compare;
  96. typedef base_class::less less;
  97. typedef cds::backoff::empty back_off;
  98. };
  99. };
  100. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  101. set_type s( kSize, 4 );
  102. test( s );
  103. }
  104. TEST_F( SplitListIterableSet_HP, stat )
  105. {
  106. struct set_traits: public cc::split_list::traits
  107. {
  108. typedef cc::iterable_list_tag ordered_list;
  109. typedef hash_int hash;
  110. typedef cds::atomicity::item_counter item_counter;
  111. typedef cc::split_list::stat<> stat;
  112. struct ordered_list_traits: public cc::iterable_list::traits
  113. {
  114. typedef base_class::less less;
  115. typedef cds::opt::v::sequential_consistent memory_model;
  116. };
  117. };
  118. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  119. set_type s( kSize, 2 );
  120. test( s );
  121. }
  122. TEST_F( SplitListIterableSet_HP, back_off )
  123. {
  124. struct set_traits: public cc::split_list::traits
  125. {
  126. typedef cc::iterable_list_tag ordered_list;
  127. typedef hash_int hash;
  128. typedef cds::atomicity::item_counter item_counter;
  129. typedef cds::backoff::yield back_off;
  130. typedef cds::opt::v::sequential_consistent memory_model;
  131. struct ordered_list_traits: public cc::iterable_list::traits
  132. {
  133. typedef cmp compare;
  134. typedef cds::backoff::pause back_off;
  135. };
  136. };
  137. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  138. set_type s( kSize, 3 );
  139. test( s );
  140. }
  141. TEST_F( SplitListIterableSet_HP, free_list )
  142. {
  143. struct set_traits: public cc::split_list::traits
  144. {
  145. typedef cc::iterable_list_tag ordered_list;
  146. typedef hash_int hash;
  147. typedef cds::atomicity::item_counter item_counter;
  148. typedef cds::intrusive::FreeList free_list;
  149. struct ordered_list_traits: public cc::iterable_list::traits
  150. {
  151. typedef cmp compare;
  152. typedef cds::backoff::pause back_off;
  153. };
  154. };
  155. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  156. set_type s( kSize, 3 );
  157. test( s );
  158. }
  159. struct set_static_traits: public cc::split_list::traits
  160. {
  161. static bool const dynamic_bucket_table = false;
  162. };
  163. TEST_F( SplitListIterableSet_HP, static_bucket_table )
  164. {
  165. struct set_traits: public set_static_traits
  166. {
  167. typedef cc::iterable_list_tag ordered_list;
  168. typedef hash_int hash;
  169. typedef cds::atomicity::item_counter item_counter;
  170. struct ordered_list_traits: public cc::iterable_list::traits
  171. {
  172. typedef cmp compare;
  173. typedef cds::backoff::pause back_off;
  174. };
  175. };
  176. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  177. set_type s( kSize, 4 );
  178. test( s );
  179. }
  180. TEST_F( SplitListIterableSet_HP, static_bucket_table_free_list )
  181. {
  182. struct set_traits: public set_static_traits
  183. {
  184. typedef cc::iterable_list_tag ordered_list;
  185. typedef hash_int hash;
  186. typedef cds::atomicity::item_counter item_counter;
  187. typedef cds::intrusive::FreeList free_list;
  188. struct ordered_list_traits: public cc::iterable_list::traits
  189. {
  190. typedef cmp compare;
  191. typedef cds::backoff::pause back_off;
  192. };
  193. };
  194. typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
  195. set_type s( kSize, 4 );
  196. test( s );
  197. }
  198. } // namespace