michael_dhp.cpp 4.2 KB

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