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