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