treiber_stack_dhp.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_treiber_stack.h"
  6. #include <cds/gc/dhp.h>
  7. #include <cds/container/treiber_stack.h>
  8. namespace {
  9. namespace cc = cds::container;
  10. typedef cds::gc::DHP gc_type;
  11. class TreiberStack_DHP : public cds_test::TreiberStack
  12. {
  13. typedef cds_test::TreiberStack base_class;
  14. protected:
  15. void SetUp()
  16. {
  17. typedef cc::TreiberStack< gc_type, int > stack_type;
  18. cds::gc::dhp::smr::construct( stack_type::c_nHazardPtrCount );
  19. cds::threading::Manager::attachThread();
  20. }
  21. void TearDown()
  22. {
  23. cds::threading::Manager::detachThread();
  24. cds::gc::dhp::smr::destruct();
  25. }
  26. template <typename Stack>
  27. void test()
  28. {
  29. Stack stack;
  30. base_class::test( stack );
  31. }
  32. template <typename Stack>
  33. void test_dyn( size_t elimination_size )
  34. {
  35. Stack stack( elimination_size );
  36. base_class::test( stack );
  37. }
  38. };
  39. TEST_F( TreiberStack_DHP, defaulted )
  40. {
  41. typedef cc::TreiberStack< gc_type, int > stack_type;
  42. test<stack_type>();
  43. }
  44. TEST_F( TreiberStack_DHP, backoff )
  45. {
  46. typedef cc::TreiberStack< gc_type, int
  47. , typename cc::treiber_stack::make_traits<
  48. cds::opt::back_off< cds::backoff::yield>
  49. >::type
  50. > stack_type;
  51. test<stack_type>();
  52. }
  53. TEST_F( TreiberStack_DHP, alloc )
  54. {
  55. // allocator must be rebinded for real value type
  56. struct foo
  57. {
  58. size_t arr[ 1024 * 1024 ];
  59. size_t a2[1024 * 1024];
  60. size_t a3[1024 * 1024];
  61. size_t a4[1024 * 1024];
  62. };
  63. typedef cc::TreiberStack< gc_type, int
  64. , typename cc::treiber_stack::make_traits<
  65. cds::opt::back_off< cds::backoff::pause>
  66. ,cds::opt::memory_model<cds::opt::v::relaxed_ordering>
  67. ,cds::opt::allocator< std::allocator< foo >>
  68. >::type
  69. > stack_type;
  70. test<stack_type>();
  71. }
  72. TEST_F( TreiberStack_DHP, elimination )
  73. {
  74. typedef cc::TreiberStack< gc_type, int
  75. , typename cc::treiber_stack::make_traits<
  76. cds::opt::enable_elimination<true>
  77. >::type
  78. > stack_type;
  79. test<stack_type>();
  80. }
  81. TEST_F( TreiberStack_DHP, elimination_backoff )
  82. {
  83. struct traits : public cc::treiber_stack::traits
  84. {
  85. enum {
  86. enable_elimination = true
  87. };
  88. typedef cds::backoff::pause back_off;
  89. };
  90. typedef cc::TreiberStack< gc_type, int, traits > stack_type;
  91. test<stack_type>();
  92. }
  93. TEST_F( TreiberStack_DHP, elimination_dynamic )
  94. {
  95. typedef cc::TreiberStack< gc_type, int
  96. , typename cc::treiber_stack::make_traits<
  97. cds::opt::enable_elimination<true>
  98. , cds::opt::buffer< cds::opt::v::initialized_dynamic_buffer<void *> >
  99. >::type
  100. > stack_type;
  101. test_dyn<stack_type>( 4 );
  102. }
  103. TEST_F( TreiberStack_DHP, elimination_stat )
  104. {
  105. typedef cc::TreiberStack< gc_type, int
  106. , typename cc::treiber_stack::make_traits<
  107. cds::opt::enable_elimination<true>
  108. , cds::opt::stat< cc::treiber_stack::stat<> >
  109. >::type
  110. > stack_type;
  111. test<stack_type>();
  112. }
  113. TEST_F( TreiberStack_DHP, elimination_dynamic_backoff )
  114. {
  115. struct traits : public cc::treiber_stack::traits
  116. {
  117. enum {
  118. enable_elimination = true
  119. };
  120. typedef cds::opt::v::initialized_dynamic_buffer<void *> buffer;
  121. typedef cds::backoff::yield back_off;
  122. };
  123. typedef cc::TreiberStack< gc_type, int, traits > stack_type;
  124. test_dyn<stack_type>( 2 );
  125. }
  126. } // namespace