2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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/michael_list_hp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
38 namespace ci = cds::intrusive;
39 typedef cds::gc::HP gc_type;
41 class IntrusiveSplitListSet_HP : public cds_test::intrusive_set_hp
44 typedef cds_test::intrusive_set_hp base_class;
47 typedef typename base_class::base_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> base_item_type;
48 typedef typename base_class::member_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> member_item_type;
52 struct list_traits : public ci::michael_list::traits
54 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
56 typedef ci::MichaelList< gc_type, base_item_type, list_traits > list_type;
57 typedef ci::SplitListSet< gc_type, list_type > set_type;
59 // +1 - for guarded_ptr
60 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
61 cds::threading::Manager::attachThread();
66 cds::threading::Manager::detachThread();
67 cds::gc::hp::GarbageCollector::Destruct( true );
72 TEST_F( IntrusiveSplitListSet_HP, base_cmp )
74 typedef ci::MichaelList< gc_type
76 ,ci::michael_list::make_traits<
77 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
78 ,ci::opt::compare< cmp<base_item_type> >
79 ,ci::opt::disposer< mock_disposer >
83 typedef ci::SplitListSet< gc_type, bucket_type,
84 ci::split_list::make_traits<
85 ci::opt::hash< hash_int >
89 set_type s( kSize, 2 );
93 TEST_F( IntrusiveSplitListSet_HP, base_less )
95 typedef ci::MichaelList< gc_type
97 ,ci::michael_list::make_traits<
98 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
99 ,ci::opt::less< less<base_item_type> >
100 ,ci::opt::disposer< mock_disposer >
104 typedef ci::SplitListSet< gc_type, bucket_type,
105 ci::split_list::make_traits<
106 ci::opt::hash< hash_int >
107 ,ci::opt::item_counter< cds::atomicity::item_counter >
111 set_type s( kSize, 2 );
115 TEST_F( IntrusiveSplitListSet_HP, base_cmpmix )
117 struct list_traits : public ci::michael_list::traits
119 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
120 typedef base_class::less<base_item_type> less;
121 typedef cmp<base_item_type> compare;
122 typedef mock_disposer disposer;
124 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
126 struct set_traits : public ci::split_list::traits
128 typedef hash_int hash;
129 typedef simple_item_counter item_counter;
130 typedef ci::split_list::stat<> stat;
132 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
134 set_type s( kSize, 2 );
138 TEST_F( IntrusiveSplitListSet_HP, base_static_bucket_table )
140 struct list_traits: public ci::michael_list::traits
142 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
143 typedef base_class::less<base_item_type> less;
144 typedef cmp<base_item_type> compare;
145 typedef mock_disposer disposer;
147 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
149 struct set_traits: public ci::split_list::traits
151 typedef hash_int hash;
152 typedef simple_item_counter item_counter;
153 typedef ci::split_list::stat<> stat;
155 dynamic_bucket_table = false
158 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
160 set_type s( kSize, 2 );
164 TEST_F( IntrusiveSplitListSet_HP, base_static_bucket_table_free_list )
166 struct list_traits: public ci::michael_list::traits
168 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
169 typedef base_class::less<base_item_type> less;
170 typedef mock_disposer disposer;
172 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
174 struct set_traits: public ci::split_list::traits
176 typedef hash_int hash;
177 typedef simple_item_counter item_counter;
178 typedef ci::split_list::stat<> stat;
180 dynamic_bucket_table = false
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( IntrusiveSplitListSet_HP, base_free_list )
192 struct list_traits: public ci::michael_list::traits
194 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
195 typedef cmp<base_item_type> compare;
196 typedef mock_disposer disposer;
198 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
200 struct set_traits: public ci::split_list::traits
202 typedef hash_int hash;
203 typedef simple_item_counter item_counter;
204 typedef ci::split_list::stat<> stat;
205 typedef ci::FreeList free_list;
207 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
209 set_type s( kSize, 2 );
213 TEST_F( IntrusiveSplitListSet_HP, base_bit_reversal_swar )
215 struct list_traits: public ci::michael_list::traits
217 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
218 typedef cmp<base_item_type> compare;
219 typedef mock_disposer disposer;
221 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
223 struct set_traits: public ci::split_list::traits
225 typedef hash_int hash;
226 typedef simple_item_counter item_counter;
227 typedef ci::split_list::stat<> stat;
228 typedef cds::algo::bit_reversal::swar bit_reversal;
230 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
232 set_type s( kSize, 2 );
236 TEST_F( IntrusiveSplitListSet_HP, base_bit_reversal_lookup )
238 struct list_traits: public ci::michael_list::traits
240 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
241 typedef cmp<base_item_type> compare;
242 typedef mock_disposer disposer;
244 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
246 struct set_traits: public ci::split_list::traits
248 typedef hash_int hash;
249 typedef simple_item_counter item_counter;
250 typedef ci::split_list::stat<> stat;
251 typedef cds::algo::bit_reversal::lookup bit_reversal;
253 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
255 set_type s( kSize, 2 );
259 TEST_F( IntrusiveSplitListSet_HP, base_bit_reversal_muldiv )
261 struct list_traits: public ci::michael_list::traits
263 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
264 typedef cmp<base_item_type> compare;
265 typedef mock_disposer disposer;
267 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
269 struct set_traits: public ci::split_list::traits
271 typedef hash_int hash;
272 typedef simple_item_counter item_counter;
273 typedef ci::split_list::stat<> stat;
274 typedef cds::algo::bit_reversal::muldiv bit_reversal;
276 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
278 set_type s( kSize, 2 );
282 TEST_F( IntrusiveSplitListSet_HP, member_cmp )
284 typedef ci::MichaelList< gc_type
286 ,ci::michael_list::make_traits<
287 ci::opt::hook< ci::michael_list::member_hook<
288 offsetof( member_item_type, hMember ),
291 ,ci::opt::compare< cmp<member_item_type> >
292 ,ci::opt::disposer< mock_disposer >
296 typedef ci::SplitListSet< gc_type, bucket_type,
297 ci::split_list::make_traits<
298 ci::opt::hash< hash_int >
302 set_type s( kSize, 2 );
306 TEST_F( IntrusiveSplitListSet_HP, member_less )
308 typedef ci::MichaelList< gc_type
310 ,ci::michael_list::make_traits<
311 ci::opt::hook< ci::michael_list::member_hook<
312 offsetof( member_item_type, hMember ),
315 ,ci::opt::less< less<member_item_type> >
316 ,ci::opt::disposer< mock_disposer >
320 typedef ci::SplitListSet< gc_type, bucket_type,
321 ci::split_list::make_traits<
322 ci::opt::hash< hash_int >
323 ,ci::opt::back_off< cds::backoff::pause >
327 set_type s( kSize, 2 );
331 TEST_F( IntrusiveSplitListSet_HP, member_cmpmix )
333 struct list_traits : public ci::michael_list::traits
335 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
336 typedef base_class::less<member_item_type> less;
337 typedef cmp<member_item_type> compare;
338 typedef mock_disposer disposer;
340 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
342 struct set_traits : public ci::split_list::traits
344 typedef hash_int hash;
345 typedef simple_item_counter item_counter;
347 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
349 set_type s( kSize, 2 );
353 TEST_F( IntrusiveSplitListSet_HP, member_static_bucket_table )
355 struct list_traits: public ci::michael_list::traits
357 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
358 typedef base_class::less<member_item_type> less;
359 typedef cmp<member_item_type> compare;
360 typedef mock_disposer disposer;
362 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
364 struct set_traits: public ci::split_list::traits
366 typedef hash_int hash;
367 typedef simple_item_counter item_counter;
369 dynamic_bucket_table = false
372 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
374 set_type s( kSize, 2 );
378 TEST_F( IntrusiveSplitListSet_HP, member_static_bucket_table_free_list )
380 struct list_traits: public ci::michael_list::traits
382 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
383 typedef cmp<member_item_type> compare;
384 typedef mock_disposer disposer;
386 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
388 struct set_traits: public ci::split_list::traits
390 typedef hash_int hash;
391 typedef simple_item_counter item_counter;
393 dynamic_bucket_table = false
395 typedef ci::FreeList free_list;
397 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
399 set_type s( kSize, 2 );
403 TEST_F( IntrusiveSplitListSet_HP, member_free_list )
405 struct list_traits: public ci::michael_list::traits
407 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
408 typedef base_class::less<member_item_type> less;
409 typedef mock_disposer disposer;
411 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
413 struct set_traits: public ci::split_list::traits
415 typedef hash_int hash;
416 typedef simple_item_counter item_counter;
417 typedef ci::FreeList free_list;
419 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
421 set_type s( kSize, 2 );