Updated copyright
[libcds.git] / test / unit / intrusive-set / intrusive_split_michael_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_set_hp.h"
32
33 #include <cds/intrusive/michael_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 IntrusiveSplitListSet_HP : public cds_test::intrusive_set_hp
42     {
43     protected:
44         typedef cds_test::intrusive_set_hp base_class;
45
46     protected:
47         typedef typename base_class::base_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>>   base_item_type;
48         typedef typename base_class::member_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> member_item_type;
49
50         void SetUp()
51         {
52             struct list_traits : public ci::michael_list::traits
53             {
54                 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
55             };
56             typedef ci::MichaelList< gc_type, base_item_type, list_traits > list_type;
57             typedef ci::SplitListSet< gc_type, list_type >   set_type;
58
59             // +1 - for guarded_ptr
60             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
61             cds::threading::Manager::attachThread();
62         }
63
64         void TearDown()
65         {
66             cds::threading::Manager::detachThread();
67             cds::gc::hp::GarbageCollector::Destruct( true );
68         }
69     };
70
71
72     TEST_F( IntrusiveSplitListSet_HP, base_cmp )
73     {
74         typedef ci::MichaelList< gc_type
75             , base_item_type
76             ,ci::michael_list::make_traits<
77                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
78                 ,ci::opt::compare< cmp<base_item_type> >
79                 ,ci::opt::disposer< mock_disposer >
80             >::type
81         > bucket_type;
82
83         typedef ci::SplitListSet< gc_type, bucket_type,
84             ci::split_list::make_traits<
85                 ci::opt::hash< hash_int >
86             >::type
87         > set_type;
88
89         set_type s( kSize, 2 );
90         test( s );
91     }
92
93     TEST_F( IntrusiveSplitListSet_HP, base_less )
94     {
95         typedef ci::MichaelList< gc_type
96             , base_item_type
97             ,ci::michael_list::make_traits<
98                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
99                 ,ci::opt::less< less<base_item_type> >
100                 ,ci::opt::disposer< mock_disposer >
101             >::type
102         > bucket_type;
103
104         typedef ci::SplitListSet< gc_type, bucket_type,
105             ci::split_list::make_traits<
106                 ci::opt::hash< hash_int >
107                 ,ci::opt::item_counter< cds::atomicity::item_counter >
108             >::type
109         > set_type;
110
111         set_type s( kSize, 2 );
112         test( s );
113     }
114
115     TEST_F( IntrusiveSplitListSet_HP, base_cmpmix )
116     {
117         struct list_traits : public ci::michael_list::traits
118         {
119             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
120             typedef base_class::less<base_item_type> less;
121             typedef cmp<base_item_type> compare;
122             typedef mock_disposer disposer;
123         };
124         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
125
126         struct set_traits : public ci::split_list::traits
127         {
128             typedef hash_int hash;
129             typedef simple_item_counter item_counter;
130             typedef ci::split_list::stat<> stat;
131         };
132         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
133
134         set_type s( kSize, 2 );
135         test( s );
136     }
137
138     TEST_F( IntrusiveSplitListSet_HP, base_static_bucket_table )
139     {
140         struct list_traits: public ci::michael_list::traits
141         {
142             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
143             typedef base_class::less<base_item_type> less;
144             typedef cmp<base_item_type> compare;
145             typedef mock_disposer disposer;
146         };
147         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
148
149         struct set_traits: public ci::split_list::traits
150         {
151             typedef hash_int hash;
152             typedef simple_item_counter item_counter;
153             typedef ci::split_list::stat<> stat;
154             enum {
155                 dynamic_bucket_table = false
156             };
157         };
158         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
159
160         set_type s( kSize, 2 );
161         test( s );
162     }
163
164     TEST_F( IntrusiveSplitListSet_HP, base_static_bucket_table_free_list )
165     {
166         struct list_traits: public ci::michael_list::traits
167         {
168             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
169             typedef base_class::less<base_item_type> less;
170             typedef mock_disposer disposer;
171         };
172         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
173
174         struct set_traits: public ci::split_list::traits
175         {
176             typedef hash_int hash;
177             typedef simple_item_counter item_counter;
178             typedef ci::split_list::stat<> stat;
179             enum {
180                 dynamic_bucket_table = false
181             };
182             typedef ci::FreeList free_list;
183         };
184         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
185
186         set_type s( kSize, 2 );
187         test( s );
188     }
189
190     TEST_F( IntrusiveSplitListSet_HP, base_free_list )
191     {
192         struct list_traits: public ci::michael_list::traits
193         {
194             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
195             typedef cmp<base_item_type> compare;
196             typedef mock_disposer disposer;
197         };
198         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
199
200         struct set_traits: public ci::split_list::traits
201         {
202             typedef hash_int hash;
203             typedef simple_item_counter item_counter;
204             typedef ci::split_list::stat<> stat;
205             typedef ci::FreeList free_list;
206         };
207         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
208
209         set_type s( kSize, 2 );
210         test( s );
211     }
212
213
214     TEST_F( IntrusiveSplitListSet_HP, member_cmp )
215     {
216         typedef ci::MichaelList< gc_type
217             ,member_item_type
218             ,ci::michael_list::make_traits<
219                 ci::opt::hook< ci::michael_list::member_hook<
220                     offsetof( member_item_type, hMember ),
221                     ci::opt::gc<gc_type>
222                 > >
223                 ,ci::opt::compare< cmp<member_item_type> >
224                 ,ci::opt::disposer< mock_disposer >
225             >::type
226         >    bucket_type;
227
228         typedef ci::SplitListSet< gc_type, bucket_type,
229             ci::split_list::make_traits<
230                 ci::opt::hash< hash_int >
231             >::type
232         > set_type;
233
234         set_type s( kSize, 2 );
235         test( s );
236     }
237
238     TEST_F( IntrusiveSplitListSet_HP, member_less )
239     {
240         typedef ci::MichaelList< gc_type
241             , member_item_type
242             ,ci::michael_list::make_traits<
243                 ci::opt::hook< ci::michael_list::member_hook<
244                     offsetof( member_item_type, hMember ),
245                     ci::opt::gc<gc_type>
246                 > >
247                 ,ci::opt::less< less<member_item_type> >
248                 ,ci::opt::disposer< mock_disposer >
249             >::type
250         > bucket_type;
251
252         typedef ci::SplitListSet< gc_type, bucket_type,
253             ci::split_list::make_traits<
254                 ci::opt::hash< hash_int >
255                 ,ci::opt::back_off< cds::backoff::pause >
256             >::type
257         > set_type;
258
259         set_type s( kSize, 2 );
260         test( s );
261     }
262
263     TEST_F( IntrusiveSplitListSet_HP, member_cmpmix )
264     {
265         struct list_traits : public ci::michael_list::traits
266         {
267             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
268             typedef base_class::less<member_item_type> less;
269             typedef cmp<member_item_type> compare;
270             typedef mock_disposer disposer;
271         };
272         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
273
274         struct set_traits : public ci::split_list::traits
275         {
276             typedef hash_int hash;
277             typedef simple_item_counter item_counter;
278         };
279         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
280
281         set_type s( kSize, 2 );
282         test( s );
283     }
284
285     TEST_F( IntrusiveSplitListSet_HP, member_static_bucket_table )
286     {
287         struct list_traits: public ci::michael_list::traits
288         {
289             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
290             typedef base_class::less<member_item_type> less;
291             typedef cmp<member_item_type> compare;
292             typedef mock_disposer disposer;
293         };
294         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
295
296         struct set_traits: public ci::split_list::traits
297         {
298             typedef hash_int hash;
299             typedef simple_item_counter item_counter;
300             enum {
301                 dynamic_bucket_table = false
302             };
303         };
304         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
305
306         set_type s( kSize, 2 );
307         test( s );
308     }
309
310     TEST_F( IntrusiveSplitListSet_HP, member_static_bucket_table_free_list )
311     {
312         struct list_traits: public ci::michael_list::traits
313         {
314             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
315             typedef cmp<member_item_type> compare;
316             typedef mock_disposer disposer;
317         };
318         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
319
320         struct set_traits: public ci::split_list::traits
321         {
322             typedef hash_int hash;
323             typedef simple_item_counter item_counter;
324             enum {
325                 dynamic_bucket_table = false
326             };
327             typedef ci::FreeList free_list;
328         };
329         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
330
331         set_type s( kSize, 2 );
332         test( s );
333     }
334
335     TEST_F( IntrusiveSplitListSet_HP, member_free_list )
336     {
337         struct list_traits: public ci::michael_list::traits
338         {
339             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
340             typedef base_class::less<member_item_type> less;
341             typedef mock_disposer disposer;
342         };
343         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
344
345         struct set_traits: public ci::split_list::traits
346         {
347             typedef hash_int hash;
348             typedef simple_item_counter item_counter;
349             typedef ci::FreeList free_list;
350         };
351         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
352
353         set_type s( kSize, 2 );
354         test( s );
355     }
356
357 } // namespace