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