Fixed container::StripedSet::emplace() bug
[libcds.git] / tests / test-hdr / set / hdr_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_set.h"
32 #include <cds/urcu/general_instant.h>
33 #include <cds/container/michael_list_rcu.h>
34 #include <cds/container/split_list_set_rcu.h>
35
36 namespace set {
37
38     namespace {
39         typedef cds::urcu::gc< cds::urcu::general_instant<> > rcu_type;
40
41         struct RCU_GPI_cmp_traits: public cc::split_list::traits
42         {
43             typedef cc::michael_list_tag                ordered_list;
44             typedef HashSetHdrTest::hash_int            hash;
45             typedef HashSetHdrTest::simple_item_counter item_counter;
46             typedef cc::opt::v::relaxed_ordering        memory_model;
47             enum { dynamic_bucket_table = false };
48
49             struct ordered_list_traits: public cc::michael_list::traits
50             {
51                 typedef HashSetHdrTest::cmp<HashSetHdrTest::item>   compare;
52             };
53         };
54
55         struct RCU_GPI_less_traits: public cc::split_list::traits
56         {
57             typedef cc::michael_list_tag                ordered_list;
58             typedef HashSetHdrTest::hash_int            hash;
59             typedef HashSetHdrTest::simple_item_counter item_counter;
60             typedef cc::opt::v::sequential_consistent   memory_model;
61             enum { dynamic_bucket_table = false };
62
63             struct ordered_list_traits: public cc::michael_list::traits
64             {
65                 typedef HashSetHdrTest::less<HashSetHdrTest::item>   less;
66             };
67         };
68
69         struct RCU_cmpmix_traits: public cc::split_list::traits
70         {
71             typedef cc::michael_list_tag                ordered_list;
72             typedef HashSetHdrTest::hash_int            hash;
73             typedef HashSetHdrTest::simple_item_counter item_counter;
74
75             struct ordered_list_traits: public cc::michael_list::traits
76             {
77                 typedef HashSetHdrTest::cmp<HashSetHdrTest::item>   compare;
78                 typedef HashSetHdrTest::less<HashSetHdrTest::item>   less;
79             };
80         };
81
82         struct RCU_cmpmix_stat_traits : public RCU_cmpmix_traits
83         {
84             typedef cc::split_list::stat<> stat;
85         };
86     }
87
88     void HashSetHdrTest::Split_RCU_GPI_cmp()
89     {
90         // traits-based version
91         typedef cc::SplitListSet< rcu_type, item, RCU_GPI_cmp_traits > set;
92
93         test_int_rcu_michael_list< set >();
94
95         // option-based version
96         typedef cc::SplitListSet< rcu_type, item,
97             cc::split_list::make_traits<
98                 cc::split_list::ordered_list<cc::michael_list_tag>
99                 ,cc::opt::hash< hash_int >
100                 ,cc::opt::item_counter< simple_item_counter >
101                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
102                 ,cc::split_list::dynamic_bucket_table< true >
103                 ,cc::split_list::ordered_list_traits<
104                     cc::michael_list::make_traits<
105                         cc::opt::compare< cmp<item> >
106                     >::type
107                 >
108             >::type
109         > opt_set;
110         test_int_rcu_michael_list< opt_set >();
111     }
112
113     void HashSetHdrTest::Split_RCU_GPI_less()
114     {
115         // traits-based version
116         typedef cc::SplitListSet< rcu_type, item, RCU_GPI_less_traits > set;
117
118         test_int_rcu_michael_list< set >();
119
120         // option-based version
121         typedef cc::SplitListSet< rcu_type, item,
122             cc::split_list::make_traits<
123                 cc::split_list::ordered_list<cc::michael_list_tag>
124                 ,cc::opt::hash< hash_int >
125                 ,cc::opt::item_counter< simple_item_counter >
126                 ,cc::opt::memory_model< cc::opt::v::sequential_consistent >
127                 ,cc::split_list::dynamic_bucket_table< false >
128                 ,cc::split_list::ordered_list_traits<
129                     cc::michael_list::make_traits<
130                         cc::opt::less< less<item> >
131                     >::type
132                 >
133             >::type
134         > opt_set;
135         test_int_rcu_michael_list< opt_set >();
136     }
137
138     void HashSetHdrTest::Split_RCU_GPI_cmpmix()
139     {
140         // traits-based version
141         typedef cc::SplitListSet< rcu_type, item, RCU_cmpmix_traits > set;
142         test_int_rcu_michael_list< set >();
143
144         // option-based version
145         typedef cc::SplitListSet< rcu_type, item,
146             cc::split_list::make_traits<
147                 cc::split_list::ordered_list<cc::michael_list_tag>
148                 ,cc::opt::hash< hash_int >
149                 ,cc::opt::item_counter< simple_item_counter >
150                 ,cc::split_list::ordered_list_traits<
151                     cc::michael_list::make_traits<
152                         cc::opt::less< less<item> >
153                         ,cc::opt::compare< cmp<item> >
154                     >::type
155                 >
156             >::type
157         > opt_set;
158         test_int_rcu_michael_list< opt_set >();
159     }
160
161     void HashSetHdrTest::Split_RCU_GPI_cmpmix_stat()
162     {
163         // traits-based version
164         typedef cc::SplitListSet< rcu_type, item, RCU_cmpmix_stat_traits > set;
165         test_int_rcu_michael_list< set >();
166
167         // option-based version
168         typedef cc::SplitListSet< rcu_type, item,
169             cc::split_list::make_traits<
170                 cc::split_list::ordered_list<cc::michael_list_tag>
171                 ,cc::opt::hash< hash_int >
172                 , cc::opt::stat< cc::split_list::stat<>>
173                 ,cc::opt::item_counter< simple_item_counter >
174                 ,cc::split_list::ordered_list_traits<
175                     cc::michael_list::make_traits<
176                         cc::opt::less< less<item> >
177                         ,cc::opt::compare< cmp<item> >
178                     >::type
179                 >
180             >::type
181         > opt_set;
182         test_int_rcu_michael_list< opt_set >();
183     }
184
185 } // namespace set
186
187