Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_splitlist_set_rcu_gpi.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-2016
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 "set/hdr_intrusive_set.h"
32 #include <cds/urcu/general_instant.h>
33 #include <cds/intrusive/michael_list_rcu.h>
34 #include <cds/intrusive/split_list_rcu.h>
35
36 namespace set {
37     namespace {
38         typedef cds::urcu::gc< cds::urcu::general_instant<> > rcu_type;
39     }
40
41     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_base_cmp()
42     {
43         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
44         typedef ci::MichaelList< rcu_type
45             ,item
46             ,ci::michael_list::make_traits<
47                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
48                 ,co::compare< cmp<item> >
49                 ,ci::opt::disposer< faked_disposer >
50             >::type
51         >    ord_list;
52
53         typedef ci::SplitListSet< rcu_type, ord_list,
54             ci::split_list::make_traits<
55                 co::hash< hash_int >
56                 ,ci::split_list::dynamic_bucket_table<true>
57                 ,co::memory_model<co::v::relaxed_ordering>
58             >::type
59         > set;
60         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
61
62         test_rcu_int_michael_list<set>();
63     }
64
65     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_base_less()
66     {
67         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
68         typedef ci::MichaelList< rcu_type
69             ,item
70             ,ci::michael_list::make_traits<
71                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
72                 ,co::less< less<item> >
73                 ,ci::opt::disposer< faked_disposer >
74             >::type
75         >    ord_list;
76
77         typedef ci::SplitListSet< rcu_type, ord_list,
78             ci::split_list::make_traits<
79                 co::hash< hash_int >
80                 ,co::memory_model<co::v::sequential_consistent>
81             >::type
82         > set;
83         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
84
85         test_rcu_int_michael_list<set>();
86     }
87
88     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_base_cmpmix()
89     {
90         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
91         typedef ci::MichaelList< rcu_type
92             ,item
93             ,ci::michael_list::make_traits<
94                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
95                 ,co::less< less<item> >
96                 ,co::compare< cmp<item> >
97                 ,ci::opt::disposer< faked_disposer >
98             >::type
99         >    ord_list;
100
101         typedef ci::SplitListSet< rcu_type, ord_list,
102             ci::split_list::make_traits<
103                 co::hash< hash_int >
104                 ,co::item_counter< simple_item_counter >
105                 ,ci::split_list::dynamic_bucket_table<true>
106             >::type
107         > set;
108         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
109
110         test_rcu_int_michael_list<set>();
111     }
112
113     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_member_cmp()
114     {
115         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
116         typedef ci::MichaelList< rcu_type
117             ,item
118             ,ci::michael_list::make_traits<
119                 ci::opt::hook< ci::michael_list::member_hook<
120                     offsetof( item, hMember ),
121                     co::gc<rcu_type>
122                 > >
123                 ,co::compare< cmp<item> >
124                 ,ci::opt::disposer< faked_disposer >
125             >::type
126         >    ord_list;
127
128         typedef ci::SplitListSet< rcu_type, ord_list,
129             ci::split_list::make_traits<
130                 co::hash< hash_int >
131             >::type
132         > set;
133         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
134
135         test_rcu_int_michael_list<set>();
136     }
137
138     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_member_less()
139     {
140         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
141         typedef ci::MichaelList< rcu_type
142             ,item
143             ,ci::michael_list::make_traits<
144                 ci::opt::hook< ci::michael_list::member_hook<
145                     offsetof( item, hMember ),
146                     co::gc<rcu_type>
147                 > >
148                 ,co::less< less<item> >
149                 ,ci::opt::disposer< faked_disposer >
150             >::type
151         >    ord_list;
152
153         typedef ci::SplitListSet< rcu_type, ord_list,
154             ci::split_list::make_traits<
155                 co::hash< hash_int >
156                 ,co::memory_model<co::v::relaxed_ordering>
157             >::type
158         > set;
159         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
160
161         test_rcu_int_michael_list<set>();
162     }
163
164     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_member_cmpmix()
165     {
166         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
167         typedef ci::MichaelList< rcu_type
168             ,item
169             ,ci::michael_list::make_traits<
170                 ci::opt::hook< ci::michael_list::member_hook<
171                     offsetof( item, hMember ),
172                     co::gc<rcu_type>
173                 > >
174                 ,co::compare< cmp<item> >
175                 ,co::less< less<item> >
176                 ,ci::opt::disposer< faked_disposer >
177             >::type
178         >    ord_list;
179
180         typedef ci::SplitListSet< rcu_type, ord_list,
181             ci::split_list::make_traits<
182                 co::hash< hash_int >
183                 ,co::item_counter< simple_item_counter >
184                 ,co::memory_model<co::v::sequential_consistent>
185             >::type
186         > set;
187         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
188
189         test_rcu_int_michael_list<set>();
190     }
191
192
193     // Static bucket table
194     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_base_cmp()
195     {
196         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
197         typedef ci::MichaelList< rcu_type
198             ,item
199             ,ci::michael_list::make_traits<
200                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
201                 ,co::compare< cmp<item> >
202                 ,ci::opt::disposer< faked_disposer >
203             >::type
204         >    ord_list;
205
206         typedef ci::SplitListSet< rcu_type, ord_list,
207             ci::split_list::make_traits<
208                 co::hash< hash_int >
209                 ,ci::split_list::dynamic_bucket_table<false>
210                 ,co::memory_model<co::v::relaxed_ordering>
211             >::type
212         > set;
213         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
214
215         test_rcu_int_michael_list<set>();
216     }
217
218     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_base_less()
219     {
220         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
221         typedef ci::MichaelList< rcu_type
222             ,item
223             ,ci::michael_list::make_traits<
224                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
225                 ,co::less< less<item> >
226                 ,ci::opt::disposer< faked_disposer >
227             >::type
228         >    ord_list;
229
230         typedef ci::SplitListSet< rcu_type, ord_list,
231             ci::split_list::make_traits<
232                 co::hash< hash_int >
233                 ,ci::split_list::dynamic_bucket_table<false>
234                 ,co::memory_model<co::v::sequential_consistent>
235             >::type
236         > set;
237         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
238
239         test_rcu_int_michael_list<set>();
240     }
241
242     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_base_cmpmix()
243     {
244         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
245         typedef ci::MichaelList< rcu_type
246             ,item
247             ,ci::michael_list::make_traits<
248                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
249                 ,co::less< less<item> >
250                 ,co::compare< cmp<item> >
251                 ,ci::opt::disposer< faked_disposer >
252             >::type
253         >    ord_list;
254
255         typedef ci::SplitListSet< rcu_type, ord_list,
256             ci::split_list::make_traits<
257                 co::hash< hash_int >
258                 ,co::item_counter< simple_item_counter >
259                 ,ci::split_list::dynamic_bucket_table<false>
260             >::type
261         > set;
262         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
263
264         test_rcu_int_michael_list<set>();
265     }
266
267     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_member_cmp()
268     {
269         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
270         typedef ci::MichaelList< rcu_type
271             ,item
272             ,ci::michael_list::make_traits<
273                 ci::opt::hook< ci::michael_list::member_hook<
274                     offsetof( item, hMember ),
275                     co::gc<rcu_type>
276                 > >
277                 ,co::compare< cmp<item> >
278                 ,ci::opt::disposer< faked_disposer >
279             >::type
280         >    ord_list;
281
282         typedef ci::SplitListSet< rcu_type, ord_list,
283             ci::split_list::make_traits<
284                 co::hash< hash_int >
285                 ,ci::split_list::dynamic_bucket_table<false>
286                 ,co::memory_model<co::v::relaxed_ordering>
287             >::type
288         > set;
289         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
290
291         test_rcu_int_michael_list<set>();
292     }
293
294     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_member_less()
295     {
296         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
297         typedef ci::MichaelList< rcu_type
298             ,item
299             ,ci::michael_list::make_traits<
300                 ci::opt::hook< ci::michael_list::member_hook<
301                     offsetof( item, hMember ),
302                     co::gc<rcu_type>
303                 > >
304                 ,co::less< less<item> >
305                 ,ci::opt::disposer< faked_disposer >
306             >::type
307         >    ord_list;
308
309         typedef ci::SplitListSet< rcu_type, ord_list,
310             ci::split_list::make_traits<
311                 ci::split_list::dynamic_bucket_table<false>
312                 ,co::hash< hash_int >
313                 ,co::memory_model<co::v::sequential_consistent>
314             >::type
315         > set;
316         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
317
318         test_rcu_int_michael_list<set>();
319     }
320
321     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_member_cmpmix()
322     {
323         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
324         typedef ci::MichaelList< rcu_type
325             ,item
326             ,ci::michael_list::make_traits<
327                 ci::opt::hook< ci::michael_list::member_hook<
328                     offsetof( item, hMember ),
329                     co::gc<rcu_type>
330                 > >
331                 ,co::compare< cmp<item> >
332                 ,co::less< less<item> >
333                 ,ci::opt::disposer< faked_disposer >
334             >::type
335         >    ord_list;
336
337         typedef ci::SplitListSet< rcu_type, ord_list,
338             ci::split_list::make_traits<
339                 co::hash< hash_int >
340                 ,co::item_counter< simple_item_counter >
341                 ,ci::split_list::dynamic_bucket_table<false>
342             >::type
343         > set;
344         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
345
346         test_rcu_int_michael_list<set>();
347     }
348
349     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_base_cmpmix_stat()
350     {
351         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
352         struct list_traits : public ci::michael_list::traits
353         {
354             typedef ci::michael_list::base_hook< co::gc<rcu_type> > hook;
355             typedef IntrusiveHashSetHdrTest::less<item> less;
356             typedef cmp<item> compare;
357             typedef faked_disposer disposer;
358         };
359         typedef ci::MichaelList< rcu_type, item, list_traits > ord_list;
360
361         struct set_traits : public ci::split_list::make_traits<ci::split_list::dynamic_bucket_table<true> >::type
362         {
363             typedef hash_int hash;
364             typedef simple_item_counter item_counter;
365             typedef ci::split_list::stat<> stat;
366         };
367         typedef ci::SplitListSet< rcu_type, ord_list, set_traits > set;
368
369         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
370
371         test_rcu_int_michael_list<set>();
372     }
373
374     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPI_member_cmpmix_stat()
375     {
376         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
377         struct list_traits :
378             public ci::michael_list::make_traits<
379                 ci::opt::hook< ci::michael_list::member_hook<
380                     offsetof( item, hMember ),
381                     co::gc<rcu_type>
382                 > >
383                 ,co::compare< cmp<item> >
384                 ,co::less< less<item> >
385                 ,ci::opt::disposer< faked_disposer >
386             >::type
387         {};
388         typedef ci::MichaelList< rcu_type, item, list_traits > ord_list;
389
390         struct set_traits :
391             public ci::split_list::make_traits<
392                 co::hash< hash_int >
393                 ,co::item_counter< simple_item_counter >
394                 ,co::memory_model<co::v::sequential_consistent>
395                 ,co::stat< ci::split_list::stat<>>
396             >::type
397         {};
398         typedef ci::SplitListSet< rcu_type, ord_list, set_traits > set;
399         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
400
401         test_rcu_int_michael_list<set>();
402     }
403
404     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_base_cmpmix_stat()
405     {
406         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
407         typedef ci::MichaelList< rcu_type
408             ,item
409             ,ci::michael_list::make_traits<
410                 ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
411                 ,co::less< less<item> >
412                 ,co::compare< cmp<item> >
413                 ,ci::opt::disposer< faked_disposer >
414             >::type
415         >    ord_list;
416
417         typedef ci::SplitListSet< rcu_type, ord_list,
418             ci::split_list::make_traits<
419                 co::hash< hash_int >
420                 ,co::item_counter< simple_item_counter >
421                 ,ci::split_list::dynamic_bucket_table<false>
422                 ,co::stat< ci::split_list::stat<>>
423             >::type
424         > set;
425         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
426
427         test_rcu_int_michael_list<set>();
428     }
429
430     void IntrusiveHashSetHdrTest::split_st_RCU_GPI_member_cmpmix_stat()
431     {
432         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
433         typedef ci::MichaelList< rcu_type
434             ,item
435             ,ci::michael_list::make_traits<
436                 ci::opt::hook< ci::michael_list::member_hook<
437                     offsetof( item, hMember ),
438                     co::gc<rcu_type>
439                 > >
440                 ,co::compare< cmp<item> >
441                 ,co::less< less<item> >
442                 ,ci::opt::disposer< faked_disposer >
443             >::type
444         >    ord_list;
445
446         typedef ci::SplitListSet< rcu_type, ord_list,
447             ci::split_list::make_traits<
448                 co::hash< hash_int >
449                 ,co::item_counter< simple_item_counter >
450                 ,ci::split_list::dynamic_bucket_table<false>
451                 ,co::stat< ci::split_list::stat<> >
452             >::type
453         > set;
454         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
455
456         test_rcu_int_michael_list<set>();
457     }
458
459
460 } // namespace set