Improved management of SkipList auxiliary nodes: now aux nodes are allocated from...
[libcds.git] / test / unit / map / test_split_michael_rcu.h
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 #ifndef CDSUNIT_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
31 #define CDSUNIT_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
32
33 #include "test_map_rcu.h"
34 #include <cds/container/michael_list_rcu.h>
35 #include <cds/container/split_list_map_rcu.h>
36 #include <cds/intrusive/free_list.h>
37
38 namespace cc = cds::container;
39
40 template <class RCU>
41 class SplitListMichaelMap: public cds_test::container_map_rcu
42 {
43     typedef cds_test::container_map_rcu base_class;
44 public:
45     typedef cds::urcu::gc<RCU> rcu_type;
46
47 protected:
48     void SetUp()
49     {
50         RCU::Construct();
51         cds::threading::Manager::attachThread();
52     }
53
54     void TearDown()
55     {
56         cds::threading::Manager::detachThread();
57         RCU::Destruct();
58     }
59 };
60
61 TYPED_TEST_CASE_P( SplitListMichaelMap );
62
63 TYPED_TEST_P( SplitListMichaelMap, compare )
64 {
65     typedef typename TestFixture::rcu_type   rcu_type;
66     typedef typename TestFixture::key_type   key_type;
67     typedef typename TestFixture::value_type value_type;
68     typedef typename TestFixture::hash1      hash1;
69
70     typedef cc::SplitListMap< rcu_type, key_type, value_type, 
71         typename cc::split_list::make_traits<
72             cc::split_list::ordered_list< cc::michael_list_tag >
73             , cds::opt::hash< hash1 >
74             , cc::split_list::ordered_list_traits< 
75                 typename cc::michael_list::make_traits<
76                     cds::opt::compare< typename TestFixture::cmp >
77                 >::type
78             >
79         >::type
80     > map_type;
81
82     map_type m( TestFixture::kSize, 2 );
83     this->test( m );
84 }
85
86 TYPED_TEST_P( SplitListMichaelMap, less )
87 {
88     typedef typename TestFixture::rcu_type   rcu_type;
89     typedef typename TestFixture::key_type   key_type;
90     typedef typename TestFixture::value_type value_type;
91     typedef typename TestFixture::hash1      hash1;
92
93     typedef cc::SplitListMap< rcu_type, key_type, value_type,
94         typename cc::split_list::make_traits<
95             cc::split_list::ordered_list< cc::michael_list_tag >
96             , cds::opt::hash< hash1 >
97             , cc::split_list::ordered_list_traits< 
98                 typename cc::michael_list::make_traits<
99                     cds::opt::less< typename TestFixture::less >
100                 >::type
101             >
102         >::type
103     > map_type;
104
105     map_type m( TestFixture::kSize, 2 );
106     this->test( m );
107 }
108
109 TYPED_TEST_P( SplitListMichaelMap, cmpmix )
110 {
111     typedef typename TestFixture::rcu_type   rcu_type;
112     typedef typename TestFixture::key_type   key_type;
113     typedef typename TestFixture::value_type value_type;
114     typedef typename TestFixture::hash1      hash1;
115
116     typedef cc::SplitListMap< rcu_type, key_type, value_type,
117         typename cc::split_list::make_traits<
118             cc::split_list::ordered_list< cc::michael_list_tag >
119             , cds::opt::hash< hash1 >
120             , cc::split_list::ordered_list_traits< 
121                 typename cc::michael_list::make_traits<
122                     cds::opt::less< typename TestFixture::less >
123                     , cds::opt::compare< typename TestFixture::cmp >
124                 >::type
125             >
126         >::type
127     > map_type;
128
129     map_type m( TestFixture::kSize, 3 );
130     this->test( m );
131 }
132
133 TYPED_TEST_P( SplitListMichaelMap, item_counting )
134 {
135     typedef typename TestFixture::rcu_type   rcu_type;
136     typedef typename TestFixture::key_type   key_type;
137     typedef typename TestFixture::value_type value_type;
138     typedef typename TestFixture::hash1      hash1;
139
140     struct map_traits: public cc::split_list::traits
141     {
142         typedef cc::michael_list_tag ordered_list;
143         typedef hash1 hash;
144         typedef cds::atomicity::item_counter item_counter;
145
146         struct ordered_list_traits: public cc::michael_list::traits
147         {
148             typedef typename TestFixture::cmp compare;
149             typedef typename TestFixture::less less;
150             typedef cds::backoff::empty back_off;
151         };
152     };
153     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
154
155     map_type m( TestFixture::kSize, 8 );
156     this->test( m );
157 }
158
159 TYPED_TEST_P( SplitListMichaelMap, stat )
160 {
161     typedef typename TestFixture::rcu_type   rcu_type;
162     typedef typename TestFixture::key_type   key_type;
163     typedef typename TestFixture::value_type value_type;
164     typedef typename TestFixture::hash1      hash1;
165
166     struct map_traits: public cc::split_list::traits
167     {
168         typedef cc::michael_list_tag ordered_list;
169         typedef hash1 hash;
170         typedef cds::atomicity::item_counter item_counter;
171         typedef cc::split_list::stat<> stat;
172
173         struct ordered_list_traits: public cc::michael_list::traits
174         {
175             typedef typename TestFixture::less less;
176             typedef cds::opt::v::sequential_consistent memory_model;
177         };
178     };
179     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
180
181     map_type m( TestFixture::kSize, 4 );
182     this->test( m );
183 }
184
185 TYPED_TEST_P( SplitListMichaelMap, back_off )
186 {
187     typedef typename TestFixture::rcu_type   rcu_type;
188     typedef typename TestFixture::key_type   key_type;
189     typedef typename TestFixture::value_type value_type;
190     typedef typename TestFixture::hash1      hash1;
191
192     struct map_traits: public cc::split_list::traits
193     {
194         typedef cc::michael_list_tag ordered_list;
195         typedef hash1 hash;
196         typedef cds::atomicity::item_counter item_counter;
197         typedef cds::backoff::yield back_off;
198         typedef cds::opt::v::sequential_consistent memory_model;
199
200         struct ordered_list_traits: public cc::michael_list::traits
201         {
202             typedef typename TestFixture::cmp compare;
203             typedef cds::backoff::pause back_off;
204         };
205     };
206     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
207
208     map_type m( TestFixture::kSize, 2 );
209     this->test( m );
210 }
211
212 TYPED_TEST_P( SplitListMichaelMap, free_list )
213 {
214     typedef typename TestFixture::rcu_type   rcu_type;
215     typedef typename TestFixture::key_type   key_type;
216     typedef typename TestFixture::value_type value_type;
217     typedef typename TestFixture::hash1      hash1;
218
219     struct map_traits: public cc::split_list::traits
220     {
221         typedef cc::michael_list_tag ordered_list;
222         typedef hash1 hash;
223         typedef cds::intrusive::FreeList free_list;
224
225         struct ordered_list_traits: public cc::michael_list::traits
226         {
227             typedef typename TestFixture::cmp compare;
228             typedef cds::backoff::pause back_off;
229         };
230     };
231     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
232
233     map_type m( TestFixture::kSize, 2 );
234     this->test( m );
235 }
236
237 namespace {
238     struct set_static_traits: public cc::split_list::traits
239     {
240         static bool const dynamic_bucket_table = false;
241     };
242 }
243
244 TYPED_TEST_P( SplitListMichaelMap, static_bucket_table )
245 {
246     typedef typename TestFixture::rcu_type   rcu_type;
247     typedef typename TestFixture::key_type   key_type;
248     typedef typename TestFixture::value_type value_type;
249     typedef typename TestFixture::hash1      hash1;
250
251     struct map_traits: public set_static_traits
252     {
253         typedef cc::michael_list_tag ordered_list;
254         typedef hash1 hash;
255         typedef cds::atomicity::item_counter item_counter;
256
257         struct ordered_list_traits: public cc::michael_list::traits
258         {
259             typedef typename TestFixture::cmp compare;
260             typedef cds::backoff::pause back_off;
261         };
262     };
263     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
264
265     map_type m( TestFixture::kSize, 4 );
266     this->test( m );
267 }
268
269 TYPED_TEST_P( SplitListMichaelMap, static_bucket_table_free_list )
270 {
271     typedef typename TestFixture::rcu_type   rcu_type;
272     typedef typename TestFixture::key_type   key_type;
273     typedef typename TestFixture::value_type value_type;
274     typedef typename TestFixture::hash1      hash1;
275
276     struct map_traits: public set_static_traits
277     {
278         typedef cc::michael_list_tag ordered_list;
279         typedef hash1 hash;
280         typedef cds::atomicity::item_counter item_counter;
281         typedef cds::intrusive::FreeList free_list;
282
283         struct ordered_list_traits: public cc::michael_list::traits
284         {
285             typedef typename TestFixture::cmp compare;
286             typedef cds::backoff::pause back_off;
287         };
288     };
289     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
290
291     map_type m( TestFixture::kSize, 4 );
292     this->test( m );
293 }
294
295 REGISTER_TYPED_TEST_CASE_P( SplitListMichaelMap,
296     compare, less, cmpmix, item_counting, stat, back_off, free_list, static_bucket_table, static_bucket_table_free_list
297 );
298
299
300 #endif // CDSUNIT_MAP_TEST_SPLIT_LIST_MICHAEL_RCU_H
301