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/lazy_list_dhp.h>
35 namespace ci = cds::intrusive;
36 typedef cds::gc::DHP gc_type;
38 class IntrusiveLazyList_DHP : public cds_test::intrusive_list_hp
41 typedef cds_test::intrusive_list_hp::base_item< ci::lazy_list::node< gc_type>> base_item;
42 typedef cds_test::intrusive_list_hp::member_item< ci::lazy_list::node< gc_type>> member_item;
44 typedef cds_test::intrusive_list_hp::base_item< ci::lazy_list::node< gc_type, std::mutex>> base_mutex_item;
45 typedef cds_test::intrusive_list_hp::member_item< ci::lazy_list::node< gc_type, std::mutex>> member_mutex_item;
50 struct traits: public ci::lazy_list::traits
52 typedef ci::lazy_list::base_hook< cds::opt::gc< gc_type >> hook;
54 typedef ci::LazyList< gc_type, base_item, traits > list_type;
56 cds::gc::dhp::GarbageCollector::Construct( 16, list_type::c_nHazardPtrCount );
57 cds::threading::Manager::attachThread();
62 cds::threading::Manager::detachThread();
63 cds::gc::hp::GarbageCollector::Destruct();
67 TEST_F( IntrusiveLazyList_DHP, base_hook )
69 typedef ci::LazyList< gc_type, base_item,
70 typename ci::lazy_list::make_traits<
71 ci::opt::hook< ci::lazy_list::base_hook< cds::opt::gc< gc_type >>>
72 ,ci::opt::disposer< mock_disposer >
73 ,cds::opt::less< less< base_item >>
79 test_sorted_iterator( l );
83 TEST_F( IntrusiveLazyList_DHP, base_hook_cmp )
85 typedef ci::LazyList< gc_type, base_item,
86 typename ci::lazy_list::make_traits<
87 ci::opt::hook< ci::lazy_list::base_hook< cds::opt::gc< gc_type >>>
88 , ci::opt::disposer< mock_disposer >
89 , cds::opt::compare< cmp< base_item >>
95 test_sorted_iterator( l );
99 TEST_F( IntrusiveLazyList_DHP, base_hook_item_counting )
101 struct traits : public ci::lazy_list::traits {
102 typedef ci::lazy_list::base_hook< cds::opt::gc< gc_type >> hook;
103 typedef mock_disposer disposer;
104 typedef cmp< base_item > compare;
105 typedef intrusive_list_common::less< base_item > less;
106 typedef cds::atomicity::item_counter item_counter;
108 typedef ci::LazyList< gc_type, base_item, traits > list_type;
112 test_sorted_iterator( l );
116 TEST_F( IntrusiveLazyList_DHP, base_hook_mutex )
118 struct traits : public ci::lazy_list::traits {
119 typedef ci::lazy_list::base_hook< cds::opt::gc< gc_type >, cds::opt::lock_type< std::mutex>> hook;
120 typedef mock_disposer disposer;
121 typedef cmp< base_mutex_item > compare;
122 typedef intrusive_list_common::less< base_mutex_item > less;
123 typedef cds::atomicity::item_counter item_counter;
125 typedef ci::LazyList< gc_type, base_mutex_item, traits > list_type;
129 test_sorted_iterator( l );
133 TEST_F( IntrusiveLazyList_DHP, base_hook_backoff )
135 struct traits : public ci::lazy_list::traits {
136 typedef ci::lazy_list::base_hook< cds::opt::gc< gc_type >> hook;
137 typedef mock_disposer disposer;
138 typedef cmp< base_item > compare;
139 typedef intrusive_list_common::less< base_item > less;
140 typedef cds::atomicity::item_counter item_counter;
141 typedef cds::backoff::pause back_off;
143 typedef ci::LazyList< gc_type, base_item, traits > list_type;
147 test_sorted_iterator( l );
151 TEST_F( IntrusiveLazyList_DHP, base_hook_seqcst )
153 struct traits : public ci::lazy_list::traits {
154 typedef ci::lazy_list::base_hook< cds::opt::gc< gc_type >> hook;
155 typedef mock_disposer disposer;
156 typedef cmp< base_item > compare;
157 typedef intrusive_list_common::less< base_item > less;
158 typedef cds::atomicity::item_counter item_counter;
159 typedef cds::opt::v::sequential_consistent memory_model;
161 typedef ci::LazyList< gc_type, base_item, traits > list_type;
165 test_sorted_iterator( l );
169 TEST_F( IntrusiveLazyList_DHP, member_hook )
171 typedef ci::LazyList< gc_type, member_item,
172 typename ci::lazy_list::make_traits<
173 ci::opt::hook< ci::lazy_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
174 ,ci::opt::disposer< mock_disposer >
175 ,cds::opt::less< less< member_item >>
181 test_sorted_iterator( l );
185 TEST_F( IntrusiveLazyList_DHP, member_hook_cmp )
187 typedef ci::LazyList< gc_type, member_item,
188 typename ci::lazy_list::make_traits<
189 ci::opt::hook< ci::lazy_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
190 ,ci::opt::disposer< mock_disposer >
191 ,cds::opt::compare< cmp< member_item >>
197 test_sorted_iterator( l );
201 TEST_F( IntrusiveLazyList_DHP, member_hook_item_counting )
203 struct traits : public ci::lazy_list::traits {
204 typedef ci::lazy_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
205 typedef mock_disposer disposer;
206 typedef cmp< member_item > compare;
207 typedef intrusive_list_common::less< member_item > less;
208 typedef cds::atomicity::item_counter item_counter;
210 typedef ci::LazyList< gc_type, member_item, traits > list_type;
214 test_sorted_iterator( l );
218 TEST_F( IntrusiveLazyList_DHP, member_hook_seqcst )
220 struct traits : public ci::lazy_list::traits {
221 typedef ci::lazy_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
222 typedef mock_disposer disposer;
223 typedef cmp< member_item > compare;
224 typedef intrusive_list_common::less< member_item > less;
225 typedef cds::atomicity::item_counter item_counter;
226 typedef cds::opt::v::sequential_consistent memory_model;
228 typedef ci::LazyList< gc_type, member_item, traits > list_type;
232 test_sorted_iterator( l );
236 TEST_F( IntrusiveLazyList_DHP, member_hook_mutex )
238 struct traits : public ci::lazy_list::traits {
239 typedef ci::lazy_list::member_hook< offsetof( member_mutex_item, hMember ), cds::opt::gc< gc_type >, cds::opt::lock_type< std::mutex >> hook;
240 typedef mock_disposer disposer;
241 typedef cmp< member_mutex_item > compare;
242 typedef intrusive_list_common::less< member_mutex_item > less;
243 typedef cds::atomicity::item_counter item_counter;
244 typedef cds::opt::v::sequential_consistent memory_model;
246 typedef ci::LazyList< gc_type, member_mutex_item, traits > list_type;
250 test_sorted_iterator( l );
254 TEST_F( IntrusiveLazyList_DHP, member_hook_back_off )
256 struct traits : public ci::lazy_list::traits {
257 typedef ci::lazy_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
258 typedef mock_disposer disposer;
259 typedef cmp< member_item > compare;
260 typedef intrusive_list_common::less< member_item > less;
261 typedef cds::atomicity::item_counter item_counter;
262 typedef cds::backoff::empty back_off;
264 typedef ci::LazyList< gc_type, member_item, traits > list_type;
268 test_sorted_iterator( l );