2
0

michael_michael_dhp.cpp 5.7 KB

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