michael_hp.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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_list_hp.h"
  6. #include <cds/container/michael_list_hp.h>
  7. namespace {
  8. namespace cc = cds::container;
  9. typedef cds::gc::HP gc_type;
  10. class MichaelList_HP : public cds_test::list_hp
  11. {
  12. protected:
  13. void SetUp()
  14. {
  15. typedef cc::MichaelList< gc_type, item > list_type;
  16. // +1 - for guarded_ptr
  17. cds::gc::hp::GarbageCollector::Construct( list_type::c_nHazardPtrCount + 1, 1, 16 );
  18. cds::threading::Manager::attachThread();
  19. }
  20. void TearDown()
  21. {
  22. cds::threading::Manager::detachThread();
  23. cds::gc::hp::GarbageCollector::Destruct( true );
  24. }
  25. };
  26. TEST_F( MichaelList_HP, less_ordered )
  27. {
  28. typedef cc::MichaelList< gc_type, item,
  29. typename cc::michael_list::make_traits<
  30. cds::opt::less< lt<item> >
  31. >::type
  32. > list_type;
  33. list_type l;
  34. test_common( l );
  35. test_ordered_iterator( l );
  36. test_hp( l );
  37. }
  38. TEST_F( MichaelList_HP, compare_ordered )
  39. {
  40. typedef cc::MichaelList< gc_type, item,
  41. typename cc::michael_list::make_traits<
  42. cds::opt::compare< cmp<item> >
  43. >::type
  44. > list_type;
  45. list_type l;
  46. test_common( l );
  47. test_ordered_iterator( l );
  48. test_hp( l );
  49. }
  50. TEST_F( MichaelList_HP, mix_ordered )
  51. {
  52. typedef cc::MichaelList< gc_type, item,
  53. typename cc::michael_list::make_traits<
  54. cds::opt::compare< cmp<item> >
  55. ,cds::opt::less< lt<item> >
  56. >::type
  57. > list_type;
  58. list_type l;
  59. test_common( l );
  60. test_ordered_iterator( l );
  61. test_hp( l );
  62. }
  63. TEST_F( MichaelList_HP, item_counting )
  64. {
  65. struct traits : public cc::michael_list::traits
  66. {
  67. typedef lt<item> less;
  68. typedef cds::atomicity::item_counter item_counter;
  69. };
  70. typedef cc::MichaelList<gc_type, item, traits > list_type;
  71. list_type l;
  72. test_common( l );
  73. test_ordered_iterator( l );
  74. test_hp( l );
  75. }
  76. TEST_F( MichaelList_HP, backoff )
  77. {
  78. struct traits : public cc::michael_list::traits
  79. {
  80. typedef lt<item> less;
  81. typedef cds::atomicity::item_counter item_counter;
  82. typedef cds::backoff::empty back_off;
  83. };
  84. typedef cc::MichaelList<gc_type, item, traits > list_type;
  85. list_type l;
  86. test_common( l );
  87. test_ordered_iterator( l );
  88. test_hp( l );
  89. }
  90. TEST_F( MichaelList_HP, seq_cst )
  91. {
  92. struct traits : public cc::michael_list::traits
  93. {
  94. typedef lt<item> less;
  95. typedef cds::atomicity::item_counter item_counter;
  96. typedef cds::opt::v::sequential_consistent memory_model;
  97. };
  98. typedef cc::MichaelList<gc_type, item, traits > list_type;
  99. list_type l;
  100. test_common( l );
  101. test_ordered_iterator( l );
  102. test_hp( l );
  103. }
  104. TEST_F( MichaelList_HP, stat )
  105. {
  106. struct traits: public cc::michael_list::traits
  107. {
  108. typedef lt<item> less;
  109. typedef cds::atomicity::item_counter item_counter;
  110. typedef cds::container::michael_list::stat<> stat;
  111. };
  112. typedef cc::MichaelList<gc_type, item, traits > list_type;
  113. list_type l;
  114. test_common( l );
  115. test_ordered_iterator( l );
  116. test_hp( l );
  117. }
  118. TEST_F( MichaelList_HP, wrapped_stat )
  119. {
  120. struct traits: public cc::michael_list::traits
  121. {
  122. typedef lt<item> less;
  123. typedef cds::atomicity::item_counter item_counter;
  124. typedef cds::container::michael_list::wrapped_stat<> stat;
  125. };
  126. typedef cc::MichaelList<gc_type, item, traits > list_type;
  127. cds::container::michael_list::stat<> st;
  128. list_type l( st );
  129. test_common( l );
  130. test_ordered_iterator( l );
  131. test_hp( l );
  132. }
  133. } // namespace