Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_splitlist_set_rcu_gpb.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_buffered.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_buffered<> > rcu_type;
39     }
40
41     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPB_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_GPB_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_GPB_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_GPB_base_cmpmix_stat()
114     {
115         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
116         struct list_traits : public ci::michael_list::traits
117         {
118             typedef ci::michael_list::base_hook< co::gc<rcu_type> > hook;
119             typedef IntrusiveHashSetHdrTest::less<item> less;
120             typedef cmp<item> compare;
121             typedef faked_disposer disposer;
122         };
123         typedef ci::MichaelList< rcu_type, item, list_traits > ord_list;
124
125         struct set_traits : public ci::split_list::make_traits<ci::split_list::dynamic_bucket_table<true> >::type
126         {
127             typedef hash_int hash;
128             typedef simple_item_counter item_counter;
129             typedef ci::split_list::stat<> stat;
130         };
131         typedef ci::SplitListSet< rcu_type, ord_list, set_traits > set;
132
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_GPB_member_cmp()
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::compare< cmp<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             > ::type
157         > set;
158         static_assert(set::traits::dynamic_bucket_table, "Set has static bucket table");
159
160         test_rcu_int_michael_list<set>();
161     }
162
163     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPB_member_less()
164     {
165         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
166         typedef ci::MichaelList < rcu_type
167             , item
168             , ci::michael_list::make_traits <
169             ci::opt::hook< ci::michael_list::member_hook <
170             offsetof( item, hMember ),
171             co::gc<rcu_type>
172             > >
173             , co::less< less<item> >
174             , ci::opt::disposer < faked_disposer >
175             > ::type
176         > ord_list;
177
178         typedef ci::SplitListSet < rcu_type, ord_list,
179             ci::split_list::make_traits <
180             co::hash< hash_int >
181             , co::memory_model < co::v::relaxed_ordering >
182             > ::type
183         > set;
184         static_assert(set::traits::dynamic_bucket_table, "Set has static bucket table");
185
186         test_rcu_int_michael_list<set>();
187     }
188
189     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPB_member_cmpmix()
190     {
191         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
192         typedef ci::MichaelList < rcu_type
193             , item
194             , ci::michael_list::make_traits <
195             ci::opt::hook< ci::michael_list::member_hook <
196             offsetof( item, hMember ),
197             co::gc<rcu_type>
198             > >
199             , co::compare< cmp<item> >
200             , co::less< less<item> >
201             , ci::opt::disposer < faked_disposer >
202             > ::type
203         > ord_list;
204
205         typedef ci::SplitListSet < rcu_type, ord_list,
206             ci::split_list::make_traits <
207             co::hash< hash_int >
208             , co::item_counter< simple_item_counter >
209             , co::memory_model < co::v::sequential_consistent >
210             > ::type
211         > set;
212         static_assert(set::traits::dynamic_bucket_table, "Set has static bucket table");
213
214         test_rcu_int_michael_list<set>();
215     }
216
217     void IntrusiveHashSetHdrTest::split_dyn_RCU_GPB_member_cmpmix_stat()
218     {
219         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
220         struct list_traits :
221             public ci::michael_list::make_traits <
222             ci::opt::hook< ci::michael_list::member_hook <
223             offsetof( item, hMember ),
224             co::gc<rcu_type>
225             > >
226             , co::compare< cmp<item> >
227             , co::less< less<item> >
228             , ci::opt::disposer < faked_disposer >
229             > ::type
230         {};
231         typedef ci::MichaelList< rcu_type, item, list_traits > ord_list;
232
233         struct set_traits :
234             public ci::split_list::make_traits <
235             co::hash< hash_int >
236             , co::item_counter< simple_item_counter >
237             , co::memory_model<co::v::sequential_consistent>
238             , co::stat < ci::split_list::stat<> >
239             > ::type
240         {};
241         typedef ci::SplitListSet< rcu_type, ord_list, set_traits > set;
242         static_assert(set::traits::dynamic_bucket_table, "Set has static bucket table");
243
244         test_rcu_int_michael_list<set>();
245     }
246
247     // Static bucket table
248     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_base_cmp()
249     {
250         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
251         typedef ci::MichaelList < rcu_type
252             , item
253             , ci::michael_list::make_traits <
254             ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
255             , co::compare< cmp<item> >
256             , ci::opt::disposer < faked_disposer >
257             > ::type
258         > ord_list;
259
260         typedef ci::SplitListSet < rcu_type, ord_list,
261             ci::split_list::make_traits <
262             co::hash< hash_int >
263             , ci::split_list::dynamic_bucket_table<false>
264             , co::memory_model < co::v::relaxed_ordering >
265             > ::type
266         > set;
267         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
268
269         test_rcu_int_michael_list<set>();
270     }
271
272     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_base_less()
273     {
274         typedef base_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
275         typedef ci::MichaelList < rcu_type
276             , item
277             , ci::michael_list::make_traits <
278             ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
279             , co::less< less<item> >
280             , ci::opt::disposer < faked_disposer >
281             > ::type
282         > ord_list;
283
284         typedef ci::SplitListSet < rcu_type, ord_list,
285             ci::split_list::make_traits <
286             co::hash< hash_int >
287             , ci::split_list::dynamic_bucket_table<false>
288             , co::memory_model < co::v::sequential_consistent >
289             > ::type
290         > set;
291         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
292
293         test_rcu_int_michael_list<set>();
294     }
295
296     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_base_cmpmix()
297     {
298         typedef base_int_item< ci::split_list::node<ci::michael_list::node<rcu_type> > > item;
299         typedef ci::MichaelList < rcu_type
300             , item
301             , ci::michael_list::make_traits <
302             ci::opt::hook< ci::michael_list::base_hook< co::gc<rcu_type> > >
303             , co::less< less<item> >
304             , co::compare< cmp<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             co::hash< hash_int >
312             , co::item_counter< simple_item_counter >
313             , ci::split_list::dynamic_bucket_table < false >
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_GPB_base_cmpmix_stat()
322     {
323         typedef base_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::base_hook< co::gc<rcu_type> > >
328             , co::less< less<item> >
329             , co::compare< cmp<item> >
330             , ci::opt::disposer < faked_disposer >
331             > ::type
332         > ord_list;
333
334         typedef ci::SplitListSet < rcu_type, ord_list,
335             ci::split_list::make_traits <
336             co::hash< hash_int >
337             , co::item_counter< simple_item_counter >
338             , ci::split_list::dynamic_bucket_table<false>
339             , co::stat < ci::split_list::stat<> >
340             > ::type
341         > set;
342         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
343
344         test_rcu_int_michael_list<set>();
345     }
346
347     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_member_cmp()
348     {
349         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
350         typedef ci::MichaelList < rcu_type
351             , item
352             , ci::michael_list::make_traits <
353             ci::opt::hook< ci::michael_list::member_hook <
354             offsetof( item, hMember ),
355             co::gc<rcu_type>
356             > >
357             , co::compare< cmp<item> >
358             , ci::opt::disposer < faked_disposer >
359             > ::type
360         > ord_list;
361
362         typedef ci::SplitListSet < rcu_type, ord_list,
363             ci::split_list::make_traits <
364             co::hash< hash_int >
365             , ci::split_list::dynamic_bucket_table<false>
366             , co::memory_model < co::v::relaxed_ordering >
367             > ::type
368         > set;
369         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
370
371         test_rcu_int_michael_list<set>();
372     }
373
374     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_member_less()
375     {
376         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
377         typedef ci::MichaelList < rcu_type
378             , item
379             , ci::michael_list::make_traits <
380             ci::opt::hook< ci::michael_list::member_hook <
381             offsetof( item, hMember ),
382             co::gc<rcu_type>
383             > >
384             , co::less< less<item> >
385             , ci::opt::disposer < faked_disposer >
386             > ::type
387         > ord_list;
388
389         typedef ci::SplitListSet < rcu_type, ord_list,
390             ci::split_list::make_traits <
391             ci::split_list::dynamic_bucket_table<false>
392             , co::hash< hash_int >
393             , co::memory_model < co::v::sequential_consistent >
394             > ::type
395         > set;
396         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
397
398         test_rcu_int_michael_list<set>();
399     }
400
401     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_member_cmpmix()
402     {
403         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
404         typedef ci::MichaelList < rcu_type
405             , item
406             , ci::michael_list::make_traits <
407             ci::opt::hook< ci::michael_list::member_hook <
408             offsetof( item, hMember ),
409             co::gc<rcu_type>
410             > >
411             , co::compare< cmp<item> >
412             , co::less< less<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             > ::type
423         > set;
424         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
425
426         test_rcu_int_michael_list<set>();
427     }
428
429     void IntrusiveHashSetHdrTest::split_st_RCU_GPB_member_cmpmix_stat()
430     {
431         typedef member_int_item< ci::split_list::node< ci::michael_list::node<rcu_type> > > item;
432         typedef ci::MichaelList < rcu_type
433             , item
434             , ci::michael_list::make_traits <
435             ci::opt::hook< ci::michael_list::member_hook <
436             offsetof( item, hMember ),
437             co::gc<rcu_type>
438             > >
439             , co::compare< cmp<item> >
440             , co::less< less<item> >
441             , ci::opt::disposer < faked_disposer >
442             > ::type
443         > ord_list;
444
445         typedef ci::SplitListSet < rcu_type, ord_list,
446             ci::split_list::make_traits <
447             co::hash< hash_int >
448             , co::item_counter< simple_item_counter >
449             , ci::split_list::dynamic_bucket_table<false>
450             , co::stat < ci::split_list::stat<> >
451             > ::type
452         > set;
453         static_assert(!set::traits::dynamic_bucket_table, "Set has dynamic bucket table");
454
455         test_rcu_int_michael_list<set>();
456     }
457 } // namespace set