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_nogc.h"
33 #include <cds/intrusive/lazy_list_nogc.h>
34 #include <cds/intrusive/michael_set_nogc.h>
39 namespace ci = cds::intrusive;
40 typedef cds::gc::nogc gc_type;
42 class IntrusiveMichaelLazySet_NoGC : public cds_test::intrusive_set_nogc
45 typedef cds_test::intrusive_set_nogc 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;
61 TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmp )
63 typedef ci::LazyList< gc_type
65 ,ci::lazy_list::make_traits<
66 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type > > >
67 ,ci::opt::compare< cmp<base_item_type> >
68 ,ci::opt::disposer< mock_disposer >
69 ,ci::opt::back_off< cds::backoff::pause >
73 typedef ci::MichaelHashSet< gc_type, bucket_type,
74 ci::michael_set::make_traits<
75 ci::opt::hash< hash_int >
79 set_type s( kSize, 2 );
83 TEST_F( IntrusiveMichaelLazySet_NoGC, base_less )
85 typedef ci::LazyList< gc_type
87 ,ci::lazy_list::make_traits<
88 ci::opt::hook< ci::lazy_list::base_hook< ci::opt::gc< gc_type >>>
89 ,ci::opt::less< less<base_item_type> >
90 ,ci::opt::disposer< mock_disposer >
94 typedef ci::MichaelHashSet< gc_type, bucket_type,
95 ci::michael_set::make_traits<
96 ci::opt::hash< hash_int >
100 set_type s( kSize, 2 );
104 TEST_F( IntrusiveMichaelLazySet_NoGC, base_cmpmix )
106 struct list_traits : public ci::lazy_list::traits
108 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
109 typedef base_class::less<base_item_type> less;
110 typedef cmp<base_item_type> compare;
111 typedef mock_disposer disposer;
113 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
115 struct set_traits : public ci::michael_set::traits
117 typedef hash_int hash;
118 typedef simple_item_counter item_counter;
120 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
122 set_type s( kSize, 2 );
126 TEST_F( IntrusiveMichaelLazySet_NoGC, base_mutex )
128 struct list_traits : public ci::lazy_list::traits
130 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
131 typedef base_class::less<base_mutex_item_type> less;
132 typedef cmp<base_mutex_item_type> compare;
133 typedef mock_disposer disposer;
135 typedef ci::LazyList< gc_type, base_mutex_item_type, list_traits > bucket_type;
137 struct set_traits : public ci::michael_set::traits
139 typedef hash_int hash;
140 typedef simple_item_counter item_counter;
142 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
144 set_type s( kSize, 2 );
148 TEST_F( IntrusiveMichaelLazySet_NoGC, base_stat )
150 struct list_traits: public ci::lazy_list::traits
152 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
153 typedef base_class::less<base_item_type> less;
154 typedef mock_disposer disposer;
155 typedef ci::lazy_list::stat<> stat;
157 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
159 struct set_traits: public ci::michael_set::traits
161 typedef hash_int hash;
162 typedef simple_item_counter item_counter;
164 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
166 set_type s( kSize, 2 );
168 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
171 TEST_F( IntrusiveMichaelLazySet_NoGC, base_wrapped_stat )
173 struct list_traits: public ci::lazy_list::traits
175 typedef ci::lazy_list::base_hook< ci::opt::gc<gc_type>> hook;
176 typedef base_class::less<base_item_type> less;
177 typedef mock_disposer disposer;
178 typedef ci::lazy_list::wrapped_stat<> stat;
180 typedef ci::LazyList< gc_type, base_item_type, list_traits > bucket_type;
182 struct set_traits: public ci::michael_set::traits
184 typedef hash_int hash;
185 typedef simple_item_counter item_counter;
187 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
189 set_type s( kSize, 2 );
191 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
194 TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmp )
196 typedef ci::LazyList< gc_type
198 ,ci::lazy_list::make_traits<
199 ci::opt::hook< ci::lazy_list::member_hook<
200 offsetof( member_item_type, hMember ),
203 ,ci::opt::compare< cmp<member_item_type> >
204 ,ci::opt::disposer< mock_disposer >
208 typedef ci::MichaelHashSet< gc_type, bucket_type,
209 ci::michael_set::make_traits<
210 ci::opt::hash< hash_int >
214 set_type s( kSize, 2 );
218 TEST_F( IntrusiveMichaelLazySet_NoGC, member_less )
220 typedef ci::LazyList< gc_type
222 ,ci::lazy_list::make_traits<
223 ci::opt::hook< ci::lazy_list::member_hook<
224 offsetof( member_item_type, hMember ),
227 ,ci::opt::less< less<member_item_type> >
228 ,ci::opt::disposer< mock_disposer >
232 typedef ci::MichaelHashSet< gc_type, bucket_type,
233 ci::michael_set::make_traits<
234 ci::opt::hash< hash_int >
238 set_type s( kSize, 2 );
242 TEST_F( IntrusiveMichaelLazySet_NoGC, member_cmpmix )
244 struct list_traits : public ci::lazy_list::traits
246 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
247 typedef base_class::less<member_item_type> less;
248 typedef cmp<member_item_type> compare;
249 typedef mock_disposer disposer;
251 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
253 struct set_traits : public ci::michael_set::traits
255 typedef hash_int hash;
256 typedef simple_item_counter item_counter;
258 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
260 set_type s( kSize, 2 );
264 TEST_F( IntrusiveMichaelLazySet_NoGC, member_mutex )
266 struct list_traits : public ci::lazy_list::traits
268 typedef ci::lazy_list::member_hook< offsetof( member_mutex_item_type, hMember ), ci::opt::gc<gc_type>, ci::opt::lock_type<std::mutex>> hook;
269 typedef base_class::less<member_mutex_item_type> less;
270 typedef cmp<member_mutex_item_type> compare;
271 typedef mock_disposer disposer;
273 typedef ci::LazyList< gc_type, member_mutex_item_type, list_traits > bucket_type;
275 struct set_traits : public ci::michael_set::traits
277 typedef hash_int hash;
278 typedef simple_item_counter item_counter;
280 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
282 set_type s( kSize, 2 );
286 TEST_F( IntrusiveMichaelLazySet_NoGC, member_stat )
288 struct list_traits: public ci::lazy_list::traits
290 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
291 typedef cmp<member_item_type> compare;
292 typedef mock_disposer disposer;
293 typedef ci::lazy_list::stat<> stat;
295 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
297 struct set_traits: public ci::michael_set::traits
299 typedef hash_int hash;
300 typedef simple_item_counter item_counter;
302 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
304 set_type s( kSize, 2 );
306 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
309 TEST_F( IntrusiveMichaelLazySet_NoGC, member_wrapped_stat )
311 struct list_traits: public ci::lazy_list::traits
313 typedef ci::lazy_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
314 typedef cmp<member_item_type> compare;
315 typedef mock_disposer disposer;
316 typedef ci::lazy_list::wrapped_stat<> stat;
318 typedef ci::LazyList< gc_type, member_item_type, list_traits > bucket_type;
320 struct set_traits: public ci::michael_set::traits
322 typedef hash_int hash;
323 typedef simple_item_counter item_counter;
325 typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
327 set_type s( kSize, 2 );
329 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );