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_michael_iterable_hp.h"
33 #include <cds/container/iterable_list_hp.h>
34 #include <cds/container/split_list_map.h>
35 #include <cds/intrusive/free_list.h>
38 namespace cc = cds::container;
39 typedef cds::gc::HP gc_type;
41 class SplitListIterableMap_HP : public cds_test::michael_iterable_map
44 typedef cds_test::michael_iterable_map base_class;
48 struct map_traits: public cc::split_list::traits {
49 typedef cc::iterable_list_tag ordered_list;
51 struct ordered_list_traits: public cc::iterable_list::traits
56 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
58 // +3 - for guarded_ptr
59 cds::gc::hp::GarbageCollector::Construct( map_type::c_nHazardPtrCount + 3, 1, 16 );
60 cds::threading::Manager::attachThread();
65 cds::threading::Manager::detachThread();
66 cds::gc::hp::GarbageCollector::Destruct( true );
70 TEST_F( SplitListIterableMap_HP, compare )
72 typedef cc::SplitListMap< gc_type, key_type, value_type,
73 typename cc::split_list::make_traits<
74 cc::split_list::ordered_list< cc::iterable_list_tag >
75 , cds::opt::hash< hash1 >
76 , cc::split_list::ordered_list_traits<
77 typename cc::iterable_list::make_traits<
78 cds::opt::compare< cmp >
84 map_type m( kSize, 2 );
88 TEST_F( SplitListIterableMap_HP, less )
90 typedef cc::SplitListMap< gc_type, key_type, value_type,
91 typename cc::split_list::make_traits<
92 cc::split_list::ordered_list< cc::iterable_list_tag >
93 , cds::opt::hash< hash1 >
94 , cc::split_list::ordered_list_traits<
95 typename cc::iterable_list::make_traits<
96 cds::opt::less< less >
102 map_type m( kSize, 2 );
106 TEST_F( SplitListIterableMap_HP, cmpmix )
108 typedef cc::SplitListMap< gc_type, key_type, value_type,
109 typename cc::split_list::make_traits<
110 cc::split_list::ordered_list< cc::iterable_list_tag >
111 , cds::opt::hash< hash1 >
112 , cc::split_list::ordered_list_traits<
113 typename cc::iterable_list::make_traits<
114 cds::opt::less< less >
115 , cds::opt::compare< cmp >
121 map_type m( kSize, 2 );
125 TEST_F( SplitListIterableMap_HP, item_counting )
127 struct map_traits: public cc::split_list::traits
129 typedef cc::iterable_list_tag ordered_list;
131 typedef cds::atomicity::item_counter item_counter;
133 struct ordered_list_traits: public cc::iterable_list::traits
136 typedef base_class::less less;
137 typedef cds::backoff::empty back_off;
140 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
142 map_type m( kSize, 4 );
146 TEST_F( SplitListIterableMap_HP, stat )
148 struct map_traits: public cc::split_list::traits
150 typedef cc::iterable_list_tag ordered_list;
152 typedef cds::atomicity::item_counter item_counter;
153 typedef cc::split_list::stat<> stat;
155 struct ordered_list_traits: public cc::iterable_list::traits
157 typedef base_class::less less;
158 typedef cc::iterable_list::stat<> stat;
161 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
163 map_type m( kSize, 2 );
165 EXPECT_NE( m.statistics().m_nInsertSuccess, 0 );
166 EXPECT_NE( m.list_statistics().m_nInsertSuccess, 0 );
169 TEST_F( SplitListIterableMap_HP, back_off )
171 struct map_traits: public cc::split_list::traits
173 typedef cc::iterable_list_tag ordered_list;
175 typedef cds::atomicity::item_counter item_counter;
176 typedef cds::backoff::yield back_off;
177 typedef cds::opt::v::sequential_consistent memory_model;
179 struct ordered_list_traits: public cc::iterable_list::traits
182 typedef cds::backoff::pause back_off;
185 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
187 map_type m( kSize, 3 );
191 TEST_F( SplitListIterableMap_HP, free_list )
193 struct map_traits: public cc::split_list::traits
195 typedef cc::iterable_list_tag ordered_list;
197 typedef cds::atomicity::item_counter item_counter;
198 typedef cds::intrusive::FreeList free_list;
200 struct ordered_list_traits: public cc::iterable_list::traits
203 typedef cds::backoff::pause back_off;
206 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
208 map_type m( kSize, 3 );
212 struct set_static_traits: public cc::split_list::traits
214 static bool const dynamic_bucket_table = false;
217 TEST_F( SplitListIterableMap_HP, static_bucket_table )
219 struct map_traits: public set_static_traits
221 typedef cc::iterable_list_tag ordered_list;
223 typedef cds::atomicity::item_counter item_counter;
225 struct ordered_list_traits: public cc::iterable_list::traits
228 typedef cds::backoff::pause back_off;
231 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
233 map_type m( kSize, 4 );
237 TEST_F( SplitListIterableMap_HP, static_bucket_table_free_list )
239 struct map_traits: public set_static_traits
241 typedef cc::iterable_list_tag ordered_list;
243 typedef cds::atomicity::item_counter item_counter;
244 typedef cds::intrusive::FreeList free_list;
246 struct ordered_list_traits: public cc::iterable_list::traits
249 typedef cds::backoff::pause back_off;
252 typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
254 map_type m( kSize, 4 );