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_dhp.h>
34 #include <cds/container/michael_set.h>
37 namespace cc = cds::container;
38 typedef cds::gc::DHP gc_type;
40 class MichaelSet_DHP : 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 cds::gc::dhp::smr::construct( set_type::c_nHazardPtrCount );
51 cds::threading::Manager::attachThread();
56 cds::threading::Manager::detachThread();
57 cds::gc::dhp::smr::destruct();
61 TEST_F( MichaelSet_DHP, compare )
63 typedef cc::MichaelList< gc_type, int_item,
64 typename cc::michael_list::make_traits<
65 cds::opt::compare< cmp >
69 typedef cc::MichaelHashSet< gc_type, list_type,
70 typename cc::michael_set::make_traits<
71 cds::opt::hash< hash_int >
75 set_type s( kSize, 2 );
79 TEST_F( MichaelSet_DHP, less )
81 typedef cc::MichaelList< gc_type, int_item,
82 typename cc::michael_list::make_traits<
83 cds::opt::less< base_class::less >
87 typedef cc::MichaelHashSet< gc_type, list_type,
88 typename cc::michael_set::make_traits<
89 cds::opt::hash< hash_int >
93 set_type s( kSize, 2 );
97 TEST_F( MichaelSet_DHP, cmpmix )
99 struct list_traits : public cc::michael_list::traits
101 typedef base_class::less less;
104 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
106 typedef cc::MichaelHashSet< gc_type, list_type,
107 typename cc::michael_set::make_traits<
108 cds::opt::hash< hash_int >
112 set_type s( kSize, 2 );
116 TEST_F( MichaelSet_DHP, item_counting )
118 struct list_traits : public cc::michael_list::traits
122 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
124 struct set_traits: public cc::michael_set::traits
126 typedef hash_int hash;
127 typedef simple_item_counter item_counter;
129 typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
131 set_type s( kSize, 3 );
135 TEST_F( MichaelSet_DHP, backoff )
137 struct list_traits : public cc::michael_list::traits
140 typedef cds::backoff::make_exponential_t<cds::backoff::pause, cds::backoff::yield> back_off;
142 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
144 struct set_traits : public cc::michael_set::traits
146 typedef hash_int hash;
147 typedef cds::atomicity::item_counter item_counter;
149 typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
151 set_type s( kSize, 4 );
155 TEST_F( MichaelSet_DHP, seq_cst )
157 struct list_traits : public cc::michael_list::traits
159 typedef base_class::less less;
160 typedef cds::backoff::pause back_off;
161 typedef cds::opt::v::sequential_consistent memory_model;
163 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
165 struct set_traits : public cc::michael_set::traits
167 typedef hash_int hash;
168 typedef cds::atomicity::item_counter item_counter;
170 typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
172 set_type s( kSize, 4 );
176 TEST_F( MichaelSet_DHP, stat )
178 struct list_traits: public cc::michael_list::traits
180 typedef base_class::less less;
181 typedef cds::backoff::pause back_off;
182 typedef cc::michael_list::stat<> stat;
184 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
186 struct set_traits: public cc::michael_set::traits
188 typedef hash_int hash;
189 typedef cds::atomicity::item_counter item_counter;
191 typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
193 set_type s( kSize, 4 );
195 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
198 TEST_F( MichaelSet_DHP, wrapped_stat )
200 struct list_traits: public cc::michael_list::traits
202 typedef base_class::less less;
203 typedef cds::backoff::pause back_off;
204 typedef cc::michael_list::wrapped_stat<> stat;
206 typedef cc::MichaelList< gc_type, int_item, list_traits > list_type;
208 struct set_traits: public cc::michael_set::traits
210 typedef hash_int hash;
211 typedef cds::atomicity::item_counter item_counter;
213 typedef cc::MichaelHashSet< gc_type, list_type, set_traits >set_type;
215 set_type s( kSize, 4 );
217 EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );