iterable_dhp.cpp 4.0 KB

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