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_list_hp.h"
32 #include <cds/intrusive/michael_list_dhp.h>
35 namespace ci = cds::intrusive;
36 typedef cds::gc::DHP gc_type;
38 class IntrusiveMichaelList_DHP : 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 cds::gc::dhp::GarbageCollector::Construct( 16, list_type::c_nHazardPtrCount );
54 cds::threading::Manager::attachThread();
59 cds::threading::Manager::detachThread();
60 cds::gc::dhp::GarbageCollector::Destruct();
64 TEST_F( IntrusiveMichaelList_DHP, base_hook )
66 typedef ci::MichaelList< gc_type, base_item,
67 typename ci::michael_list::make_traits<
68 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
69 ,ci::opt::disposer< mock_disposer >
70 ,cds::opt::less< less< base_item >>
76 test_ordered_iterator( l );
80 TEST_F( IntrusiveMichaelList_DHP, base_hook_cmp )
82 typedef ci::MichaelList< gc_type, base_item,
83 typename ci::michael_list::make_traits<
84 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
85 , ci::opt::disposer< mock_disposer >
86 , cds::opt::compare< cmp< base_item >>
92 test_ordered_iterator( l );
96 TEST_F( IntrusiveMichaelList_DHP, base_hook_item_counting )
98 struct traits : public ci::michael_list::traits {
99 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
100 typedef mock_disposer disposer;
101 typedef cmp< base_item > compare;
102 typedef intrusive_list_common::less< base_item > less;
103 typedef cds::atomicity::item_counter item_counter;
105 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
109 test_ordered_iterator( l );
113 TEST_F( IntrusiveMichaelList_DHP, base_hook_backoff )
115 struct traits : public ci::michael_list::traits {
116 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
117 typedef mock_disposer disposer;
118 typedef cmp< base_item > compare;
119 typedef intrusive_list_common::less< base_item > less;
120 typedef cds::atomicity::item_counter item_counter;
121 typedef cds::backoff::pause back_off;
123 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
127 test_ordered_iterator( l );
131 TEST_F( IntrusiveMichaelList_DHP, base_hook_seqcst )
133 struct traits : public ci::michael_list::traits {
134 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
135 typedef mock_disposer disposer;
136 typedef cmp< base_item > compare;
137 typedef intrusive_list_common::less< base_item > less;
138 typedef cds::atomicity::item_counter item_counter;
139 typedef cds::opt::v::sequential_consistent memory_model;
141 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
145 test_ordered_iterator( l );
148 TEST_F( IntrusiveMichaelList_DHP, base_hook_stat )
150 struct traits: public ci::michael_list::traits {
151 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
152 typedef mock_disposer disposer;
153 typedef cmp< base_item > compare;
154 typedef intrusive_list_common::less< base_item > less;
155 typedef cds::intrusive::michael_list::stat<> stat;
157 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
161 test_ordered_iterator( l );
165 TEST_F( IntrusiveMichaelList_DHP, base_hook_wrapped_stat )
167 struct traits: public ci::michael_list::traits {
168 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
169 typedef mock_disposer disposer;
170 typedef cmp< base_item > compare;
171 typedef cds::intrusive::michael_list::wrapped_stat<> stat;
173 typedef ci::MichaelList< gc_type, base_item, traits > list_type;
175 cds::intrusive::michael_list::stat<> st;
178 test_ordered_iterator( l );
183 TEST_F( IntrusiveMichaelList_DHP, member_hook )
185 typedef ci::MichaelList< gc_type, member_item,
186 typename ci::michael_list::make_traits<
187 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
188 ,ci::opt::disposer< mock_disposer >
189 ,cds::opt::less< less< member_item >>
195 test_ordered_iterator( l );
199 TEST_F( IntrusiveMichaelList_DHP, member_hook_cmp )
201 typedef ci::MichaelList< gc_type, member_item,
202 typename ci::michael_list::make_traits<
203 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
204 ,ci::opt::disposer< mock_disposer >
205 ,cds::opt::compare< cmp< member_item >>
211 test_ordered_iterator( l );
215 TEST_F( IntrusiveMichaelList_DHP, member_hook_item_counting )
217 struct traits : public ci::michael_list::traits {
218 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
219 typedef mock_disposer disposer;
220 typedef cmp< member_item > compare;
221 typedef intrusive_list_common::less< member_item > less;
222 typedef cds::atomicity::item_counter item_counter;
224 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
228 test_ordered_iterator( l );
232 TEST_F( IntrusiveMichaelList_DHP, member_hook_seqcst )
234 struct traits : public ci::michael_list::traits {
235 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
236 typedef mock_disposer disposer;
237 typedef cmp< member_item > compare;
238 typedef intrusive_list_common::less< member_item > less;
239 typedef cds::atomicity::item_counter item_counter;
240 typedef cds::opt::v::sequential_consistent memory_model;
242 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
246 test_ordered_iterator( l );
250 TEST_F( IntrusiveMichaelList_DHP, member_hook_back_off )
252 struct traits : public ci::michael_list::traits {
253 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
254 typedef mock_disposer disposer;
255 typedef cmp< member_item > compare;
256 typedef intrusive_list_common::less< member_item > less;
257 typedef cds::atomicity::item_counter item_counter;
258 typedef cds::backoff::empty back_off;
260 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
264 test_ordered_iterator( l );
268 TEST_F( IntrusiveMichaelList_DHP, member_hook_stat )
270 struct traits: public ci::michael_list::traits {
271 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
272 typedef mock_disposer disposer;
273 typedef cmp< member_item > compare;
274 typedef intrusive_list_common::less< member_item > less;
275 typedef cds::intrusive::michael_list::stat<> stat;
277 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
281 test_ordered_iterator( l );
285 TEST_F( IntrusiveMichaelList_DHP, member_hook_wrapped_stat )
287 struct traits: public ci::michael_list::traits {
288 typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
289 typedef mock_disposer disposer;
290 typedef cmp< member_item > compare;
291 typedef cds::intrusive::michael_list::wrapped_stat<> stat;
293 typedef ci::MichaelList< gc_type, member_item, traits > list_type;
295 cds::intrusive::michael_list::stat<> st;
298 test_ordered_iterator( l );