michael_michael_hp.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_set_hp.h"
  6. #include <cds/container/michael_list_hp.h>
  7. #include <cds/container/michael_set.h>
  8. namespace {
  9. namespace cc = cds::container;
  10. typedef cds::gc::HP gc_type;
  11. class MichaelSet_HP : public cds_test::container_set_hp
  12. {
  13. protected:
  14. typedef cds_test::container_set_hp base_class;
  15. void SetUp()
  16. {
  17. typedef cc::MichaelList< gc_type, int_item > list_type;
  18. typedef cc::MichaelHashSet< gc_type, list_type > set_type;
  19. // +1 - for guarded_ptr
  20. cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
  21. cds::threading::Manager::attachThread();
  22. }
  23. void TearDown()
  24. {
  25. cds::threading::Manager::detachThread();
  26. cds::gc::hp::GarbageCollector::Destruct( true );
  27. }
  28. };
  29. TEST_F( MichaelSet_HP, compare )
  30. {
  31. typedef cc::MichaelList< gc_type, int_item,
  32. typename cc::michael_list::make_traits<
  33. cds::opt::compare< cmp >
  34. >::type
  35. > list_type;
  36. typedef cc::MichaelHashSet< gc_type, list_type,
  37. typename cc::michael_set::make_traits<
  38. cds::opt::hash< hash_int >
  39. >::type
  40. > set_type;
  41. set_type s( kSize, 2 );
  42. test( s );
  43. }
  44. TEST_F( MichaelSet_HP, less )
  45. {
  46. typedef cc::MichaelList< gc_type, int_item,
  47. typename cc::michael_list::make_traits<
  48. cds::opt::less< base_class::less >
  49. >::type
  50. > list_type;
  51. typedef cc::MichaelHashSet< gc_type, list_type,
  52. typename cc::michael_set::make_traits<
  53. cds::opt::hash< hash_int >
  54. >::type
  55. > set_type;
  56. set_type s( kSize, 2 );
  57. test( s );
  58. }
  59. TEST_F( MichaelSet_HP, cmpmix )
  60. {
  61. struct list_traits : public cc::michael_list::traits
  62. {
  63. typedef base_class::less less;
  64. typedef cmp compare;
  65. };
  66. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  67. typedef cc::MichaelHashSet< gc_type, list_type,
  68. typename cc::michael_set::make_traits<
  69. cds::opt::hash< hash_int >
  70. >::type
  71. > set_type;
  72. set_type s( kSize, 2 );
  73. test( s );
  74. }
  75. TEST_F( MichaelSet_HP, item_counting )
  76. {
  77. struct list_traits : public cc::michael_list::traits
  78. {
  79. typedef cmp compare;
  80. };
  81. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  82. struct set_traits: public cc::michael_set::traits
  83. {
  84. typedef hash_int hash;
  85. typedef simple_item_counter item_counter;
  86. };
  87. typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
  88. set_type s( kSize, 3 );
  89. test( s );
  90. }
  91. TEST_F( MichaelSet_HP, backoff )
  92. {
  93. struct list_traits : public cc::michael_list::traits
  94. {
  95. typedef cmp compare;
  96. typedef cds::backoff::make_exponential_t<cds::backoff::pause, cds::backoff::yield> back_off;
  97. };
  98. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  99. struct set_traits : public cc::michael_set::traits
  100. {
  101. typedef hash_int hash;
  102. typedef cds::atomicity::item_counter item_counter;
  103. };
  104. typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
  105. set_type s( kSize, 4 );
  106. test( s );
  107. }
  108. TEST_F( MichaelSet_HP, seq_cst )
  109. {
  110. struct list_traits : public cc::michael_list::traits
  111. {
  112. typedef base_class::less less;
  113. typedef cds::backoff::pause back_off;
  114. typedef cds::opt::v::sequential_consistent memory_model;
  115. };
  116. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  117. struct set_traits : public cc::michael_set::traits
  118. {
  119. typedef hash_int hash;
  120. typedef cds::atomicity::item_counter item_counter;
  121. };
  122. typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
  123. set_type s( kSize, 4 );
  124. test( s );
  125. }
  126. TEST_F( MichaelSet_HP, stat )
  127. {
  128. struct list_traits: public cc::michael_list::traits
  129. {
  130. typedef base_class::less less;
  131. typedef cds::backoff::pause back_off;
  132. typedef cc::michael_list::stat<> stat;
  133. };
  134. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  135. struct set_traits: public cc::michael_set::traits
  136. {
  137. typedef hash_int hash;
  138. typedef cds::atomicity::item_counter item_counter;
  139. };
  140. typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
  141. set_type s( kSize, 4 );
  142. test( s );
  143. EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
  144. }
  145. TEST_F( MichaelSet_HP, wrapped_stat )
  146. {
  147. struct list_traits: public cc::michael_list::traits
  148. {
  149. typedef base_class::less less;
  150. typedef cds::backoff::pause back_off;
  151. typedef cc::michael_list::wrapped_stat<> stat;
  152. };
  153. typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
  154. struct set_traits: public cc::michael_set::traits
  155. {
  156. typedef hash_int hash;
  157. typedef cds::atomicity::item_counter item_counter;
  158. };
  159. typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
  160. set_type s( kSize, 4 );
  161. test( s );
  162. EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
  163. }
  164. } // namespace