fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / stack / intrusive_treiber_stack_dhp.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13     list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #include "test_intrusive_treiber_stack.h"
32
33 #include <cds/gc/dhp.h>
34 #include <cds/intrusive/treiber_stack.h>
35
36 namespace {
37
38     namespace ci = cds::intrusive;
39
40     class IntrusiveTreiberStack_DHP : public cds_test::IntrusiveTreiberStack
41     {
42         typedef cds_test::IntrusiveTreiberStack base_class;
43     protected:
44         typedef cds::gc::DHP gc_type;
45
46         void SetUp()
47         {
48             typedef cds::intrusive::TreiberStack< gc_type,
49                 base_hook_item<gc_type>
50                 , typename ci::treiber_stack::make_traits<
51                     ci::opt::hook<
52                         ci::treiber_stack::base_hook<
53                             ci::opt::gc<gc_type>
54                         >
55                     >
56                 >::type
57             > stack_type;
58
59             cds::gc::dhp::smr::construct( stack_type::c_nHazardPtrCount );
60             cds::threading::Manager::attachThread();
61         }
62
63         void TearDown()
64         {
65             cds::threading::Manager::detachThread();
66             cds::gc::dhp::smr::destruct();
67         }
68
69         template <typename Stack>
70         void test()
71         {
72             Stack stack;
73             base_class::test( stack );
74         }
75
76         template <typename Stack>
77         void test_dyn( size_t elimination_size )
78         {
79             Stack stack( elimination_size );
80             base_class::test( stack );
81         }
82     };
83
84     TEST_F( IntrusiveTreiberStack_DHP, base )
85     {
86         typedef cds::intrusive::TreiberStack< gc_type,
87             base_hook_item<gc_type>
88             , typename ci::treiber_stack::make_traits<
89                 ci::opt::hook<
90                     ci::treiber_stack::base_hook<
91                         ci::opt::gc<gc_type>
92                     >
93                 >
94             >::type
95         > stack_type;
96
97         test<stack_type>();
98     }
99
100     TEST_F( IntrusiveTreiberStack_DHP, base_disposer )
101     {
102         struct traits:
103             ci::treiber_stack::make_traits <
104                 ci::opt::hook<
105                     ci::treiber_stack::base_hook< ci::opt::gc<gc_type>>
106                 >
107                 ,ci::opt::disposer< mock_disposer >
108             >::type
109         {};
110         typedef cds::intrusive::TreiberStack<
111             gc_type,
112             base_hook_item<gc_type>,
113             traits
114         > stack_type;
115
116         test<stack_type>();
117     }
118
119     TEST_F( IntrusiveTreiberStack_DHP, member )
120     {
121         struct traits
122             : ci::treiber_stack::make_traits <
123                 ci::opt::hook<
124                     ci::treiber_stack::member_hook<
125                         offsetof( member_hook_item<gc_type>, hMember),
126                         ci::opt::gc<gc_type>
127                     >
128                 >
129             > ::type
130         {};
131         typedef cds::intrusive::TreiberStack<
132             gc_type,
133             member_hook_item<gc_type>,
134             traits
135         > stack_type;
136
137         test<stack_type>();
138     }
139
140     TEST_F( IntrusiveTreiberStack_DHP, member_disposer )
141     {
142         struct traits
143             : ci::treiber_stack::make_traits <
144                 ci::opt::hook<
145                     ci::treiber_stack::member_hook<
146                         offsetof( member_hook_item<gc_type>, hMember),
147                         ci::opt::gc<gc_type>
148                     >
149                 >
150                 ,ci::opt::disposer< mock_disposer >
151             >::type
152         {};
153         typedef cds::intrusive::TreiberStack<
154             gc_type,
155             member_hook_item<gc_type>,
156             traits
157         > stack_type;
158
159         test<stack_type>();
160     }
161
162     TEST_F( IntrusiveTreiberStack_DHP, relaxed )
163     {
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 >
168                 ,ci::opt::hook<
169                     ci::treiber_stack::base_hook<
170                         ci::opt::gc<gc_type>
171                     >
172                 >
173             >::type
174         > stack_type;
175
176         test<stack_type>();
177     }
178
179     TEST_F( IntrusiveTreiberStack_DHP, elimination_base )
180     {
181         typedef cds::intrusive::TreiberStack< gc_type,
182             base_hook_item<gc_type>
183             , typename ci::treiber_stack::make_traits<
184                 cds::opt::enable_elimination<true>
185                 ,ci::opt::hook<
186                     ci::treiber_stack::base_hook<
187                         ci::opt::gc<gc_type>
188                     >
189                 >
190             >::type
191         > stack_type;
192
193         test<stack_type>();
194     }
195
196     TEST_F( IntrusiveTreiberStack_DHP, elimination_base_dynamic )
197     {
198         typedef cds::intrusive::TreiberStack< gc_type,
199             base_hook_item<gc_type>
200             , typename ci::treiber_stack::make_traits<
201                 cds::opt::enable_elimination<true>
202                 ,ci::opt::hook<
203                     ci::treiber_stack::base_hook<
204                         ci::opt::gc<gc_type>
205                     >
206                 >
207                 ,ci::opt::buffer< ci::opt::v::initialized_dynamic_buffer<void *> >
208             >::type
209         > stack_type;
210
211         test_dyn<stack_type>( 2 );
212     }
213
214     TEST_F( IntrusiveTreiberStack_DHP, elimination_base_disposer )
215     {
216         typedef cds::intrusive::TreiberStack< gc_type,
217             base_hook_item<gc_type>
218             , typename ci::treiber_stack::make_traits<
219                 cds::opt::enable_elimination<true>
220                 ,ci::opt::hook<
221                     ci::treiber_stack::base_hook< ci::opt::gc<gc_type> >
222                 >
223                 ,ci::opt::disposer< mock_disposer >
224             >::type
225         > stack_type;
226
227         test<stack_type>();
228     }
229
230     TEST_F( IntrusiveTreiberStack_DHP, elimination_member )
231     {
232         typedef cds::intrusive::TreiberStack< gc_type,
233             member_hook_item<gc_type>
234             , typename ci::treiber_stack::make_traits<
235                 cds::opt::enable_elimination<true>
236                 ,ci::opt::hook<
237                     ci::treiber_stack::member_hook<
238                         offsetof( member_hook_item<gc_type>, hMember),
239                         ci::opt::gc<gc_type>
240                     >
241                 >
242             >::type
243         > stack_type;
244
245         test<stack_type>();
246     }
247
248     TEST_F( IntrusiveTreiberStack_DHP, elimination_member_dynamic )
249     {
250         typedef cds::intrusive::TreiberStack< gc_type,
251             member_hook_item<gc_type>
252             , typename ci::treiber_stack::make_traits<
253                 cds::opt::enable_elimination<true>
254                 ,ci::opt::hook<
255                     ci::treiber_stack::member_hook<
256                         offsetof( member_hook_item<gc_type>, hMember),
257                         ci::opt::gc<gc_type>
258                     >
259                 >
260                 ,ci::opt::buffer< ci::opt::v::initialized_dynamic_buffer<void *> >
261             >::type
262         > stack_type;
263
264         test_dyn<stack_type>( 2 );
265     }
266
267     TEST_F( IntrusiveTreiberStack_DHP, elimination_member_disposer )
268     {
269         typedef cds::intrusive::TreiberStack< gc_type,
270             member_hook_item<gc_type>
271             , typename ci::treiber_stack::make_traits<
272                 cds::opt::enable_elimination<true>
273                 ,ci::opt::hook<
274                     ci::treiber_stack::member_hook<
275                         offsetof( member_hook_item<gc_type>, hMember),
276                         ci::opt::gc<gc_type>
277                     >
278                 >
279                 ,ci::opt::buffer< ci::opt::v::initialized_dynamic_buffer<void *> >
280                 , ci::opt::disposer< mock_disposer >
281             >::type
282         > stack_type;
283
284         test_dyn<stack_type>( 2 );
285     }
286
287 } // namespace
288