michael_iterable_dhp.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_michael_iterable_hp.h"
  6. #include <cds/container/iterable_kvlist_dhp.h>
  7. #include <cds/container/michael_map.h>
  8. namespace {
  9. namespace cc = cds::container;
  10. typedef cds::gc::DHP gc_type;
  11. class MichaelIterableMap_DHP: public cds_test::michael_iterable_hp
  12. {
  13. protected:
  14. typedef cds_test::michael_iterable_hp base_class;
  15. void SetUp()
  16. {
  17. typedef cc::IterableKVList< gc_type, key_type, value_type > list_type;
  18. typedef cc::MichaelHashMap< gc_type, list_type > map_type;
  19. cds::gc::dhp::smr::construct( map_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( MichaelIterableMap_DHP, compare )
  29. {
  30. typedef cc::IterableKVList< gc_type, key_type, value_type,
  31. typename cc::iterable_list::make_traits<
  32. cds::opt::compare< cmp >
  33. >::type
  34. > list_type;
  35. typedef cc::MichaelHashMap< gc_type, list_type,
  36. typename cc::michael_map::make_traits<
  37. cds::opt::hash< hash1 >
  38. >::type
  39. > map_type;
  40. map_type m( kSize, 2 );
  41. test( m );
  42. }
  43. TEST_F( MichaelIterableMap_DHP, less )
  44. {
  45. typedef cc::IterableKVList< gc_type, key_type, value_type,
  46. typename cc::iterable_list::make_traits<
  47. cds::opt::less< less >
  48. >::type
  49. > list_type;
  50. typedef cc::MichaelHashMap< gc_type, list_type,
  51. typename cc::michael_map::make_traits<
  52. cds::opt::hash< hash1 >
  53. >::type
  54. > map_type;
  55. map_type m( kSize, 1 );
  56. test( m );
  57. }
  58. TEST_F( MichaelIterableMap_DHP, cmpmix )
  59. {
  60. typedef cc::IterableKVList< gc_type, key_type, value_type,
  61. typename cc::iterable_list::make_traits<
  62. cds::opt::less< less >
  63. ,cds::opt::compare< cmp >
  64. >::type
  65. > list_type;
  66. typedef cc::MichaelHashMap< gc_type, list_type,
  67. typename cc::michael_map::make_traits<
  68. cds::opt::hash< hash1 >
  69. >::type
  70. > map_type;
  71. map_type m( kSize, 2 );
  72. test( m );
  73. }
  74. TEST_F( MichaelIterableMap_DHP, backoff )
  75. {
  76. struct list_traits: public cc::iterable_list::traits
  77. {
  78. typedef cmp compare;
  79. typedef cds::backoff::make_exponential_t<cds::backoff::pause, cds::backoff::yield> back_off;
  80. };
  81. typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
  82. struct map_traits: public cc::michael_map::traits
  83. {
  84. typedef hash1 hash;
  85. typedef cds::atomicity::item_counter item_counter;
  86. };
  87. typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
  88. map_type m( kSize, 4 );
  89. test( m );
  90. }
  91. TEST_F( MichaelIterableMap_DHP, seq_cst )
  92. {
  93. struct list_traits: public cc::iterable_list::traits
  94. {
  95. typedef cmp compare;
  96. typedef cds::backoff::yield back_off;
  97. typedef cds::opt::v::sequential_consistent memory_model;
  98. };
  99. typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
  100. struct map_traits: public cc::michael_map::traits
  101. {
  102. typedef hash1 hash;
  103. };
  104. typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
  105. map_type s( kSize, 8 );
  106. test( s );
  107. }
  108. TEST_F( MichaelIterableMap_DHP, stat )
  109. {
  110. struct list_traits: public cc::iterable_list::traits
  111. {
  112. typedef cmp compare;
  113. typedef cds::backoff::yield back_off;
  114. typedef cc::iterable_list::stat<> stat;
  115. };
  116. typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
  117. struct map_traits: public cc::michael_map::traits
  118. {
  119. typedef hash1 hash;
  120. };
  121. typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
  122. map_type m( kSize, 8 );
  123. test( m );
  124. EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );
  125. }
  126. TEST_F( MichaelIterableMap_DHP, wrapped_stat )
  127. {
  128. struct list_traits: public cc::iterable_list::traits
  129. {
  130. typedef cmp compare;
  131. typedef cc::iterable_list::wrapped_stat<> stat;
  132. };
  133. typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
  134. struct map_traits: public cc::michael_map::traits
  135. {
  136. typedef hash1 hash;
  137. };
  138. typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
  139. map_type m( kSize, 8 );
  140. test( m );
  141. EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );
  142. }
  143. } // namespace