fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / intrusive-list / intrusive_michael_hp.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_list_hp.h"
32 #include <cds/intrusive/michael_list_hp.h>
33
34 namespace {
35     namespace ci = cds::intrusive;
36     typedef cds::gc::HP gc_type;
37
38     class IntrusiveMichaelList_HP : public cds_test::intrusive_list_hp
39     {
40     public:
41         typedef cds_test::intrusive_list_hp::base_item< ci::michael_list::node< gc_type>> base_item;
42         typedef cds_test::intrusive_list_hp::member_item< ci::michael_list::node< gc_type>> member_item;
43
44     protected:
45         void SetUp()
46         {
47             struct traits: public ci::michael_list::traits
48             {
49                 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
50             };
51             typedef ci::MichaelList< gc_type, base_item, traits > list_type;
52
53             // +1 - for guarded_ptr
54             cds::gc::hp::GarbageCollector::Construct( list_type::c_nHazardPtrCount + 1, 1, 16 );
55             cds::threading::Manager::attachThread();
56         }
57
58         void TearDown()
59         {
60             cds::threading::Manager::detachThread();
61             cds::gc::hp::GarbageCollector::Destruct( true );
62         }
63     };
64
65     TEST_F( IntrusiveMichaelList_HP, base_hook )
66     {
67         typedef ci::MichaelList< gc_type, base_item,
68             typename ci::michael_list::make_traits<
69                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
70                 ,ci::opt::disposer< mock_disposer >
71                 ,cds::opt::less< less< base_item >>
72             >::type
73        > list_type;
74
75        list_type l;
76        test_common( l );
77        test_ordered_iterator( l );
78        test_hp( l );
79     }
80
81     TEST_F( IntrusiveMichaelList_HP, base_hook_cmp )
82     {
83         typedef ci::MichaelList< gc_type, base_item,
84             typename ci::michael_list::make_traits<
85                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
86                 , ci::opt::disposer< mock_disposer >
87                 , cds::opt::compare< cmp< base_item >>
88             >::type
89         > list_type;
90
91         list_type l;
92         test_common( l );
93         test_ordered_iterator( l );
94         test_hp( l );
95     }
96
97     TEST_F( IntrusiveMichaelList_HP, base_hook_item_counting )
98     {
99         struct traits : public ci::michael_list::traits {
100             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
101             typedef mock_disposer disposer;
102             typedef cmp< base_item > compare;
103             typedef intrusive_list_common::less< base_item > less;
104             typedef cds::atomicity::item_counter item_counter;
105         };
106         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
107
108         list_type l;
109         test_common( l );
110         test_ordered_iterator( l );
111         test_hp( l );
112     }
113
114     TEST_F( IntrusiveMichaelList_HP, base_hook_cache_friendly_item_counting )
115     {
116         struct traits: public ci::michael_list::traits {
117             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
118             typedef mock_disposer disposer;
119             typedef cmp< base_item > compare;
120             typedef intrusive_list_common::less< base_item > less;
121             typedef cds::atomicity::cache_friendly_item_counter item_counter;
122         };
123         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
124
125         list_type l;
126         test_common( l );
127         test_ordered_iterator( l );
128         test_hp( l );
129     }
130
131     TEST_F( IntrusiveMichaelList_HP, base_hook_backoff )
132     {
133         struct traits : public ci::michael_list::traits {
134             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
135             typedef mock_disposer disposer;
136             typedef cmp< base_item > compare;
137             typedef intrusive_list_common::less< base_item > less;
138             typedef cds::atomicity::item_counter item_counter;
139             typedef cds::backoff::pause back_off;
140         };
141         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
142
143         list_type l;
144         test_common( l );
145         test_ordered_iterator( l );
146         test_hp( l );
147     }
148
149     TEST_F( IntrusiveMichaelList_HP, base_hook_seqcst )
150     {
151         struct traits : public ci::michael_list::traits {
152             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
153             typedef mock_disposer disposer;
154             typedef cmp< base_item > compare;
155             typedef intrusive_list_common::less< base_item > less;
156             typedef cds::atomicity::item_counter item_counter;
157             typedef cds::opt::v::sequential_consistent memory_model;
158         };
159         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
160
161         list_type l;
162         test_common( l );
163         test_ordered_iterator( l );
164         test_hp( l );
165     }
166
167     TEST_F( IntrusiveMichaelList_HP, base_hook_stat )
168     {
169         struct traits: public ci::michael_list::traits {
170             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
171             typedef mock_disposer disposer;
172             typedef cmp< base_item > compare;
173             typedef intrusive_list_common::less< base_item > less;
174             typedef cds::intrusive::michael_list::stat<> stat;
175         };
176         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
177
178         list_type l;
179         test_common( l );
180         test_ordered_iterator( l );
181         test_hp( l );
182     }
183
184     TEST_F( IntrusiveMichaelList_HP, base_hook_wrapped_stat )
185     {
186         struct traits: public ci::michael_list::traits {
187             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
188             typedef mock_disposer disposer;
189             typedef cmp< base_item > compare;
190             typedef cds::intrusive::michael_list::wrapped_stat<> stat;
191         };
192         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
193
194         cds::intrusive::michael_list::stat<> st;
195         list_type l( st );
196         test_common( l );
197         test_ordered_iterator( l );
198         test_hp( l );
199     }
200
201     TEST_F( IntrusiveMichaelList_HP, member_hook )
202     {
203         typedef ci::MichaelList< gc_type, member_item,
204             typename ci::michael_list::make_traits<
205                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
206                 ,ci::opt::disposer< mock_disposer >
207                 ,cds::opt::less< less< member_item >>
208             >::type
209        > list_type;
210
211        list_type l;
212        test_common( l );
213        test_ordered_iterator( l );
214        test_hp( l );
215     }
216
217     TEST_F( IntrusiveMichaelList_HP, member_hook_cmp )
218     {
219         typedef ci::MichaelList< gc_type, member_item,
220             typename ci::michael_list::make_traits<
221                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
222                 ,ci::opt::disposer< mock_disposer >
223                 ,cds::opt::compare< cmp< member_item >>
224             >::type
225         > list_type;
226
227         list_type l;
228         test_common( l );
229         test_ordered_iterator( l );
230         test_hp( l );
231     }
232
233     TEST_F( IntrusiveMichaelList_HP, member_hook_item_counting )
234     {
235         struct traits : public ci::michael_list::traits {
236             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
237             typedef mock_disposer disposer;
238             typedef cmp< member_item > compare;
239             typedef intrusive_list_common::less< member_item > less;
240             typedef cds::atomicity::item_counter item_counter;
241         };
242         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
243
244         list_type l;
245         test_common( l );
246         test_ordered_iterator( l );
247         test_hp( l );
248     }
249
250     TEST_F( IntrusiveMichaelList_HP, member_hook_seqcst )
251     {
252         struct traits : public ci::michael_list::traits {
253             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
254             typedef mock_disposer disposer;
255             typedef cmp< member_item > compare;
256             typedef intrusive_list_common::less< member_item > less;
257             typedef cds::atomicity::item_counter item_counter;
258             typedef cds::opt::v::sequential_consistent memory_model;
259         };
260         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
261
262         list_type l;
263         test_common( l );
264         test_ordered_iterator( l );
265         test_hp( l );
266     }
267
268     TEST_F( IntrusiveMichaelList_HP, member_hook_back_off )
269     {
270         struct traits : public ci::michael_list::traits {
271             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
272             typedef mock_disposer disposer;
273             typedef cmp< member_item > compare;
274             typedef intrusive_list_common::less< member_item > less;
275             typedef cds::atomicity::item_counter item_counter;
276             typedef cds::backoff::empty back_off;
277         };
278         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
279
280         list_type l;
281         test_common( l );
282         test_ordered_iterator( l );
283         test_hp( l );
284     }
285
286     TEST_F( IntrusiveMichaelList_HP, member_hook_stat )
287     {
288         struct traits: public ci::michael_list::traits {
289             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
290             typedef mock_disposer disposer;
291             typedef cmp< member_item > compare;
292             typedef intrusive_list_common::less< member_item > less;
293             typedef cds::intrusive::michael_list::stat<> stat;
294         };
295         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
296
297         list_type l;
298         test_common( l );
299         test_ordered_iterator( l );
300         test_hp( l );
301     }
302
303     TEST_F( IntrusiveMichaelList_HP, member_hook_wrapped_stat )
304     {
305         struct traits: public ci::michael_list::traits {
306             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
307             typedef mock_disposer disposer;
308             typedef cmp< member_item > compare;
309             typedef cds::intrusive::michael_list::wrapped_stat<> stat;
310         };
311         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
312
313         cds::intrusive::michael_list::stat<> st;
314         list_type l( st );
315         test_common( l );
316         test_ordered_iterator( l );
317         test_hp( l );
318     }
319
320 } // namespace