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_list_hp.h"
32 #include <cds/intrusive/michael_list_hp.h>
35 namespace ci = cds::intrusive;
36 typedef cds::gc::HP gc_type;
38 class IntrusiveMichaelList_HP : public cds_test::intrusive_list_hp
41 typedef cds_test::intrusive_list_hp::base_item< ci::michael_list::node< gc_type>> base_item;
42 typedef cds_test::intrusive_list_hp::member_item< ci::michael_list::node< gc_type>> member_item;
47 struct traits: public ci::michael_list::traits
49 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
51 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
53 // +1 - for guarded_ptr
54 cds::gc::hp::GarbageCollector::Construct( list_type::c_nHazardPtrCount + 1, 1, 16 );
55 cds::threading::Manager::attachThread();
60 cds::threading::Manager::detachThread();
61 cds::gc::hp::GarbageCollector::Destruct( true );
65 TEST_F( IntrusiveMichaelList_HP, base_hook )
67 typedef ci::MichaelList< gc_type, base_item,
68 typename ci::michael_list::make_traits<
69 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
70 ,ci::opt::disposer< mock_disposer >
71 ,cds::opt::less< less< base_item >>
77 test_ordered_iterator( l );
81 TEST_F( IntrusiveMichaelList_HP, base_hook_cmp )
83 typedef ci::MichaelList< gc_type, base_item,
84 typename ci::michael_list::make_traits<
85 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
86 , ci::opt::disposer< mock_disposer >
87 , cds::opt::compare< cmp< base_item >>
93 test_ordered_iterator( l );
97 TEST_F( IntrusiveMichaelList_HP, base_hook_item_counting )
99 struct traits : public ci::michael_list::traits {
100 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
101 typedef mock_disposer disposer;
102 typedef cmp< base_item > compare;
103 typedef intrusive_list_common::less< base_item > less;
104 typedef cds::atomicity::item_counter item_counter;
106 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
110 test_ordered_iterator( l );
114 TEST_F( IntrusiveMichaelList_HP, base_hook_backoff )
116 struct traits : public ci::michael_list::traits {
117 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
118 typedef mock_disposer disposer;
119 typedef cmp< base_item > compare;
120 typedef intrusive_list_common::less< base_item > less;
121 typedef cds::atomicity::item_counter item_counter;
122 typedef cds::backoff::pause back_off;
124 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
128 test_ordered_iterator( l );
132 TEST_F( IntrusiveMichaelList_HP, base_hook_seqcst )
134 struct traits : public ci::michael_list::traits {
135 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
136 typedef mock_disposer disposer;
137 typedef cmp< base_item > compare;
138 typedef intrusive_list_common::less< base_item > less;
139 typedef cds::atomicity::item_counter item_counter;
140 typedef cds::opt::v::sequential_consistent memory_model;
142 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
146 test_ordered_iterator( l );
150 TEST_F( IntrusiveMichaelList_HP, base_hook_stat )
152 struct traits: public ci::michael_list::traits {
153 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
154 typedef mock_disposer disposer;
155 typedef cmp< base_item > compare;
156 typedef intrusive_list_common::less< base_item > less;
157 typedef cds::intrusive::michael_list::stat<> stat;
159 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
163 test_ordered_iterator( l );
167 TEST_F( IntrusiveMichaelList_HP, base_hook_wrapped_stat )
169 struct traits: public ci::michael_list::traits {
170 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
171 typedef mock_disposer disposer;
172 typedef cmp< base_item > compare;
173 typedef cds::intrusive::michael_list::wrapped_stat<> stat;
175 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
177 cds::intrusive::michael_list::stat<> st;
180 test_ordered_iterator( l );
184 TEST_F( IntrusiveMichaelList_HP, member_hook )
186 typedef ci::MichaelList< gc_type, member_item,
187 typename ci::michael_list::make_traits<
188 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
189 ,ci::opt::disposer< mock_disposer >
190 ,cds::opt::less< less< member_item >>
196 test_ordered_iterator( l );
200 TEST_F( IntrusiveMichaelList_HP, member_hook_cmp )
202 typedef ci::MichaelList< gc_type, member_item,
203 typename ci::michael_list::make_traits<
204 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
205 ,ci::opt::disposer< mock_disposer >
206 ,cds::opt::compare< cmp< member_item >>
212 test_ordered_iterator( l );
216 TEST_F( IntrusiveMichaelList_HP, member_hook_item_counting )
218 struct traits : public ci::michael_list::traits {
219 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
220 typedef mock_disposer disposer;
221 typedef cmp< member_item > compare;
222 typedef intrusive_list_common::less< member_item > less;
223 typedef cds::atomicity::item_counter item_counter;
225 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
229 test_ordered_iterator( l );
233 TEST_F( IntrusiveMichaelList_HP, member_hook_seqcst )
235 struct traits : public ci::michael_list::traits {
236 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
237 typedef mock_disposer disposer;
238 typedef cmp< member_item > compare;
239 typedef intrusive_list_common::less< member_item > less;
240 typedef cds::atomicity::item_counter item_counter;
241 typedef cds::opt::v::sequential_consistent memory_model;
243 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
247 test_ordered_iterator( l );
251 TEST_F( IntrusiveMichaelList_HP, member_hook_back_off )
253 struct traits : public ci::michael_list::traits {
254 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
255 typedef mock_disposer disposer;
256 typedef cmp< member_item > compare;
257 typedef intrusive_list_common::less< member_item > less;
258 typedef cds::atomicity::item_counter item_counter;
259 typedef cds::backoff::empty back_off;
261 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
265 test_ordered_iterator( l );
269 TEST_F( IntrusiveMichaelList_HP, member_hook_stat )
271 struct traits: public ci::michael_list::traits {
272 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
273 typedef mock_disposer disposer;
274 typedef cmp< member_item > compare;
275 typedef intrusive_list_common::less< member_item > less;
276 typedef cds::intrusive::michael_list::stat<> stat;
278 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
282 test_ordered_iterator( l );
286 TEST_F( IntrusiveMichaelList_HP, member_hook_wrapped_stat )
288 struct traits: public ci::michael_list::traits {
289 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
290 typedef mock_disposer disposer;
291 typedef cmp< member_item > compare;
292 typedef cds::intrusive::michael_list::wrapped_stat<> stat;
294 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
296 cds::intrusive::michael_list::stat<> st;
299 test_ordered_iterator( l );