2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
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 "test_intrusive_treiber_stack.h"
33 #include <cds/gc/hp.h>
34 #include <cds/intrusive/treiber_stack.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::HP gc_type;
41 class IntrusiveTreiberStack_HP : public cds_test::IntrusiveTreiberStack
43 typedef cds_test::IntrusiveTreiberStack base_class;
48 typedef cds::intrusive::TreiberStack< gc_type, base_hook_item<gc_type>> stack_type;
50 cds::gc::hp::GarbageCollector::Construct( stack_type::c_nHazardPtrCount, 1, 16 );
51 cds::threading::Manager::attachThread();
56 cds::threading::Manager::detachThread();
57 cds::gc::hp::GarbageCollector::Destruct( true );
60 template <typename Stack>
64 base_class::test( stack );
67 template <typename Stack>
68 void test_dyn( size_t elimination_size )
70 Stack stack( elimination_size );
71 base_class::test( stack );
75 TEST_F( IntrusiveTreiberStack_HP, defaulted )
77 typedef cds::intrusive::TreiberStack< gc_type,
78 base_hook_item<gc_type>
84 TEST_F( IntrusiveTreiberStack_HP, base )
86 typedef cds::intrusive::TreiberStack< gc_type,
87 base_hook_item<gc_type>
88 , typename ci::treiber_stack::make_traits<
90 ci::treiber_stack::base_hook<
100 TEST_F( IntrusiveTreiberStack_HP, base_disposer )
103 ci::treiber_stack::make_traits <
105 ci::treiber_stack::base_hook< ci::opt::gc<gc_type> >
107 ,ci::opt::disposer< mock_disposer >
110 typedef cds::intrusive::TreiberStack<
112 base_hook_item<gc_type>,
119 TEST_F( IntrusiveTreiberStack_HP, member )
122 : ci::treiber_stack::make_traits <
124 ci::treiber_stack::member_hook<
125 offsetof( member_hook_item<gc_type>, hMember),
131 typedef cds::intrusive::TreiberStack<
133 member_hook_item<gc_type>,
140 TEST_F( IntrusiveTreiberStack_HP, member_disposer )
143 : ci::treiber_stack::make_traits <
145 ci::treiber_stack::member_hook<
146 offsetof( member_hook_item<gc_type>, hMember),
150 ,ci::opt::disposer< mock_disposer >
153 typedef cds::intrusive::TreiberStack<
155 member_hook_item<gc_type>,
162 TEST_F( IntrusiveTreiberStack_HP, relaxed )
164 typedef cds::intrusive::TreiberStack< gc_type,
165 base_hook_item<gc_type>
166 , typename ci::treiber_stack::make_traits<
167 ci::opt::memory_model< ci::opt::v::relaxed_ordering >
174 TEST_F( IntrusiveTreiberStack_HP, elimination )
176 typedef cds::intrusive::TreiberStack< gc_type,
177 base_hook_item<gc_type>
178 , typename ci::treiber_stack::make_traits<
179 cds::opt::enable_elimination<true>
186 TEST_F( IntrusiveTreiberStack_HP, elimination_base )
188 typedef cds::intrusive::TreiberStack< gc_type,
189 base_hook_item<gc_type>
190 , typename ci::treiber_stack::make_traits<
191 cds::opt::enable_elimination<true>
193 ci::treiber_stack::base_hook<
203 TEST_F( IntrusiveTreiberStack_HP, elimination_base_dynamic )
205 typedef cds::intrusive::TreiberStack< gc_type,
206 base_hook_item<gc_type>
207 , typename ci::treiber_stack::make_traits<
208 cds::opt::enable_elimination<true>
210 ci::treiber_stack::base_hook<
214 ,ci::opt::buffer< ci::opt::v::dynamic_buffer<void *> >
218 test_dyn<stack_type>( 2 );
221 TEST_F( IntrusiveTreiberStack_HP, elimination_base_disposer )
223 typedef cds::intrusive::TreiberStack< gc_type,
224 base_hook_item<gc_type>
225 , typename ci::treiber_stack::make_traits<
226 cds::opt::enable_elimination<true>
228 ci::treiber_stack::base_hook< ci::opt::gc<gc_type> >
230 ,ci::opt::disposer< mock_disposer >
237 TEST_F( IntrusiveTreiberStack_HP, elimination_member )
239 typedef cds::intrusive::TreiberStack< gc_type,
240 member_hook_item<gc_type>
241 , typename ci::treiber_stack::make_traits<
242 cds::opt::enable_elimination<true>
244 ci::treiber_stack::member_hook<
245 offsetof( member_hook_item<gc_type>, hMember),
255 TEST_F( IntrusiveTreiberStack_HP, elimination_member_dynamic )
257 typedef cds::intrusive::TreiberStack< gc_type,
258 member_hook_item<gc_type>
259 , typename ci::treiber_stack::make_traits<
260 cds::opt::enable_elimination<true>
262 ci::treiber_stack::member_hook<
263 offsetof( member_hook_item<gc_type>, hMember),
267 ,ci::opt::buffer< ci::opt::v::dynamic_buffer<void *> >
271 test_dyn<stack_type>( 2 );
274 TEST_F( IntrusiveTreiberStack_HP, elimination_member_disposer )
276 typedef cds::intrusive::TreiberStack< gc_type,
277 member_hook_item<gc_type>
278 , typename ci::treiber_stack::make_traits<
279 cds::opt::enable_elimination<true>
281 ci::treiber_stack::member_hook<
282 offsetof( member_hook_item<gc_type>, hMember),
286 ,ci::opt::buffer< ci::opt::v::dynamic_buffer<void *> >
287 , ci::opt::disposer< mock_disposer >
291 test_dyn<stack_type>( 2 );