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 "test_treiber_stack.h"
33 #include <cds/gc/dhp.h>
34 #include <cds/container/treiber_stack.h>
38 namespace cc = cds::container;
39 typedef cds::gc::DHP gc_type;
41 class TreiberStack_DHP : public cds_test::TreiberStack
43 typedef cds_test::TreiberStack base_class;
48 typedef cc::TreiberStack< gc_type, int > stack_type;
50 cds::gc::dhp::smr::construct( stack_type::c_nHazardPtrCount );
51 cds::threading::Manager::attachThread();
56 cds::threading::Manager::detachThread();
57 cds::gc::dhp::smr::destruct();
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( TreiberStack_DHP, defaulted )
77 typedef cc::TreiberStack< gc_type, int > stack_type;
82 TEST_F( TreiberStack_DHP, backoff )
84 typedef cc::TreiberStack< gc_type, int
85 , typename cc::treiber_stack::make_traits<
86 cds::opt::back_off< cds::backoff::yield>
93 TEST_F( TreiberStack_DHP, alloc )
95 // allocator must be rebinded for real value type
98 size_t arr[ 1024 * 1024 ];
99 size_t a2[1024 * 1024];
100 size_t a3[1024 * 1024];
101 size_t a4[1024 * 1024];
104 typedef cc::TreiberStack< gc_type, int
105 , typename cc::treiber_stack::make_traits<
106 cds::opt::back_off< cds::backoff::pause>
107 ,cds::opt::memory_model<cds::opt::v::relaxed_ordering>
108 ,cds::opt::allocator< std::allocator< foo >>
115 TEST_F( TreiberStack_DHP, elimination )
117 typedef cc::TreiberStack< gc_type, int
118 , typename cc::treiber_stack::make_traits<
119 cds::opt::enable_elimination<true>
126 TEST_F( TreiberStack_DHP, elimination_backoff )
128 struct traits : public cc::treiber_stack::traits
131 enable_elimination = true
133 typedef cds::backoff::pause back_off;
135 typedef cc::TreiberStack< gc_type, int, traits > stack_type;
140 TEST_F( TreiberStack_DHP, elimination_dynamic )
142 typedef cc::TreiberStack< gc_type, int
143 , typename cc::treiber_stack::make_traits<
144 cds::opt::enable_elimination<true>
145 , cds::opt::buffer< cds::opt::v::initialized_dynamic_buffer<void *> >
149 test_dyn<stack_type>( 4 );
152 TEST_F( TreiberStack_DHP, elimination_stat )
154 typedef cc::TreiberStack< gc_type, int
155 , typename cc::treiber_stack::make_traits<
156 cds::opt::enable_elimination<true>
157 , cds::opt::stat< cc::treiber_stack::stat<> >
164 TEST_F( TreiberStack_DHP, elimination_dynamic_backoff )
166 struct traits : public cc::treiber_stack::traits
169 enable_elimination = true
171 typedef cds::opt::v::initialized_dynamic_buffer<void *> buffer;
172 typedef cds::backoff::yield back_off;
174 typedef cc::TreiberStack< gc_type, int, traits > stack_type;
176 test_dyn<stack_type>( 2 );