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_set_hp.h"
33 #include <cds/container/michael_list_hp.h>
34 #include <cds/container/michael_set.h>
37 namespace cc = cds::container;
38 typedef cds::gc::HP gc_type;
40 class MichaelSet_HP : public cds_test::container_set_hp
43 typedef cds_test::container_set_hp base_class;
47 typedef cc::MichaelList< gc_type, int_item > list_type;
48 typedef cc::MichaelHashSet< gc_type, list_type > set_type;
50 // +1 - for guarded_ptr
51 cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
52 cds::threading::Manager::attachThread();
57 cds::threading::Manager::detachThread();
58 cds::gc::hp::GarbageCollector::Destruct( true );
62 TEST_F( MichaelSet_HP, compare )
64 typedef cc::MichaelList< gc_type, int_item,
65 typename cc::michael_list::make_traits<
66 cds::opt::compare< cmp >
70 typedef cc::MichaelHashSet< gc_type, list_type,
71 typename cc::michael_set::make_traits<
72 cds::opt::hash< hash_int >
76 set_type s( kSize, 2 );
80 TEST_F( MichaelSet_HP, less )
82 typedef cc::MichaelList< gc_type, int_item,
83 typename cc::michael_list::make_traits<
84 cds::opt::less< base_class::less >
88 typedef cc::MichaelHashSet< gc_type, list_type,
89 typename cc::michael_set::make_traits<
90 cds::opt::hash< hash_int >
94 set_type s( kSize, 2 );
98 TEST_F( MichaelSet_HP, cmpmix )
100 struct list_traits : public cc::michael_list::traits
102 typedef base_class::less less;
105 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
107 typedef cc::MichaelHashSet< gc_type, list_type,
108 typename cc::michael_set::make_traits<
109 cds::opt::hash< hash_int >
113 set_type s( kSize, 2 );
117 TEST_F( MichaelSet_HP, item_counting )
119 struct list_traits : public cc::michael_list::traits
123 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
125 struct set_traits: public cc::michael_set::traits
127 typedef hash_int hash;
128 typedef simple_item_counter item_counter;
130 typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
132 set_type s( kSize, 3 );
136 TEST_F( MichaelSet_HP, backoff )
138 struct list_traits : public cc::michael_list::traits
141 typedef cds::backoff::exponential<cds::backoff::pause, cds::backoff::yield> back_off;
143 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
145 struct set_traits : public cc::michael_set::traits
147 typedef hash_int hash;
148 typedef cds::atomicity::item_counter item_counter;
150 typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
152 set_type s( kSize, 4 );
156 TEST_F( MichaelSet_HP, seq_cst )
158 struct list_traits : public cc::michael_list::traits
160 typedef base_class::less less;
161 typedef cds::backoff::pause back_off;
162 typedef cds::opt::v::sequential_consistent memory_model;
164 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
166 struct set_traits : public cc::michael_set::traits
168 typedef hash_int hash;
169 typedef cds::atomicity::item_counter item_counter;
171 typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
173 set_type s( kSize, 4 );
177 TEST_F( MichaelSet_HP, stat )
179 struct list_traits: public cc::michael_list::traits
181 typedef base_class::less less;
182 typedef cds::backoff::pause back_off;
183 typedef cc::michael_list::stat<> stat;
185 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
187 struct set_traits: public cc::michael_set::traits
189 typedef hash_int hash;
190 typedef cds::atomicity::item_counter item_counter;
192 typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
194 set_type s( kSize, 4 );
196 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
199 TEST_F( MichaelSet_HP, wrapped_stat )
201 struct list_traits: public cc::michael_list::traits
203 typedef base_class::less less;
204 typedef cds::backoff::pause back_off;
205 typedef cc::michael_list::wrapped_stat<> stat;
207 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
209 struct set_traits: public cc::michael_set::traits
211 typedef hash_int hash;
212 typedef cds::atomicity::item_counter item_counter;
214 typedef cc::MichaelHashSet< gc_type, list_type, set_traits > set_type;
216 set_type s( kSize, 4 );
218 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );