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