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/michael_set.h>
39 namespace ci = cds::intrusive;
40 typedef cds::gc::HP gc_type;
42 class IntrusiveMichaelLazySet_HP : public cds_test::intrusive_set_hp
45 typedef cds_test::intrusive_set_hp base_class;
48 typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type>> base_item_type;
49 typedef typename base_class::base_int_item< ci::lazy_list::node<gc_type, std::mutex>> base_mutex_item_type;
50 typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type>> member_item_type;
51 typedef typename base_class::member_int_item< ci::lazy_list::node<gc_type, std::mutex>> member_mutex_item_type;
55 struct list_traits : public ci::lazy_list::traits
57 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
59 typedef ci::LazyList< gc_type, base_item_type, list_traits > list_type;
60 typedef ci::MichaelHashSet< gc_type, list_type > set_type;
62 // +1 - for guarded_ptr
63 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
64 cds::threading::Manager::attachThread();
69 cds::threading::Manager::detachThread();
70 cds::gc::hp::GarbageCollector::Destruct( true );
75 TEST_F( IntrusiveMichaelLazySet_HP, 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::MichaelHashSet< gc_type, bucket_type,
88 ci::michael_set::make_traits<
89 ci::opt::hash< hash_int >
93 set_type s( kSize, 2 );
97 TEST_F( IntrusiveMichaelLazySet_HP, 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::MichaelHashSet< gc_type, bucket_type,
109 ci::michael_set::make_traits<
110 ci::opt::hash< hash_int >
114 set_type s( kSize, 2 );
118 TEST_F( IntrusiveMichaelLazySet_HP, base_cmpmix )
120 struct list_traits : public ci::lazy_list::traits
122 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
123 typedef base_class::less<base_item_type> less;
124 typedef cmp<base_item_type> compare;
125 typedef mock_disposer disposer;
127 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
129 struct set_traits : public ci::michael_set::traits
131 typedef hash_int hash;
132 typedef simple_item_counter item_counter;
134 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
136 set_type s( kSize, 2 );
140 TEST_F( IntrusiveMichaelLazySet_HP, base_mutex )
142 struct list_traits : public ci::lazy_list::traits
144 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
145 typedef base_class::less<base_mutex_item_type> less;
146 typedef cmp<base_mutex_item_type> compare;
147 typedef mock_disposer disposer;
149 typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
151 struct set_traits : public ci::michael_set::traits
153 typedef hash_int hash;
154 typedef simple_item_counter item_counter;
156 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
158 set_type s( kSize, 2 );
162 TEST_F( IntrusiveMichaelLazySet_HP, base_stat )
164 struct list_traits: public ci::lazy_list::traits
166 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
167 typedef cmp<base_mutex_item_type> compare;
168 typedef mock_disposer disposer;
169 typedef ci::lazy_list::stat<> stat;
171 typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
173 struct set_traits: public ci::michael_set::traits
175 typedef hash_int hash;
176 typedef simple_item_counter item_counter;
178 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
180 set_type s( kSize, 2 );
184 TEST_F( IntrusiveMichaelLazySet_HP, base_wrapped_stat )
186 struct list_traits: public ci::lazy_list::traits
188 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
189 typedef cmp<base_item_type> compare;
190 typedef mock_disposer disposer;
191 typedef ci::lazy_list::wrapped_stat<> stat;
193 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
195 struct set_traits: public ci::michael_set::traits
197 typedef hash_int hash;
198 typedef simple_item_counter item_counter;
200 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
202 set_type s( kSize, 2 );
207 TEST_F( IntrusiveMichaelLazySet_HP, member_cmp )
209 typedef ci::LazyList< gc_type
211 ,ci::lazy_list::make_traits<
212 ci::opt::hook< ci::lazy_list::member_hook<
213 offsetof( member_item_type, hMember ),
216 ,ci::opt::compare< cmp<member_item_type> >
217 ,ci::opt::disposer< mock_disposer >
221 typedef ci::MichaelHashSet< gc_type, bucket_type,
222 ci::michael_set::make_traits<
223 ci::opt::hash< hash_int >
227 set_type s( kSize, 2 );
231 TEST_F( IntrusiveMichaelLazySet_HP, member_less )
233 typedef ci::LazyList< gc_type
235 ,ci::lazy_list::make_traits<
236 ci::opt::hook< ci::lazy_list::member_hook<
237 offsetof( member_item_type, hMember ),
240 ,ci::opt::less< less<member_item_type> >
241 ,ci::opt::disposer< mock_disposer >
245 typedef ci::MichaelHashSet< gc_type, bucket_type,
246 ci::michael_set::make_traits<
247 ci::opt::hash< hash_int >
251 set_type s( kSize, 2 );
255 TEST_F( IntrusiveMichaelLazySet_HP, member_cmpmix )
257 struct list_traits : public ci::lazy_list::traits
259 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
260 typedef base_class::less<member_item_type> less;
261 typedef cmp<member_item_type> compare;
262 typedef mock_disposer disposer;
264 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
266 struct set_traits : public ci::michael_set::traits
268 typedef hash_int hash;
269 typedef simple_item_counter item_counter;
271 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
273 set_type s( kSize, 2 );
277 TEST_F( IntrusiveMichaelLazySet_HP, member_mutex )
279 struct list_traits : public ci::lazy_list::traits
281 typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
282 typedef base_class::less<member_mutex_item_type> less;
283 typedef cmp<member_mutex_item_type> compare;
284 typedef mock_disposer disposer;
286 typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
288 struct set_traits : public ci::michael_set::traits
290 typedef hash_int hash;
291 typedef simple_item_counter item_counter;
293 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
295 set_type s( kSize, 2 );
299 TEST_F( IntrusiveMichaelLazySet_HP, member_stat )
301 struct list_traits: public ci::lazy_list::traits
303 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
304 typedef base_class::less<member_item_type> less;
305 typedef mock_disposer disposer;
306 typedef ci::lazy_list::stat<> stat;
308 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
310 struct set_traits: public ci::michael_set::traits
312 typedef hash_int hash;
313 typedef simple_item_counter item_counter;
315 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
317 set_type s( kSize, 2 );
321 TEST_F( IntrusiveMichaelLazySet_HP, member_wrapped_stat )
323 struct list_traits: public ci::lazy_list::traits
325 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
326 typedef base_class::less<member_item_type> less;
327 typedef mock_disposer disposer;
328 typedef ci::lazy_list::wrapped_stat<> stat;
330 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
332 struct set_traits: public ci::michael_set::traits
334 typedef hash_int hash;
335 typedef simple_item_counter item_counter;
337 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
339 set_type s( kSize, 2 );