2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #include "test_intrusive_set_hp.h"
33 #include <cds/intrusive/lazy_list_hp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
40 namespace ci = cds::intrusive;
41 typedef cds::gc::HP gc_type;
43 class IntrusiveSplitListLazySet_HP : public cds_test::intrusive_set_hp
46 typedef cds_test::intrusive_set_hp base_class;
49 typedef typename base_class::base_int_item< ci::split_list::node< ci::lazy_list::node<gc_type>>> base_item_type;
50 typedef typename base_class::base_int_item< ci::split_list::node< ci::lazy_list::node<gc_type, std::mutex >>> base_mutex_item_type;
51 typedef typename base_class::member_int_item< ci::split_list::node< ci::lazy_list::node<gc_type>>> member_item_type;
52 typedef typename base_class::member_int_item< ci::split_list::node< ci::lazy_list::node<gc_type, std::mutex>>> member_mutex_item_type;
56 struct list_traits : public ci::lazy_list::traits
58 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
60 typedef ci::LazyList< gc_type, base_item_type, list_traits > list_type;
61 typedef ci::SplitListSet< gc_type, list_type > set_type;
63 // +1 - for guarded_ptr
64 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
65 cds::threading::Manager::attachThread();
70 cds::threading::Manager::detachThread();
71 cds::gc::hp::GarbageCollector::Destruct( true );
76 TEST_F( IntrusiveSplitListLazySet_HP, base_cmp )
78 typedef ci::LazyList< gc_type
80 ,ci::lazy_list::make_traits<
81 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
82 ,ci::opt::compare< cmp<base_item_type> >
83 ,ci::opt::disposer< mock_disposer >
84 ,ci::opt::back_off< cds::backoff::pause >
88 typedef ci::SplitListSet< gc_type, bucket_type,
89 ci::split_list::make_traits<
90 ci::opt::hash< hash_int >
94 set_type s( kSize, 2 );
98 TEST_F( IntrusiveSplitListLazySet_HP, base_less )
100 typedef ci::LazyList< gc_type
102 ,ci::lazy_list::make_traits<
103 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
104 ,ci::opt::less< less<base_item_type> >
105 ,ci::opt::disposer< mock_disposer >
109 typedef ci::SplitListSet< gc_type, bucket_type,
110 ci::split_list::make_traits<
111 ci::opt::hash< hash_int >
112 , ci::opt::item_counter< cds::atomicity::item_counter >
116 set_type s( kSize, 2 );
120 TEST_F( IntrusiveSplitListLazySet_HP, base_cmpmix )
122 struct list_traits : public ci::lazy_list::traits
124 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
125 typedef base_class::less<base_item_type> less;
126 typedef cmp<base_item_type> compare;
127 typedef mock_disposer disposer;
129 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
131 struct set_traits : public ci::split_list::traits
133 typedef hash_int hash;
134 typedef simple_item_counter item_counter;
135 typedef ci::split_list::stat<> stat;
137 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
139 set_type s( kSize, 2 );
143 TEST_F( IntrusiveSplitListLazySet_HP, base_mutex )
145 struct list_traits : public ci::lazy_list::traits
147 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
148 typedef base_class::less<base_mutex_item_type> less;
149 typedef cmp<base_mutex_item_type> compare;
150 typedef mock_disposer disposer;
152 typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
154 struct set_traits : public ci::split_list::traits
156 typedef hash_int hash;
157 typedef simple_item_counter item_counter;
158 typedef cds::backoff::empty back_off;
160 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
162 set_type s( kSize, 2 );
166 TEST_F( IntrusiveSplitListLazySet_HP, base_free_list )
168 struct list_traits: public ci::lazy_list::traits
170 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
171 typedef base_class::less<base_item_type> less;
172 typedef cmp<base_item_type> compare;
173 typedef mock_disposer disposer;
175 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
177 struct set_traits: public ci::split_list::traits
179 typedef hash_int hash;
180 typedef simple_item_counter item_counter;
181 typedef ci::split_list::stat<> stat;
182 typedef ci::FreeList free_list;
184 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
186 set_type s( kSize, 2 );
190 TEST_F( IntrusiveSplitListLazySet_HP, base_static_bucket_table )
192 struct list_traits: public ci::lazy_list::traits
194 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
195 typedef base_class::less<base_item_type> less;
196 typedef cmp<base_item_type> compare;
197 typedef mock_disposer disposer;
199 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
201 struct set_traits: public ci::split_list::traits
203 typedef hash_int hash;
204 typedef simple_item_counter item_counter;
205 typedef cds::backoff::empty back_off;
207 dynamic_bucket_table = false
210 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
212 set_type s( kSize, 2 );
216 TEST_F( IntrusiveSplitListLazySet_HP, base_static_bucket_table_free_list )
218 struct list_traits: public ci::lazy_list::traits
220 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
221 typedef base_class::less<base_item_type> less;
222 typedef cmp<base_item_type> compare;
223 typedef mock_disposer disposer;
225 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
227 struct set_traits: public ci::split_list::traits
229 typedef hash_int hash;
230 typedef simple_item_counter item_counter;
231 typedef cds::backoff::empty back_off;
233 dynamic_bucket_table = false
235 typedef ci::FreeList free_list;
237 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
239 set_type s( kSize, 2 );
244 TEST_F( IntrusiveSplitListLazySet_HP, member_cmp )
246 typedef ci::LazyList< gc_type
248 ,ci::lazy_list::make_traits<
249 ci::opt::hook< ci::lazy_list::member_hook<
250 offsetof( member_item_type, hMember ),
253 ,ci::opt::compare< cmp<member_item_type> >
254 ,ci::opt::disposer< mock_disposer >
258 typedef ci::SplitListSet< gc_type, bucket_type,
259 ci::split_list::make_traits<
260 ci::opt::hash< hash_int >
264 set_type s( kSize, 2 );
268 TEST_F( IntrusiveSplitListLazySet_HP, member_less )
270 typedef ci::LazyList< gc_type
272 ,ci::lazy_list::make_traits<
273 ci::opt::hook< ci::lazy_list::member_hook<
274 offsetof( member_item_type, hMember ),
277 ,ci::opt::less< less<member_item_type> >
278 ,ci::opt::disposer< mock_disposer >
282 typedef ci::SplitListSet< gc_type, bucket_type,
283 ci::split_list::make_traits<
284 ci::opt::hash< hash_int >
285 , ci::opt::back_off< cds::backoff::pause >
289 set_type s( kSize, 2 );
293 TEST_F( IntrusiveSplitListLazySet_HP, member_cmpmix )
295 struct list_traits : public ci::lazy_list::traits
297 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
298 typedef base_class::less<member_item_type> less;
299 typedef cmp<member_item_type> compare;
300 typedef mock_disposer disposer;
302 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
304 struct set_traits : public ci::split_list::traits
306 typedef hash_int hash;
307 typedef simple_item_counter item_counter;
309 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
311 set_type s( kSize, 2 );
315 TEST_F( IntrusiveSplitListLazySet_HP, member_mutex )
317 struct list_traits : public ci::lazy_list::traits
319 typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
320 typedef base_class::less<member_mutex_item_type> less;
321 typedef cmp<member_mutex_item_type> compare;
322 typedef mock_disposer disposer;
324 typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
326 struct set_traits : public ci::split_list::traits
328 typedef hash_int hash;
329 typedef simple_item_counter item_counter;
331 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
333 set_type s( kSize, 2 );
337 TEST_F( IntrusiveSplitListLazySet_HP, member_free_list )
339 struct list_traits: public ci::lazy_list::traits
341 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
342 typedef base_class::less<member_item_type> less;
343 typedef cmp<member_item_type> compare;
344 typedef mock_disposer disposer;
346 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
348 struct set_traits: public ci::split_list::traits
350 typedef hash_int hash;
351 typedef simple_item_counter item_counter;
352 typedef ci::FreeList free_list;
354 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
356 set_type s( kSize, 2 );
360 TEST_F( IntrusiveSplitListLazySet_HP, member_static_bucket_table )
362 struct list_traits: public ci::lazy_list::traits
364 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
365 typedef base_class::less<member_item_type> less;
366 typedef cmp<member_item_type> compare;
367 typedef mock_disposer disposer;
369 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
371 struct set_traits: public ci::split_list::traits
373 typedef hash_int hash;
374 typedef simple_item_counter item_counter;
376 dynamic_bucket_table = false
379 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
381 set_type s( kSize, 2 );
385 TEST_F( IntrusiveSplitListLazySet_HP, member_static_bucket_table_free_list )
387 struct list_traits: public ci::lazy_list::traits
389 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
390 typedef base_class::less<member_item_type> less;
391 typedef cmp<member_item_type> compare;
392 typedef mock_disposer disposer;
394 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
396 struct set_traits: public ci::split_list::traits
398 typedef hash_int hash;
399 typedef simple_item_counter item_counter;
401 dynamic_bucket_table = false
403 typedef ci::FreeList free_list;
405 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
407 set_type s( kSize, 2 );