Removed signal_threaded uRCU
[libcds.git] / test / unit / intrusive-set / intrusive_split_iterable_hp.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30
31 #include "test_intrusive_split_iterable_set_hp.h"
32
33 #include <cds/intrusive/iterable_list_hp.h>
34 #include <cds/intrusive/split_list.h>
35 #include <cds/intrusive/free_list.h>
36
37 namespace {
38     namespace ci = cds::intrusive;
39     typedef cds::gc::HP gc_type;
40
41     class IntrusiveSplitListIterableSet_HP : public cds_test::intrusive_split_iterable_set_hp
42     {
43     protected:
44         typedef cds_test::intrusive_split_iterable_set_hp base_class;
45         typedef base_class::item_type< ci::split_list::node<void>> item_type;
46
47     protected:
48         void SetUp()
49         {
50             struct list_traits : public ci::iterable_list::traits
51             {};
52             typedef ci::IterableList< gc_type, item_type, list_traits > list_type;
53             typedef ci::SplitListSet< gc_type, list_type >   set_type;
54
55             // +3 - for iterators
56             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 3, 1, 16 );
57             cds::threading::Manager::attachThread();
58         }
59
60         void TearDown()
61         {
62             cds::threading::Manager::detachThread();
63             cds::gc::hp::GarbageCollector::Destruct( true );
64         }
65     };
66
67
68     TEST_F( IntrusiveSplitListIterableSet_HP, cmp )
69     {
70         typedef ci::IterableList< gc_type
71             , item_type
72             ,ci::iterable_list::make_traits<
73                 ci::opt::compare< cmp<item_type> >
74                 ,ci::opt::disposer< mock_disposer >
75             >::type
76         > bucket_type;
77
78         typedef ci::SplitListSet< gc_type, bucket_type,
79             ci::split_list::make_traits<
80                 ci::opt::hash< hash_int >
81             >::type
82         > set_type;
83
84         set_type s( kSize, 2 );
85         test( s );
86     }
87
88     TEST_F( IntrusiveSplitListIterableSet_HP, less )
89     {
90         typedef ci::IterableList< gc_type
91             , item_type
92             ,ci::iterable_list::make_traits<
93                 ci::opt::less< less<item_type> >
94                 ,ci::opt::disposer< mock_disposer >
95             >::type
96         > bucket_type;
97
98         typedef ci::SplitListSet< gc_type, bucket_type,
99             ci::split_list::make_traits<
100                 ci::opt::hash< hash_int >
101             >::type
102         > set_type;
103
104         set_type s( kSize, 2 );
105         test( s );
106     }
107
108     TEST_F( IntrusiveSplitListIterableSet_HP, cmpmix )
109     {
110         struct list_traits : public ci::iterable_list::traits
111         {
112             typedef base_class::less<item_type> less;
113             typedef cmp<item_type> compare;
114             typedef mock_disposer disposer;
115         };
116         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
117
118         struct set_traits : public ci::split_list::traits
119         {
120             typedef hash_int hash;
121             typedef simple_item_counter item_counter;
122         };
123         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
124
125         set_type s( kSize, 2 );
126         test( s );
127     }
128
129     TEST_F( IntrusiveSplitListIterableSet_HP, free_list )
130     {
131         struct list_traits: public ci::iterable_list::traits
132         {
133             typedef base_class::less<item_type> less;
134             typedef cmp<item_type> compare;
135             typedef mock_disposer disposer;
136         };
137         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
138
139         struct set_traits: public ci::split_list::traits
140         {
141             typedef hash_int hash;
142             typedef ci::FreeList  free_list;
143         };
144         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
145
146         set_type s( kSize, 2 );
147         test( s );
148     }
149
150     TEST_F( IntrusiveSplitListIterableSet_HP, static_bucket_table )
151     {
152         struct list_traits: public ci::iterable_list::traits
153         {
154             typedef base_class::less<item_type> less;
155             typedef cmp<item_type> compare;
156             typedef mock_disposer disposer;
157         };
158         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
159
160         struct set_traits: public ci::split_list::traits
161         {
162             typedef hash_int hash;
163             enum {
164                 dynamic_bucket_table = false
165             };
166         };
167         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
168
169         set_type s( kSize, 2 );
170         test( s );
171     }
172
173     TEST_F( IntrusiveSplitListIterableSet_HP, static_bucket_table_free_list )
174     {
175         struct list_traits: public ci::iterable_list::traits
176         {
177             typedef base_class::less<item_type> less;
178             typedef cmp<item_type> compare;
179             typedef mock_disposer disposer;
180         };
181         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
182
183         struct set_traits: public ci::split_list::traits
184         {
185             typedef hash_int hash;
186             enum {
187                 dynamic_bucket_table = false
188             };
189             typedef ci::FreeList free_list;
190         };
191         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
192
193         set_type s( kSize, 2 );
194         test( s );
195     }
196
197     TEST_F( IntrusiveSplitListIterableSet_HP, list_stat )
198     {
199         struct list_traits: public ci::iterable_list::traits
200         {
201             typedef base_class::less<item_type> less;
202             typedef cmp<item_type> compare;
203             typedef mock_disposer disposer;
204             typedef ci::iterable_list::stat<> stat;
205         };
206         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
207
208         struct set_traits: public ci::split_list::traits
209         {
210             typedef hash_int hash;
211             typedef simple_item_counter item_counter;
212         };
213         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
214
215         set_type s( kSize, 2 );
216         test( s );
217         EXPECT_GE( s.list_statistics().m_nInsertSuccess, 0u );
218     }
219
220     TEST_F( IntrusiveSplitListIterableSet_HP, stat )
221     {
222         struct list_traits: public ci::iterable_list::traits
223         {
224             typedef base_class::less<item_type> less;
225             typedef cmp<item_type> compare;
226             typedef mock_disposer disposer;
227         };
228         typedef ci::IterableList< gc_type, item_type, list_traits > bucket_type;
229
230         struct set_traits: public ci::split_list::traits
231         {
232             typedef hash_int hash;
233             typedef simple_item_counter item_counter;
234             typedef ci::split_list::stat<> stat;
235         };
236         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
237
238         set_type s( kSize, 2 );
239         test( s );
240         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
241     }
242
243     TEST_F( IntrusiveSplitListIterableSet_HP, derived_list )
244     {
245         class bucket_type: public ci::IterableList< gc_type
246             , item_type
247             ,ci::iterable_list::make_traits<
248                 ci::opt::compare< cmp<item_type> >
249                 ,ci::opt::disposer< mock_disposer >
250             >::type
251         >
252         {};
253
254         typedef ci::SplitListSet< gc_type, bucket_type,
255             ci::split_list::make_traits<
256                 ci::opt::hash< hash_int >
257             >::type
258         > set_type;
259
260         set_type s( kSize, 2 );
261         test( s );
262     }
263
264
265 } // namespace