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/michael_set.h>
37 namespace ci = cds::intrusive;
38 typedef cds::gc::HP gc_type;
40 class IntrusiveMichaelSet_HP : public cds_test::intrusive_set_hp
43 typedef cds_test::intrusive_set_hp base_class;
46 typedef typename base_class::base_int_item< ci::michael_list::node<gc_type>> base_item_type;
47 typedef typename base_class::member_int_item< ci::michael_list::node<gc_type>> member_item_type;
51 struct list_traits : public ci::michael_list::traits
53 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
55 typedef ci::MichaelList< gc_type, base_item_type, list_traits > list_type;
56 typedef ci::MichaelHashSet< gc_type, list_type > set_type;
58 // +1 - for guarded_ptr
59 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
60 cds::threading::Manager::attachThread();
65 cds::threading::Manager::detachThread();
66 cds::gc::hp::GarbageCollector::Destruct( true );
71 TEST_F( IntrusiveMichaelSet_HP, base_cmp )
73 typedef ci::MichaelList< gc_type
75 ,ci::michael_list::make_traits<
76 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
77 ,ci::opt::compare< cmp<base_item_type> >
78 ,ci::opt::disposer< mock_disposer >
82 typedef ci::MichaelHashSet< gc_type, bucket_type,
83 ci::michael_set::make_traits<
84 ci::opt::hash< hash_int >
88 set_type s( kSize, 2 );
92 TEST_F( IntrusiveMichaelSet_HP, base_less )
94 typedef ci::MichaelList< gc_type
96 ,ci::michael_list::make_traits<
97 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
98 ,ci::opt::less< less<base_item_type> >
99 ,ci::opt::disposer< mock_disposer >
103 typedef ci::MichaelHashSet< gc_type, bucket_type,
104 ci::michael_set::make_traits<
105 ci::opt::hash< hash_int >
109 set_type s( kSize, 2 );
113 TEST_F( IntrusiveMichaelSet_HP, base_cmpmix )
115 struct list_traits : public ci::michael_list::traits
117 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
118 typedef base_class::less<base_item_type> less;
119 typedef cmp<base_item_type> compare;
120 typedef mock_disposer disposer;
122 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
124 struct set_traits : public ci::michael_set::traits
126 typedef hash_int hash;
127 typedef simple_item_counter item_counter;
129 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
131 set_type s( kSize, 2 );
136 TEST_F( IntrusiveMichaelSet_HP, base_stat )
138 struct list_traits: public ci::michael_list::traits
140 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
141 typedef cmp<base_item_type> compare;
142 typedef mock_disposer disposer;
143 typedef ci::michael_list::stat<> stat;
145 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
147 struct set_traits: public ci::michael_set::traits
149 typedef hash_int hash;
150 typedef simple_item_counter item_counter;
152 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
154 set_type s( kSize, 2 );
156 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
159 TEST_F( IntrusiveMichaelSet_HP, base_wrapped_stat )
161 struct list_traits: public ci::michael_list::traits
163 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
164 typedef base_class::less<base_item_type> less;
165 typedef mock_disposer disposer;
166 typedef ci::michael_list::wrapped_stat<> stat;
168 typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
170 struct set_traits: public ci::michael_set::traits
172 typedef hash_int hash;
173 typedef simple_item_counter item_counter;
175 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
177 set_type s( kSize, 2 );
179 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
182 TEST_F( IntrusiveMichaelSet_HP, member_cmp )
184 typedef ci::MichaelList< gc_type
186 ,ci::michael_list::make_traits<
187 ci::opt::hook< ci::michael_list::member_hook<
188 offsetof( member_item_type, hMember ),
191 ,ci::opt::compare< cmp<member_item_type> >
192 ,ci::opt::disposer< mock_disposer >
196 typedef ci::MichaelHashSet< gc_type, bucket_type,
197 ci::michael_set::make_traits<
198 ci::opt::hash< hash_int >
202 set_type s( kSize, 2 );
206 TEST_F( IntrusiveMichaelSet_HP, member_less )
208 typedef ci::MichaelList< gc_type
210 ,ci::michael_list::make_traits<
211 ci::opt::hook< ci::michael_list::member_hook<
212 offsetof( member_item_type, hMember ),
215 ,ci::opt::less< less<member_item_type> >
216 ,ci::opt::disposer< mock_disposer >
220 typedef ci::MichaelHashSet< gc_type, bucket_type,
221 ci::michael_set::make_traits<
222 ci::opt::hash< hash_int >
226 set_type s( kSize, 2 );
230 TEST_F( IntrusiveMichaelSet_HP, member_cmpmix )
232 struct list_traits : public ci::michael_list::traits
234 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
235 typedef base_class::less<member_item_type> less;
236 typedef cmp<member_item_type> compare;
237 typedef mock_disposer disposer;
239 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
241 struct set_traits : public ci::michael_set::traits
243 typedef hash_int hash;
244 typedef simple_item_counter item_counter;
246 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
248 set_type s( kSize, 2 );
252 TEST_F( IntrusiveMichaelSet_HP, member_stat )
254 struct list_traits: public ci::michael_list::traits
256 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
257 typedef base_class::less<member_item_type> less;
258 typedef cmp<member_item_type> compare;
259 typedef mock_disposer disposer;
260 typedef ci::michael_list::stat<> stat;
262 typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
264 struct set_traits: public ci::michael_set::traits
266 typedef hash_int hash;
267 typedef simple_item_counter item_counter;
269 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
271 set_type s( kSize, 2 );
273 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
276 TEST_F( IntrusiveMichaelSet_HP, member_wrapped_stat )
278 struct list_traits: public ci::michael_list::traits
280 typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
281 typedef base_class::less<member_item_type> less;
282 typedef cmp<member_item_type> compare;
283 typedef mock_disposer disposer;
284 typedef ci::michael_list::wrapped_stat<> stat;
286 typedef ci::MichaelList< gc_type, member_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 );
297 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );