2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "intrusive_stack_push_pop.h"
32 #include "../misc/common.h"
35 /*static*/ size_t intrusive_stack_push_pop::s_nPushThreadCount = 4;
36 /*static*/ size_t intrusive_stack_push_pop::s_nPopThreadCount = 4;
37 /*static*/ size_t intrusive_stack_push_pop::s_nStackSize = 10000000;
38 /*static*/ size_t intrusive_stack_push_pop::s_nEliminationSize = 4;
39 /*static*/ bool intrusive_stack_push_pop::s_bFCIterative = false;
40 /*static*/ unsigned int intrusive_stack_push_pop::s_nFCCombinePassCount = 64;
41 /*static*/ unsigned int intrusive_stack_push_pop::s_nFCCompactFactor = 1024;
43 /*static*/ atomics::atomic<size_t> intrusive_stack_push_pop::s_nWorkingProducers( 0 );
45 /*static*/ void intrusive_stack_push_pop::SetUpTestCase()
47 cds_test::config const& cfg = get_config( "IntrusiveStack_PushPop" );
49 s_nPushThreadCount = cfg.get_size_t( "PushThreadCount", s_nPushThreadCount );
50 s_nPopThreadCount = cfg.get_size_t( "PopThreadCount", s_nPopThreadCount );
51 s_nStackSize = cfg.get_size_t( "StackSize", s_nStackSize );
52 s_nEliminationSize = cfg.get_size_t( "EliminationSize", s_nEliminationSize );
53 s_bFCIterative = cfg.get_bool( "FCIterate", s_bFCIterative );
54 s_nFCCombinePassCount = cfg.get_uint( "FCCombinePassCount", s_nFCCombinePassCount );
55 s_nFCCompactFactor = cfg.get_uint( "FCCompactFactor", s_nFCCompactFactor );
57 if ( s_nPushThreadCount == 0 )
58 s_nPushThreadCount = 1;
59 if ( s_nPopThreadCount == 0 )
60 s_nPopThreadCount = 1;
61 if ( s_nEliminationSize == 0 )
62 s_nEliminationSize = 1;
64 } // namespace cds_test
67 class intrusive_stack_push_pop : public cds_test::intrusive_stack_push_pop
69 typedef cds_test::intrusive_stack_push_pop base_class;
71 typedef base_class::value_type<> value_type;
72 typedef base_class::value_type< cds::intrusive::treiber_stack::node< cds::gc::HP >> hp_value_type;
73 typedef base_class::value_type< cds::intrusive::treiber_stack::node< cds::gc::DHP >> dhp_value_type;
75 template <typename Stack>
78 value_array<typename Stack::value_type> arrValue( s_nStackSize );
81 do_test( stack, arrValue );
83 Stack::gc::force_dispose();
86 void check_elimination_stat( cds::intrusive::treiber_stack::empty_stat const& )
89 void check_elimination_stat( cds::intrusive::treiber_stack::stat<> const& s )
91 EXPECT_EQ( s.m_PushCount.get() + s.m_ActivePushCollision.get() + s.m_PassivePushCollision.get(), s_nStackSize );
92 EXPECT_EQ( s.m_PopCount.get() + s.m_ActivePopCollision.get() + s.m_PassivePopCollision.get(), s_nStackSize );
93 EXPECT_EQ( s.m_PushCount.get(), s.m_PopCount.get());
94 EXPECT_EQ( s.m_ActivePopCollision.get(), s.m_PassivePushCollision.get());
95 EXPECT_EQ( s.m_ActivePushCollision.get(), s.m_PassivePopCollision.get());
98 template <typename Stack>
99 void test_elimination()
101 value_array<typename Stack::value_type> arrValue( s_nStackSize );
103 Stack stack( s_nEliminationSize );
104 do_test( stack, arrValue );
105 check_elimination_stat( stack.statistics());
107 Stack::gc::force_dispose();
110 template <typename Stack>
113 value_array<typename Stack::value_type> arrValue( s_nStackSize );
115 do_test( stack, arrValue );
119 // TreiberStack<cds::gc::HP>
120 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
121 TEST_F( test_fixture, stack_impl ) \
123 typedef typename istack::Types<hp_value_type>::stack_impl stack_type; \
124 test< stack_type >(); \
127 CDSSTRESS_TreiberStack_HP( intrusive_stack_push_pop )
129 #undef CDSSTRESS_Stack_F
131 // TreiberStack<cds::gc::DHP>
132 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
133 TEST_F( test_fixture, stack_impl ) \
135 typedef typename istack::Types<dhp_value_type>::stack_impl stack_type; \
136 test< stack_type >(); \
139 CDSSTRESS_TreiberStack_DHP( intrusive_stack_push_pop )
141 #undef CDSSTRESS_Stack_F
143 // TreiberStack<cds::gc::HP> + elimination enabled
144 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
145 TEST_F( test_fixture, stack_impl ) \
147 typedef typename istack::Types<hp_value_type>::stack_impl stack_type; \
148 test_elimination< stack_type >(); \
151 CDSSTRESS_EliminationStack_HP( intrusive_stack_push_pop )
153 #undef CDSSTRESS_Stack_F
156 // TreiberStack<cds::gc::DHP> + elimination enabled
157 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
158 TEST_F( test_fixture, stack_impl ) \
160 typedef typename istack::Types<dhp_value_type>::stack_impl stack_type; \
161 test_elimination< stack_type >(); \
164 CDSSTRESS_EliminationStack_DHP( intrusive_stack_push_pop )
166 #undef CDSSTRESS_Stack_F
170 #define CDSSTRESS_Stack_F( test_fixture, stack_impl ) \
171 TEST_F( test_fixture, stack_impl ) \
173 typedef typename istack::Types<value_type>::stack_impl stack_type; \
174 test_std< stack_type >(); \
177 //CDSSTRESS_StdStack( intrusive_stack_push_pop )
179 #undef CDSSTRESS_Stack_F
181 //INSTANTIATE_TEST_CASE_P( a, intrusive_stack_push_pop, ::testing::Values(1));