c904eeb327b3f5d8190f759ccd3f34f478d65345
[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-2016
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
36 namespace {
37     namespace ci = cds::intrusive;
38     typedef cds::gc::HP gc_type;
39
40     class IntrusiveSplitListSet_HP : public cds_test::intrusive_set_hp
41     {
42     protected:
43         typedef cds_test::intrusive_set_hp base_class;
44
45     protected:
46         typedef typename base_class::base_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>>   base_item_type;
47         typedef typename base_class::member_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> member_item_type;
48
49         void SetUp()
50         {
51             struct list_traits : public ci::michael_list::traits
52             {
53                 typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
54             };
55             typedef ci::MichaelList< gc_type, base_item_type, list_traits > list_type;
56             typedef ci::SplitListSet< gc_type, list_type >   set_type;
57
58             // +1 - for guarded_ptr
59             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
60             cds::threading::Manager::attachThread();
61         }
62
63         void TearDown()
64         {
65             cds::threading::Manager::detachThread();
66             cds::gc::hp::GarbageCollector::Destruct( true );
67         }
68     };
69
70
71     TEST_F( IntrusiveSplitListSet_HP, base_cmp )
72     {
73         typedef ci::MichaelList< gc_type
74             , base_item_type
75             ,ci::michael_list::make_traits<
76                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
77                 ,ci::opt::compare< cmp<base_item_type> >
78                 ,ci::opt::disposer< mock_disposer >
79             >::type
80         > bucket_type;
81
82         typedef ci::SplitListSet< gc_type, bucket_type,
83             ci::split_list::make_traits<
84                 ci::opt::hash< hash_int >
85             >::type
86         > set_type;
87
88         set_type s( kSize, 2 );
89         test( s );
90     }
91
92     TEST_F( IntrusiveSplitListSet_HP, base_less )
93     {
94         typedef ci::MichaelList< gc_type
95             , base_item_type
96             ,ci::michael_list::make_traits<
97                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
98                 ,ci::opt::less< less<base_item_type> >
99                 ,ci::opt::disposer< mock_disposer >
100             >::type
101         > bucket_type;
102
103         typedef ci::SplitListSet< gc_type, bucket_type,
104             ci::split_list::make_traits<
105                 ci::opt::hash< hash_int >
106                 ,ci::opt::item_counter< cds::atomicity::item_counter >
107             >::type
108         > set_type;
109
110         set_type s( kSize, 2 );
111         test( s );
112     }
113
114     TEST_F( IntrusiveSplitListSet_HP, base_cmpmix )
115     {
116         struct list_traits : public ci::michael_list::traits
117         {
118             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
119             typedef base_class::less<base_item_type> less;
120             typedef cmp<base_item_type> compare;
121             typedef mock_disposer disposer;
122         };
123         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
124
125         struct set_traits : public ci::split_list::traits
126         {
127             typedef hash_int hash;
128             typedef simple_item_counter item_counter;
129             typedef ci::split_list::stat<> stat;
130         };
131         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
132
133         set_type s( kSize, 2 );
134         test( s );
135     }
136
137
138     TEST_F( IntrusiveSplitListSet_HP, member_cmp )
139     {
140         typedef ci::MichaelList< gc_type
141             ,member_item_type
142             ,ci::michael_list::make_traits<
143                 ci::opt::hook< ci::michael_list::member_hook<
144                     offsetof( member_item_type, hMember ),
145                     ci::opt::gc<gc_type>
146                 > >
147                 ,ci::opt::compare< cmp<member_item_type> >
148                 ,ci::opt::disposer< mock_disposer >
149             >::type
150         >    bucket_type;
151
152         typedef ci::SplitListSet< gc_type, bucket_type,
153             ci::split_list::make_traits<
154                 ci::opt::hash< hash_int >
155             >::type
156         > set_type;
157
158         set_type s( kSize, 2 );
159         test( s );
160     }
161
162     TEST_F( IntrusiveSplitListSet_HP, member_less )
163     {
164         typedef ci::MichaelList< gc_type
165             , member_item_type
166             ,ci::michael_list::make_traits<
167                 ci::opt::hook< ci::michael_list::member_hook<
168                     offsetof( member_item_type, hMember ),
169                     ci::opt::gc<gc_type>
170                 > >
171                 ,ci::opt::less< less<member_item_type> >
172                 ,ci::opt::disposer< mock_disposer >
173             >::type
174         > bucket_type;
175
176         typedef ci::SplitListSet< gc_type, bucket_type,
177             ci::split_list::make_traits<
178                 ci::opt::hash< hash_int >
179                 ,ci::opt::back_off< cds::backoff::pause >
180             >::type
181         > set_type;
182
183         set_type s( kSize, 2 );
184         test( s );
185     }
186
187     TEST_F( IntrusiveSplitListSet_HP, member_cmpmix )
188     {
189         struct list_traits : public ci::michael_list::traits
190         {
191             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
192             typedef base_class::less<member_item_type> less;
193             typedef cmp<member_item_type> compare;
194             typedef mock_disposer disposer;
195         };
196         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
197
198         struct set_traits : public ci::split_list::traits
199         {
200             typedef hash_int hash;
201             typedef simple_item_counter item_counter;
202         };
203         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
204
205         set_type s( kSize, 2 );
206         test( s );
207     }
208
209 } // namespace