fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / intrusive-set / test_intrusive_split_lazy_rcu.h
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 #ifndef CDSUNIT_SET_TEST_INTRUSIVE_SPLIT_LAZY_RCU_H
31 #define CDSUNIT_SET_TEST_INTRUSIVE_SPLIT_LAZY_RCU_H
32
33 #include "test_intrusive_set_rcu.h"
34 #include <cds/intrusive/lazy_list_rcu.h>
35 #include <cds/intrusive/split_list_rcu.h>
36 #include <cds/intrusive/free_list.h>
37
38 namespace ci = cds::intrusive;
39
40 template <class RCU>
41 class IntrusiveSplitLazySet: public cds_test::intrusive_set_rcu
42 {
43     typedef cds_test::intrusive_set_rcu base_class;
44 public:
45     typedef cds::urcu::gc<RCU> rcu_type;
46     typedef typename base_class::base_int_item< ci::split_list::node<ci::lazy_list::node<rcu_type>>>   base_item_type;
47     typedef typename base_class::base_int_item< ci::split_list::node<ci::lazy_list::node<rcu_type, std::mutex>>>   base_mutex_item_type;
48     typedef typename base_class::member_int_item< ci::split_list::node<ci::lazy_list::node<rcu_type>>> member_item_type;
49     typedef typename base_class::member_int_item< ci::split_list::node<ci::lazy_list::node<rcu_type, std::mutex>>> member_mutex_item_type;
50
51 protected:
52     void SetUp()
53     {
54         RCU::Construct();
55         cds::threading::Manager::attachThread();
56     }
57
58     void TearDown()
59     {
60         cds::threading::Manager::detachThread();
61         RCU::Destruct();
62     }
63 };
64
65 TYPED_TEST_CASE_P( IntrusiveSplitLazySet );
66
67 TYPED_TEST_P( IntrusiveSplitLazySet, base_cmp )
68 {
69     typedef typename TestFixture::rcu_type rcu_type;
70     typedef typename TestFixture::base_item_type base_item_type;
71     typedef typename TestFixture::mock_disposer mock_disposer;
72     typedef typename TestFixture::template cmp<base_item_type> item_cmp;
73     typedef typename TestFixture::hash_int hash_int;
74
75     typedef ci::LazyList< rcu_type
76         , base_item_type
77         , typename ci::lazy_list::make_traits<
78             ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< rcu_type > > >
79             , ci::opt::compare< item_cmp >
80             , ci::opt::disposer< mock_disposer >
81         >::type
82     > bucket_type;
83
84     typedef ci::SplitListSet< rcu_type, bucket_type,
85         typename ci::split_list::make_traits<
86             ci::opt::hash< hash_int >
87         >::type
88     > set_type;
89
90     set_type s( TestFixture::kSize, 2 );
91     this->test( s );
92 }
93
94 TYPED_TEST_P( IntrusiveSplitLazySet, base_less )
95 {
96     typedef typename TestFixture::rcu_type rcu_type;
97     typedef typename TestFixture::base_item_type base_item_type;
98     typedef typename TestFixture::mock_disposer mock_disposer;
99     typedef typename TestFixture::template less<base_item_type> item_less;
100     typedef typename TestFixture::hash_int hash_int;
101
102     typedef ci::LazyList< rcu_type
103         , base_item_type
104         , typename ci::lazy_list::make_traits<
105             ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< rcu_type >>>
106             , ci::opt::less< item_less >
107             , ci::opt::disposer< mock_disposer >
108         >::type
109     > bucket_type;
110
111     typedef ci::SplitListSet< rcu_type, bucket_type,
112         typename ci::split_list::make_traits<
113             ci::opt::hash< hash_int >
114             , ci::opt::item_counter< cds::atomicity::item_counter >
115         >::type
116     > set_type;
117
118     set_type s( TestFixture::kSize, 2 );
119     this->test( s );
120 }
121
122 TYPED_TEST_P( IntrusiveSplitLazySet, base_cmpmix )
123 {
124     typedef typename TestFixture::rcu_type rcu_type;
125     typedef typename TestFixture::base_item_type base_item_type;
126     typedef typename TestFixture::mock_disposer mock_disposer;
127     typedef typename TestFixture::hash_int hash_int;
128
129     struct list_traits : public ci::lazy_list::traits
130     {
131         typedef ci::lazy_list::base_hook< ci::opt::gc<rcu_type>> hook;
132         typedef typename TestFixture::template less<base_item_type> less;
133         typedef typename TestFixture::template cmp<base_item_type> compare;
134         typedef mock_disposer disposer;
135     };
136     typedef ci::LazyList< rcu_type, base_item_type, list_traits > bucket_type;
137
138     struct set_traits : public ci::split_list::traits
139     {
140         typedef hash_int hash;
141         typedef typename TestFixture::simple_item_counter item_counter;
142         typedef ci::split_list::stat<> stat;
143     };
144     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
145
146     set_type s( TestFixture::kSize, 2 );
147     this->test( s );
148 }
149
150 TYPED_TEST_P( IntrusiveSplitLazySet, base_mutex )
151 {
152     typedef typename TestFixture::rcu_type rcu_type;
153     typedef typename TestFixture::base_mutex_item_type base_mutex_item_type;
154     typedef typename TestFixture::mock_disposer mock_disposer;
155     typedef typename TestFixture::hash_int hash_int;
156
157     struct list_traits : public ci::lazy_list::traits
158     {
159         typedef ci::lazy_list::base_hook< ci::opt::gc<rcu_type>, ci::opt::lock_type<std::mutex>> hook;
160         typedef typename TestFixture::template less<base_mutex_item_type> less;
161         typedef typename TestFixture::template cmp<base_mutex_item_type> compare;
162         typedef mock_disposer disposer;
163     };
164     typedef ci::LazyList< rcu_type, base_mutex_item_type, list_traits > bucket_type;
165
166     struct set_traits : public ci::split_list::traits
167     {
168         typedef hash_int hash;
169         typedef typename TestFixture::simple_item_counter item_counter;
170         typedef cds::backoff::empty back_off;
171     };
172     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
173
174     set_type s( TestFixture::kSize, 2 );
175     this->test( s );
176 }
177
178 TYPED_TEST_P( IntrusiveSplitLazySet, base_static_bucket_table )
179 {
180     typedef typename TestFixture::rcu_type rcu_type;
181     typedef typename TestFixture::base_item_type base_item_type;
182     typedef typename TestFixture::mock_disposer mock_disposer;
183     typedef typename TestFixture::hash_int hash_int;
184
185     struct list_traits: public ci::lazy_list::traits
186     {
187         typedef ci::lazy_list::base_hook< ci::opt::gc<rcu_type>> hook;
188         typedef typename TestFixture::template less<base_item_type> less;
189         typedef typename TestFixture::template cmp<base_item_type> compare;
190         typedef mock_disposer disposer;
191     };
192     typedef ci::LazyList< rcu_type, base_item_type, list_traits > bucket_type;
193
194     struct set_traits: public ci::split_list::traits
195     {
196         typedef hash_int hash;
197         typedef typename TestFixture::simple_item_counter item_counter;
198         typedef ci::split_list::stat<> stat;
199         enum {
200             dynamic_bucket_table = false
201         };
202     };
203     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
204
205     set_type s( TestFixture::kSize, 2 );
206     this->test( s );
207 }
208
209 TYPED_TEST_P( IntrusiveSplitLazySet, base_static_bucket_table_free_list )
210 {
211     typedef typename TestFixture::rcu_type rcu_type;
212     typedef typename TestFixture::base_item_type base_item_type;
213     typedef typename TestFixture::mock_disposer mock_disposer;
214     typedef typename TestFixture::hash_int hash_int;
215
216     struct list_traits: public ci::lazy_list::traits
217     {
218         typedef ci::lazy_list::base_hook< ci::opt::gc<rcu_type>> hook;
219         typedef typename TestFixture::template less<base_item_type> less;
220         typedef mock_disposer disposer;
221     };
222     typedef ci::LazyList< rcu_type, base_item_type, list_traits > bucket_type;
223
224     struct set_traits: public ci::split_list::traits
225     {
226         typedef hash_int hash;
227         typedef typename TestFixture::simple_item_counter item_counter;
228         typedef ci::split_list::stat<> stat;
229         enum {
230             dynamic_bucket_table = false
231         };
232         typedef ci::FreeList free_list;
233     };
234     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
235
236     set_type s( TestFixture::kSize, 2 );
237     this->test( s );
238 }
239
240 TYPED_TEST_P( IntrusiveSplitLazySet, base_free_list )
241 {
242     typedef typename TestFixture::rcu_type rcu_type;
243     typedef typename TestFixture::base_item_type base_item_type;
244     typedef typename TestFixture::mock_disposer mock_disposer;
245     typedef typename TestFixture::hash_int hash_int;
246
247     struct list_traits: public ci::lazy_list::traits
248     {
249         typedef ci::lazy_list::base_hook< ci::opt::gc<rcu_type>> hook;
250         typedef typename TestFixture::template cmp<base_item_type> compare;
251         typedef mock_disposer disposer;
252     };
253     typedef ci::LazyList< rcu_type, base_item_type, list_traits > bucket_type;
254
255     struct set_traits: public ci::split_list::traits
256     {
257         typedef hash_int hash;
258         typedef typename TestFixture::simple_item_counter item_counter;
259         typedef ci::split_list::stat<> stat;
260         typedef ci::FreeList free_list;
261     };
262     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
263
264     set_type s( TestFixture::kSize, 2 );
265     this->test( s );
266 }
267
268 TYPED_TEST_P( IntrusiveSplitLazySet, member_cmp )
269 {
270     typedef typename TestFixture::rcu_type rcu_type;
271     typedef typename TestFixture::member_item_type member_item_type;
272     typedef typename TestFixture::mock_disposer mock_disposer;
273     typedef typename TestFixture::template cmp<member_item_type> item_cmp;
274     typedef typename TestFixture::hash_int hash_int;
275
276     typedef ci::LazyList< rcu_type
277         , member_item_type
278         , typename ci::lazy_list::make_traits<
279             ci::opt::hook< ci::lazy_list::member_hook<
280                 offsetof( member_item_type, hMember ),
281                 ci::opt::gc<rcu_type>
282             >>
283             , ci::opt::compare< item_cmp >
284             , ci::opt::disposer< mock_disposer >
285         >::type
286     >    bucket_type;
287
288     typedef ci::SplitListSet< rcu_type, bucket_type,
289         typename ci::split_list::make_traits<
290             ci::opt::hash< hash_int >
291         >::type
292     > set_type;
293
294     set_type s( TestFixture::kSize, 2 );
295     this->test( s );
296 }
297
298 TYPED_TEST_P( IntrusiveSplitLazySet, member_less )
299 {
300     typedef typename TestFixture::rcu_type rcu_type;
301     typedef typename TestFixture::member_item_type member_item_type;
302     typedef typename TestFixture::mock_disposer mock_disposer;
303     typedef typename TestFixture::template less<member_item_type> item_less;
304     typedef typename TestFixture::hash_int hash_int;
305
306     typedef ci::LazyList< rcu_type
307         , member_item_type
308         , typename ci::lazy_list::make_traits<
309             ci::opt::hook< ci::lazy_list::member_hook<
310                 offsetof( member_item_type, hMember ),
311                 ci::opt::gc<rcu_type>
312             > >
313             , ci::opt::less< item_less >
314             , ci::opt::disposer< mock_disposer >
315         >::type
316     > bucket_type;
317
318     typedef ci::SplitListSet< rcu_type, bucket_type,
319         typename ci::split_list::make_traits<
320             ci::opt::hash< hash_int >
321             , ci::opt::back_off< cds::backoff::pause >
322         >::type
323     > set_type;
324
325     set_type s( TestFixture::kSize, 2 );
326     this->test( s );
327 }
328
329 TYPED_TEST_P( IntrusiveSplitLazySet, member_cmpmix )
330 {
331     typedef typename TestFixture::rcu_type rcu_type;
332     typedef typename TestFixture::member_item_type member_item_type;
333     typedef typename TestFixture::mock_disposer mock_disposer;
334     typedef typename TestFixture::hash_int hash_int;
335
336     struct list_traits : public ci::lazy_list::traits
337     {
338         typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
339         typedef typename TestFixture::template less<member_item_type> less;
340         typedef typename TestFixture::template cmp<member_item_type> compare;
341         typedef mock_disposer disposer;
342     };
343     typedef ci::LazyList< rcu_type, member_item_type, list_traits > bucket_type;
344
345     struct set_traits : public ci::split_list::traits
346     {
347         typedef hash_int hash;
348         typedef typename TestFixture::simple_item_counter item_counter;
349     };
350     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
351
352     set_type s( TestFixture::kSize, 2 );
353     this->test( s );
354 }
355
356 TYPED_TEST_P( IntrusiveSplitLazySet, member_mutex )
357 {
358     typedef typename TestFixture::rcu_type rcu_type;
359     typedef typename TestFixture::member_mutex_item_type member_mutex_item_type;
360     typedef typename TestFixture::mock_disposer mock_disposer;
361     typedef typename TestFixture::hash_int hash_int;
362
363     struct list_traits : public ci::lazy_list::traits
364     {
365         typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<rcu_type>, ci::opt::lock_type<std::mutex>> hook;
366         typedef typename TestFixture::template less<member_mutex_item_type> less;
367         typedef typename TestFixture::template cmp<member_mutex_item_type> compare;
368         typedef mock_disposer disposer;
369     };
370     typedef ci::LazyList< rcu_type, member_mutex_item_type, list_traits > bucket_type;
371
372     struct set_traits : public ci::split_list::traits
373     {
374         typedef hash_int hash;
375         typedef typename TestFixture::simple_item_counter item_counter;
376     };
377     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
378
379     set_type s( TestFixture::kSize, 2 );
380     this->test( s );
381 }
382
383 TYPED_TEST_P( IntrusiveSplitLazySet, member_static_bucket_table )
384 {
385     typedef typename TestFixture::rcu_type rcu_type;
386     typedef typename TestFixture::member_item_type member_item_type;
387     typedef typename TestFixture::mock_disposer mock_disposer;
388     typedef typename TestFixture::hash_int hash_int;
389
390     struct list_traits: public ci::lazy_list::traits
391     {
392         typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
393         typedef typename TestFixture::template less<member_item_type> less;
394         typedef typename TestFixture::template cmp<member_item_type> compare;
395         typedef mock_disposer disposer;
396     };
397     typedef ci::LazyList< rcu_type, member_item_type, list_traits > bucket_type;
398
399     struct set_traits: public ci::split_list::traits
400     {
401         typedef hash_int hash;
402         typedef typename TestFixture::simple_item_counter item_counter;
403         enum {
404             dynamic_bucket_table = false
405         };
406     };
407     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
408
409     set_type s( TestFixture::kSize, 2 );
410     this->test( s );
411 }
412
413 TYPED_TEST_P( IntrusiveSplitLazySet, member_static_bucket_table_free_list )
414 {
415     typedef typename TestFixture::rcu_type rcu_type;
416     typedef typename TestFixture::member_item_type member_item_type;
417     typedef typename TestFixture::mock_disposer mock_disposer;
418     typedef typename TestFixture::hash_int hash_int;
419
420     struct list_traits: public ci::lazy_list::traits
421     {
422         typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
423         typedef typename TestFixture::template less<member_item_type> less;
424         typedef typename TestFixture::template cmp<member_item_type> compare;
425         typedef mock_disposer disposer;
426     };
427     typedef ci::LazyList< rcu_type, member_item_type, list_traits > bucket_type;
428
429     struct set_traits: public ci::split_list::traits
430     {
431         typedef hash_int hash;
432         typedef typename TestFixture::simple_item_counter item_counter;
433         enum {
434             dynamic_bucket_table = false
435         };
436         typedef ci::FreeList free_list;
437     };
438     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
439
440     set_type s( TestFixture::kSize, 2 );
441     this->test( s );
442 }
443
444 TYPED_TEST_P( IntrusiveSplitLazySet, member_free_list )
445 {
446     typedef typename TestFixture::rcu_type rcu_type;
447     typedef typename TestFixture::member_item_type member_item_type;
448     typedef typename TestFixture::mock_disposer mock_disposer;
449     typedef typename TestFixture::hash_int hash_int;
450
451     struct list_traits: public ci::lazy_list::traits
452     {
453         typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<rcu_type>> hook;
454         typedef typename TestFixture::template cmp<member_item_type> compare;
455         typedef mock_disposer disposer;
456     };
457     typedef ci::LazyList< rcu_type, member_item_type, list_traits > bucket_type;
458
459     struct set_traits: public ci::split_list::traits
460     {
461         typedef hash_int hash;
462         typedef typename TestFixture::simple_item_counter item_counter;
463         typedef ci::FreeList free_list;
464     };
465     typedef ci::SplitListSet< rcu_type, bucket_type, set_traits > set_type;
466
467     set_type s( TestFixture::kSize, 2 );
468     this->test( s );
469 }
470
471 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
472 // "No test named <test_name> can be found in this test case"
473 REGISTER_TYPED_TEST_CASE_P( IntrusiveSplitLazySet,
474     base_cmp, base_less, base_cmpmix, base_mutex, base_static_bucket_table, base_static_bucket_table_free_list, base_free_list, member_cmp, member_less, member_cmpmix, member_mutex, member_static_bucket_table, member_static_bucket_table_free_list, member_free_list
475 );
476
477
478 #endif // CDSUNIT_SET_TEST_INTRUSIVE_MICHAEL_LAZY_RCU_H
479