fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / map / test_split_lazy_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-2017
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_LAZY_RCU_H
31 #define CDSUNIT_MAP_TEST_SPLIT_LIST_LAZY_RCU_H
32
33 #include "test_map_rcu.h"
34 #include <cds/container/lazy_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 SplitListLazyMap: 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( SplitListLazyMap );
62
63 //TYPED_TEST_P( SplitListLazyMap, compare )
64 TYPED_TEST_P( SplitListLazyMap, compare )
65 {
66     typedef typename TestFixture::rcu_type   rcu_type;
67     typedef typename TestFixture::key_type   key_type;
68     typedef typename TestFixture::value_type value_type;
69     typedef typename TestFixture::hash1      hash1;
70
71     typedef cc::SplitListMap< rcu_type, key_type, value_type,
72         typename cc::split_list::make_traits<
73             cc::split_list::ordered_list< cc::lazy_list_tag >
74             , cds::opt::hash< hash1 >
75             , cc::split_list::ordered_list_traits<
76                 typename cc::lazy_list::make_traits<
77                     cds::opt::compare< typename TestFixture::cmp >
78                 >::type
79             >
80         >::type
81     > map_type;
82
83     map_type m( TestFixture::kSize, 2 );
84     this->test( m );
85 }
86
87 TYPED_TEST_P( SplitListLazyMap, less )
88 {
89     typedef typename TestFixture::rcu_type   rcu_type;
90     typedef typename TestFixture::key_type   key_type;
91     typedef typename TestFixture::value_type value_type;
92     typedef typename TestFixture::hash1      hash1;
93
94     typedef cc::SplitListMap< rcu_type, key_type, value_type,
95         typename cc::split_list::make_traits<
96             cc::split_list::ordered_list< cc::lazy_list_tag >
97             , cds::opt::hash< hash1 >
98             , cc::split_list::ordered_list_traits<
99                 typename cc::lazy_list::make_traits<
100                     cds::opt::less< typename TestFixture::less >
101                 >::type
102             >
103         >::type
104     > map_type;
105
106     map_type m( TestFixture::kSize, 4 );
107     this->test( m );
108 }
109
110 TYPED_TEST_P( SplitListLazyMap, cmpmix )
111 {
112     typedef typename TestFixture::rcu_type   rcu_type;
113     typedef typename TestFixture::key_type   key_type;
114     typedef typename TestFixture::value_type value_type;
115     typedef typename TestFixture::hash1      hash1;
116
117     typedef cc::SplitListMap< rcu_type, key_type, value_type,
118         typename cc::split_list::make_traits<
119             cc::split_list::ordered_list< cc::lazy_list_tag >
120             , cds::opt::hash< hash1 >
121             , cc::split_list::ordered_list_traits<
122                 typename cc::lazy_list::make_traits<
123                     cds::opt::less< typename TestFixture::less >
124                     , cds::opt::compare< typename TestFixture::cmp >
125                 >::type
126             >
127         >::type
128     > map_type;
129
130     map_type m( TestFixture::kSize, 2 );
131     this->test( m );
132 }
133
134 TYPED_TEST_P( SplitListLazyMap, item_counting )
135 {
136     typedef typename TestFixture::rcu_type   rcu_type;
137     typedef typename TestFixture::key_type   key_type;
138     typedef typename TestFixture::value_type value_type;
139     typedef typename TestFixture::hash1      hash1;
140
141     struct map_traits: public cc::split_list::traits
142     {
143         typedef cc::lazy_list_tag ordered_list;
144         typedef hash1 hash;
145         typedef cds::atomicity::item_counter item_counter;
146
147         struct ordered_list_traits: public cc::lazy_list::traits
148         {
149             typedef typename TestFixture::cmp compare;
150             typedef typename TestFixture::less less;
151             typedef cds::backoff::empty back_off;
152         };
153     };
154     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
155
156     map_type m( TestFixture::kSize, 1 );
157     this->test( m );
158 }
159
160 TYPED_TEST_P( SplitListLazyMap, stat )
161 {
162     typedef typename TestFixture::rcu_type   rcu_type;
163     typedef typename TestFixture::key_type   key_type;
164     typedef typename TestFixture::value_type value_type;
165     typedef typename TestFixture::hash1      hash1;
166
167     struct map_traits: public cc::split_list::traits
168     {
169         typedef cc::lazy_list_tag ordered_list;
170         typedef hash1 hash;
171         typedef cds::atomicity::item_counter item_counter;
172         typedef cc::split_list::stat<> stat;
173
174         struct ordered_list_traits: public cc::lazy_list::traits
175         {
176             typedef typename TestFixture::less less;
177             typedef cds::opt::v::sequential_consistent memory_model;
178         };
179     };
180     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
181
182     map_type m( TestFixture::kSize, 3 );
183     this->test( m );
184 }
185
186 TYPED_TEST_P( SplitListLazyMap, back_off )
187 {
188     typedef typename TestFixture::rcu_type   rcu_type;
189     typedef typename TestFixture::key_type   key_type;
190     typedef typename TestFixture::value_type value_type;
191     typedef typename TestFixture::hash1      hash1;
192
193     struct map_traits: public cc::split_list::traits
194     {
195         typedef cc::lazy_list_tag ordered_list;
196         typedef hash1 hash;
197         typedef cds::atomicity::item_counter item_counter;
198         typedef cds::backoff::yield back_off;
199         typedef cds::opt::v::sequential_consistent memory_model;
200
201         struct ordered_list_traits: public cc::lazy_list::traits
202         {
203             typedef typename TestFixture::cmp compare;
204             typedef cds::backoff::pause back_off;
205         };
206     };
207     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
208
209     map_type m( TestFixture::kSize, 2 );
210     this->test( m );
211 }
212
213 TYPED_TEST_P( SplitListLazyMap, free_list )
214 {
215     typedef typename TestFixture::rcu_type   rcu_type;
216     typedef typename TestFixture::key_type   key_type;
217     typedef typename TestFixture::value_type value_type;
218     typedef typename TestFixture::hash1      hash1;
219
220     struct map_traits: public cc::split_list::traits
221     {
222         typedef cc::lazy_list_tag ordered_list;
223         typedef hash1 hash;
224         typedef cds::intrusive::FreeList free_list;
225
226         struct ordered_list_traits: public cc::lazy_list::traits
227         {
228             typedef typename TestFixture::cmp compare;
229             typedef cds::backoff::pause back_off;
230         };
231     };
232     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
233
234     map_type m( TestFixture::kSize, 2 );
235     this->test( m );
236 }
237
238 TYPED_TEST_P( SplitListLazyMap, mutex )
239 {
240     typedef typename TestFixture::rcu_type   rcu_type;
241     typedef typename TestFixture::key_type   key_type;
242     typedef typename TestFixture::value_type value_type;
243     typedef typename TestFixture::hash1      hash1;
244
245     struct map_traits: public cc::split_list::traits
246     {
247         typedef cc::lazy_list_tag ordered_list;
248         typedef hash1 hash;
249         typedef cds::atomicity::item_counter item_counter;
250         typedef cds::backoff::yield back_off;
251         typedef cds::opt::v::sequential_consistent memory_model;
252
253         struct ordered_list_traits: public cc::lazy_list::traits
254         {
255             typedef typename TestFixture::cmp compare;
256             typedef cds::backoff::pause back_off;
257             typedef std::mutex lock_type;
258         };
259     };
260     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
261
262     map_type m( TestFixture::kSize, 2 );
263     this->test( m );
264 }
265
266 namespace {
267     struct set_static_traits: public cc::split_list::traits
268     {
269         static bool const dynamic_bucket_table = false;
270     };
271 }
272
273 TYPED_TEST_P( SplitListLazyMap, static_bucket_table )
274 {
275     typedef typename TestFixture::rcu_type   rcu_type;
276     typedef typename TestFixture::key_type   key_type;
277     typedef typename TestFixture::value_type value_type;
278     typedef typename TestFixture::hash1      hash1;
279
280     struct map_traits: public set_static_traits
281     {
282         typedef cc::lazy_list_tag ordered_list;
283         typedef hash1 hash;
284         typedef cds::atomicity::item_counter item_counter;
285
286         struct ordered_list_traits: public cc::lazy_list::traits
287         {
288             typedef typename TestFixture::cmp compare;
289             typedef cds::backoff::pause back_off;
290         };
291     };
292     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
293
294     map_type m( TestFixture::kSize, 4 );
295     this->test( m );
296 }
297
298 TYPED_TEST_P( SplitListLazyMap, static_bucket_table_free_list )
299 {
300     typedef typename TestFixture::rcu_type   rcu_type;
301     typedef typename TestFixture::key_type   key_type;
302     typedef typename TestFixture::value_type value_type;
303     typedef typename TestFixture::hash1      hash1;
304
305     struct map_traits: public set_static_traits
306     {
307         typedef cc::lazy_list_tag ordered_list;
308         typedef hash1 hash;
309         typedef cds::atomicity::item_counter item_counter;
310         typedef cds::intrusive::FreeList free_list;
311
312         struct ordered_list_traits: public cc::lazy_list::traits
313         {
314             typedef typename TestFixture::cmp compare;
315             typedef cds::backoff::pause back_off;
316         };
317     };
318     typedef cc::SplitListMap< rcu_type, key_type, value_type, map_traits > map_type;
319
320     map_type m( TestFixture::kSize, 4 );
321     this->test( m );
322 }
323
324 REGISTER_TYPED_TEST_CASE_P( SplitListLazyMap,
325     compare, less, cmpmix, item_counting, stat, back_off, mutex, free_list, static_bucket_table, static_bucket_table_free_list
326 );
327
328
329 #endif // CDSUNIT_MAP_TEST_SPLIT_LIST_LAZY_RCU_H
330