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/lazy_list_dhp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
40 namespace ci = cds::intrusive;
41 typedef cds::gc::DHP gc_type;
43 class IntrusiveSplitListLazySet_DHP : 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 cds::gc::dhp::smr::construct( set_type::c_nHazardPtrCount );
64 cds::threading::Manager::attachThread();
69 cds::threading::Manager::detachThread();
70 cds::gc::dhp::smr::destruct();
75 TEST_F( IntrusiveSplitListLazySet_DHP, base_cmp )
77 typedef ci::LazyList< gc_type
79 ,ci::lazy_list::make_traits<
80 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
81 ,ci::opt::compare< cmp<base_item_type> >
82 ,ci::opt::disposer< mock_disposer >
83 ,ci::opt::back_off< cds::backoff::pause >
87 typedef ci::SplitListSet< gc_type, bucket_type,
88 ci::split_list::make_traits<
89 ci::opt::hash< hash_int >
93 set_type s( kSize, 2 );
97 TEST_F( IntrusiveSplitListLazySet_DHP, base_less )
99 typedef ci::LazyList< gc_type
101 ,ci::lazy_list::make_traits<
102 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
103 ,ci::opt::less< less<base_item_type> >
104 ,ci::opt::disposer< mock_disposer >
108 typedef ci::SplitListSet< gc_type, bucket_type,
109 ci::split_list::make_traits<
110 ci::opt::hash< hash_int >
111 , ci::opt::item_counter< cds::atomicity::item_counter >
115 set_type s( kSize, 2 );
119 TEST_F( IntrusiveSplitListLazySet_DHP, base_cmpmix )
121 struct list_traits : public ci::lazy_list::traits
123 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
124 typedef base_class::less<base_item_type> less;
125 typedef cmp<base_item_type> compare;
126 typedef mock_disposer disposer;
128 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
130 struct set_traits : public ci::split_list::traits
132 typedef hash_int hash;
133 typedef simple_item_counter item_counter;
134 typedef ci::split_list::stat<> stat;
136 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
138 set_type s( kSize, 2 );
142 TEST_F( IntrusiveSplitListLazySet_DHP, base_mutex )
144 struct list_traits : public ci::lazy_list::traits
146 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
147 typedef base_class::less<base_mutex_item_type> less;
148 typedef cmp<base_mutex_item_type> compare;
149 typedef mock_disposer disposer;
151 typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
153 struct set_traits : public ci::split_list::traits
155 typedef hash_int hash;
156 typedef simple_item_counter item_counter;
157 typedef cds::backoff::empty back_off;
159 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
161 set_type s( kSize, 2 );
165 TEST_F( IntrusiveSplitListLazySet_DHP, base_static_bucket_table )
167 typedef ci::LazyList< gc_type
169 ,ci::lazy_list::make_traits<
170 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
171 ,ci::opt::less< less<base_item_type> >
172 ,ci::opt::disposer< mock_disposer >
176 typedef ci::SplitListSet< gc_type, bucket_type,
177 ci::split_list::make_traits<
178 ci::opt::hash< hash_int >
179 , ci::opt::item_counter< cds::atomicity::item_counter >
180 , ci::split_list::dynamic_bucket_table< false >
184 set_type s( kSize, 2 );
188 TEST_F( IntrusiveSplitListLazySet_DHP, base_free_list )
190 typedef ci::LazyList< gc_type
192 ,ci::lazy_list::make_traits<
193 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
194 ,ci::opt::less< less<base_item_type> >
195 ,ci::opt::disposer< mock_disposer >
199 typedef ci::SplitListSet< gc_type, bucket_type,
200 ci::split_list::make_traits<
201 ci::opt::hash< hash_int >
202 , ci::opt::item_counter< cds::atomicity::item_counter >
203 , ci::opt::free_list< ci::FreeList >
207 set_type s( kSize, 2 );
211 TEST_F( IntrusiveSplitListLazySet_DHP, base_static_bucket_table_free_list )
213 typedef ci::LazyList< gc_type
215 ,ci::lazy_list::make_traits<
216 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
217 ,ci::opt::less< less<base_item_type> >
218 ,ci::opt::disposer< mock_disposer >
222 typedef ci::SplitListSet< gc_type, bucket_type,
223 ci::split_list::make_traits<
224 ci::opt::hash< hash_int >
225 , ci::opt::item_counter< cds::atomicity::item_counter >
226 , ci::split_list::dynamic_bucket_table< false >
227 , ci::opt::free_list< ci::FreeList >
231 set_type s( kSize, 2 );
236 TEST_F( IntrusiveSplitListLazySet_DHP, member_cmp )
238 typedef ci::LazyList< gc_type
240 ,ci::lazy_list::make_traits<
241 ci::opt::hook< ci::lazy_list::member_hook<
242 offsetof( member_item_type, hMember ),
245 ,ci::opt::compare< cmp<member_item_type> >
246 ,ci::opt::disposer< mock_disposer >
250 typedef ci::SplitListSet< gc_type, bucket_type,
251 ci::split_list::make_traits<
252 ci::opt::hash< hash_int >
256 set_type s( kSize, 2 );
260 TEST_F( IntrusiveSplitListLazySet_DHP, member_less )
262 typedef ci::LazyList< gc_type
264 ,ci::lazy_list::make_traits<
265 ci::opt::hook< ci::lazy_list::member_hook<
266 offsetof( member_item_type, hMember ),
269 ,ci::opt::less< less<member_item_type> >
270 ,ci::opt::disposer< mock_disposer >
274 typedef ci::SplitListSet< gc_type, bucket_type,
275 ci::split_list::make_traits<
276 ci::opt::hash< hash_int >
277 , ci::opt::back_off< cds::backoff::pause >
281 set_type s( kSize, 2 );
285 TEST_F( IntrusiveSplitListLazySet_DHP, member_cmpmix )
287 struct list_traits : public ci::lazy_list::traits
289 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
290 typedef base_class::less<member_item_type> less;
291 typedef cmp<member_item_type> compare;
292 typedef mock_disposer disposer;
294 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
296 struct set_traits : public ci::split_list::traits
298 typedef hash_int hash;
299 typedef simple_item_counter item_counter;
301 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
303 set_type s( kSize, 2 );
307 TEST_F( IntrusiveSplitListLazySet_DHP, member_mutex )
309 struct list_traits : public ci::lazy_list::traits
311 typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
312 typedef base_class::less<member_mutex_item_type> less;
313 typedef cmp<member_mutex_item_type> compare;
314 typedef mock_disposer disposer;
316 typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
318 struct set_traits : public ci::split_list::traits
320 typedef hash_int hash;
321 typedef simple_item_counter item_counter;
323 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
325 set_type s( kSize, 2 );
329 TEST_F( IntrusiveSplitListLazySet_DHP, member_static_bucket_table )
331 struct list_traits: public ci::lazy_list::traits
333 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
334 typedef cmp<member_item_type> compare;
335 typedef mock_disposer disposer;
337 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
339 struct set_traits: public ci::split_list::traits
341 typedef hash_int hash;
342 typedef simple_item_counter item_counter;
344 dynamic_bucket_table = false
347 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
349 set_type s( kSize, 2 );
353 TEST_F( IntrusiveSplitListLazySet_DHP, member_free_list )
355 struct list_traits: public ci::lazy_list::traits
357 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
358 typedef cmp<member_item_type> compare;
359 typedef mock_disposer disposer;
361 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
363 struct set_traits: public ci::split_list::traits
365 typedef hash_int hash;
366 typedef simple_item_counter item_counter;
367 typedef ci::FreeList free_list;
369 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
371 set_type s( kSize, 2 );
375 TEST_F( IntrusiveSplitListLazySet_DHP, member_static_bucket_table_free_list )
377 struct list_traits: public ci::lazy_list::traits
379 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
380 typedef cmp<member_item_type> compare;
381 typedef mock_disposer disposer;
383 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
385 struct set_traits: public ci::split_list::traits
387 typedef hash_int hash;
388 typedef simple_item_counter item_counter;
390 dynamic_bucket_table = false
392 typedef ci::FreeList free_list;
394 typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
396 set_type s( kSize, 2 );