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_michael_iterable_hp.h"
33 #include <cds/container/iterable_kvlist_hp.h>
34 #include <cds/container/michael_map.h>
38 namespace cc = cds::container;
39 typedef cds::gc::HP gc_type;
41 class MichaelIterableMap_HP: public cds_test::michael_iterable_hp
44 typedef cds_test::michael_iterable_hp base_class;
48 typedef cc::IterableKVList< gc_type, key_type, value_type > list_type;
49 typedef cc::MichaelHashMap< gc_type, list_type > map_type;
51 // +3 - for guarded_ptr and iterator
52 cds::gc::hp::GarbageCollector::Construct( map_type::c_nHazardPtrCount + 3, 1, 16 );
53 cds::threading::Manager::attachThread();
58 cds::threading::Manager::detachThread();
59 cds::gc::hp::GarbageCollector::Destruct( true );
63 TEST_F( MichaelIterableMap_HP, compare )
65 typedef cc::IterableKVList< gc_type, key_type, value_type,
66 typename cc::iterable_list::make_traits<
67 cds::opt::compare< cmp >
71 typedef cc::MichaelHashMap< gc_type, list_type,
72 typename cc::michael_map::make_traits<
73 cds::opt::hash< hash1 >
77 map_type m( kSize, 2 );
81 TEST_F( MichaelIterableMap_HP, less )
83 typedef cc::IterableKVList< gc_type, key_type, value_type,
84 typename cc::iterable_list::make_traits<
85 cds::opt::less< less >
89 typedef cc::MichaelHashMap< gc_type, list_type,
90 typename cc::michael_map::make_traits<
91 cds::opt::hash< hash1 >
95 map_type m( kSize, 1 );
99 TEST_F( MichaelIterableMap_HP, cmpmix )
101 typedef cc::IterableKVList< gc_type, key_type, value_type,
102 typename cc::iterable_list::make_traits<
103 cds::opt::less< less >
104 ,cds::opt::compare< cmp >
108 typedef cc::MichaelHashMap< gc_type, list_type,
109 typename cc::michael_map::make_traits<
110 cds::opt::hash< hash1 >
114 map_type m( kSize, 2 );
118 TEST_F( MichaelIterableMap_HP, backoff )
120 struct list_traits: public cc::iterable_list::traits
123 typedef cds::backoff::exponential<cds::backoff::pause, cds::backoff::yield> back_off;
125 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
127 struct map_traits: public cc::michael_map::traits
130 typedef cds::atomicity::item_counter item_counter;
132 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
134 map_type m( kSize, 4 );
138 TEST_F( MichaelIterableMap_HP, seq_cst )
140 struct list_traits: public cc::iterable_list::traits
143 typedef cds::backoff::yield back_off;
144 typedef cds::opt::v::sequential_consistent memory_model;
146 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
148 struct map_traits: public cc::michael_map::traits
152 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
154 map_type s( kSize, 8 );
158 TEST_F( MichaelIterableMap_HP, stat )
160 struct list_traits: public cc::iterable_list::traits
163 typedef cds::backoff::yield back_off;
164 typedef cc::iterable_list::stat<> stat;
166 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
168 struct map_traits: public cc::michael_map::traits
172 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
174 map_type m( kSize, 8 );
176 EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );
179 TEST_F( MichaelIterableMap_HP, wrapped_stat )
181 struct list_traits: public cc::iterable_list::traits
184 typedef cc::iterable_list::wrapped_stat<> stat;
186 typedef cc::IterableKVList< gc_type, key_type, value_type, list_traits > list_type;
188 struct map_traits: public cc::michael_map::traits
192 typedef cc::MichaelHashMap< gc_type, list_type, map_traits > map_type;
194 map_type m( kSize, 8 );
196 EXPECT_GE( m.statistics().m_nInsertSuccess, 0u );