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