d6de7f051838efd8460c98b271df52f49e8ab908
[libcds.git] / test / unit / list / intrusive_michael_dhp.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_list_hp.h"
32 #include <cds/intrusive/michael_list_dhp.h>
33
34 namespace {
35     namespace ci = cds::intrusive;
36     typedef cds::gc::DHP gc_type;
37
38     class IntrusiveMichaelList_DHP : public cds_test::intrusive_list_hp
39     {
40     public:
41         typedef cds_test::intrusive_list_hp::base_item< ci::michael_list::node< gc_type>> base_item;
42         typedef cds_test::intrusive_list_hp::member_item< ci::michael_list::node< gc_type>> member_item;
43
44     protected:
45         void SetUp()
46         {
47             struct traits: public ci::michael_list::traits
48             {
49                 typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
50             };
51             typedef ci::MichaelList< gc_type, base_item, traits > list_type;
52
53             cds::gc::dhp::GarbageCollector::Construct( 16, list_type::c_nHazardPtrCount );
54             cds::threading::Manager::attachThread();
55         }
56
57         void TearDown()
58         {
59             cds::threading::Manager::detachThread();
60             cds::gc::hp::GarbageCollector::Destruct();
61         }
62     };
63
64     TEST_F( IntrusiveMichaelList_DHP, base_hook )
65     {
66         typedef ci::MichaelList< gc_type, base_item,
67             typename ci::michael_list::make_traits< 
68                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
69                 ,ci::opt::disposer< mock_disposer >
70                 ,cds::opt::less< less< base_item >>
71             >::type 
72        > list_type;
73
74        list_type l;
75        test_common( l );
76        test_ordered_iterator( l );
77        test_hp( l );
78     }
79
80     TEST_F( IntrusiveMichaelList_DHP, base_hook_cmp )
81     {
82         typedef ci::MichaelList< gc_type, base_item,
83             typename ci::michael_list::make_traits<
84                 ci::opt::hook< ci::michael_list::base_hook< cds::opt::gc< gc_type >>>
85                 , ci::opt::disposer< mock_disposer >
86                 , cds::opt::compare< cmp< base_item >>
87             >::type
88         > list_type;
89
90         list_type l;
91         test_common( l );
92         test_ordered_iterator( l );
93         test_hp( l );
94     }
95
96     TEST_F( IntrusiveMichaelList_DHP, base_hook_item_counting )
97     {
98         struct traits : public ci::michael_list::traits {
99             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
100             typedef mock_disposer disposer;
101             typedef cmp< base_item > compare;
102             typedef intrusive_list_common::less< base_item > less;
103             typedef cds::atomicity::item_counter item_counter;
104         };
105         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
106
107         list_type l;
108         test_common( l );
109         test_ordered_iterator( l );
110         test_hp( l );
111     }
112
113     TEST_F( IntrusiveMichaelList_DHP, base_hook_backoff )
114     {
115         struct traits : public ci::michael_list::traits {
116             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
117             typedef mock_disposer disposer;
118             typedef cmp< base_item > compare;
119             typedef intrusive_list_common::less< base_item > less;
120             typedef cds::atomicity::item_counter item_counter;
121             typedef cds::backoff::pause back_off;
122         };
123         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
124
125         list_type l;
126         test_common( l );
127         test_ordered_iterator( l );
128         test_hp( l );
129     }
130
131     TEST_F( IntrusiveMichaelList_DHP, base_hook_seqcst )
132     {
133         struct traits : public ci::michael_list::traits {
134             typedef ci::michael_list::base_hook< cds::opt::gc< gc_type >> hook;
135             typedef mock_disposer disposer;
136             typedef cmp< base_item > compare;
137             typedef intrusive_list_common::less< base_item > less;
138             typedef cds::atomicity::item_counter item_counter;
139             typedef cds::opt::v::sequential_consistent memory_model;
140         };
141         typedef ci::MichaelList< gc_type, base_item, traits > list_type;
142
143         list_type l;
144         test_common( l );
145         test_ordered_iterator( l );
146         test_hp( l );
147     }
148
149     TEST_F( IntrusiveMichaelList_DHP, member_hook )
150     {
151         typedef ci::MichaelList< gc_type, member_item,
152             typename ci::michael_list::make_traits< 
153                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
154                 ,ci::opt::disposer< mock_disposer >
155                 ,cds::opt::less< less< member_item >>
156             >::type 
157        > list_type;
158
159        list_type l;
160        test_common( l );
161        test_ordered_iterator( l );
162        test_hp( l );
163     }
164
165     TEST_F( IntrusiveMichaelList_DHP, member_hook_cmp )
166     {
167         typedef ci::MichaelList< gc_type, member_item,
168             typename ci::michael_list::make_traits<
169                 ci::opt::hook< ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >>>
170                 ,ci::opt::disposer< mock_disposer >
171                 ,cds::opt::compare< cmp< member_item >>
172             >::type
173         > list_type;
174
175         list_type l;
176         test_common( l );
177         test_ordered_iterator( l );
178         test_hp( l );
179     }
180
181     TEST_F( IntrusiveMichaelList_DHP, member_hook_item_counting )
182     {
183         struct traits : public ci::michael_list::traits {
184             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
185             typedef mock_disposer disposer;
186             typedef cmp< member_item > compare;
187             typedef intrusive_list_common::less< member_item > less;
188             typedef cds::atomicity::item_counter item_counter;
189         };
190         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
191
192         list_type l;
193         test_common( l );
194         test_ordered_iterator( l );
195         test_hp( l );
196     }
197
198     TEST_F( IntrusiveMichaelList_DHP, member_hook_seqcst )
199     {
200         struct traits : public ci::michael_list::traits {
201             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
202             typedef mock_disposer disposer;
203             typedef cmp< member_item > compare;
204             typedef intrusive_list_common::less< member_item > less;
205             typedef cds::atomicity::item_counter item_counter;
206             typedef cds::opt::v::sequential_consistent memory_model;
207         };
208         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
209
210         list_type l;
211         test_common( l );
212         test_ordered_iterator( l );
213         test_hp( l );
214     }
215
216     TEST_F( IntrusiveMichaelList_DHP, member_hook_back_off )
217     {
218         struct traits : public ci::michael_list::traits {
219             typedef ci::michael_list::member_hook< offsetof( member_item, hMember ), cds::opt::gc< gc_type >> hook;
220             typedef mock_disposer disposer;
221             typedef cmp< member_item > compare;
222             typedef intrusive_list_common::less< member_item > less;
223             typedef cds::atomicity::item_counter item_counter;
224             typedef cds::backoff::empty back_off;
225         };
226         typedef ci::MichaelList< gc_type, member_item, traits > list_type;
227
228         list_type l;
229         test_common( l );
230         test_ordered_iterator( l );
231         test_hp( l );
232     }
233
234 } // namespace