Removed trailing spaces
[libcds.git] / test / unit / list / 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_list_hp.h"
32 #include <cds/container/michael_list_hp.h>
33
34 namespace {
35     namespace cc = cds::container;
36     typedef cds::gc::HP gc_type;
37
38     class MichaelList_HP : public cds_test::list_hp
39     {
40     protected:
41         void SetUp()
42         {
43             typedef cc::MichaelList< gc_type, item > list_type;
44
45             // +1 - for guarded_ptr
46             cds::gc::hp::GarbageCollector::Construct( list_type::c_nHazardPtrCount + 1, 1, 16 );
47             cds::threading::Manager::attachThread();
48         }
49
50         void TearDown()
51         {
52             cds::threading::Manager::detachThread();
53             cds::gc::hp::GarbageCollector::Destruct( true );
54         }
55     };
56
57     TEST_F( MichaelList_HP, less_ordered )
58     {
59         typedef cc::MichaelList< gc_type, item,
60             typename cc::michael_list::make_traits<
61                 cds::opt::less< lt<item> >
62             >::type
63         > list_type;
64
65         list_type l;
66         test_common( l );
67         test_ordered_iterator( l );
68         test_hp( l );
69     }
70
71     TEST_F( MichaelList_HP, compare_ordered )
72     {
73         typedef cc::MichaelList< gc_type, item,
74             typename cc::michael_list::make_traits<
75                 cds::opt::compare< cmp<item> >
76             >::type
77         > list_type;
78
79         list_type l;
80         test_common( l );
81         test_ordered_iterator( l );
82         test_hp( l );
83     }
84
85     TEST_F( MichaelList_HP, mix_ordered )
86     {
87         typedef cc::MichaelList< gc_type, item,
88             typename cc::michael_list::make_traits<
89                 cds::opt::compare< cmp<item> >
90                 ,cds::opt::less< lt<item> >
91             >::type
92         > list_type;
93
94         list_type l;
95         test_common( l );
96         test_ordered_iterator( l );
97         test_hp( l );
98     }
99
100     TEST_F( MichaelList_HP, item_counting )
101     {
102         struct traits : public cc::michael_list::traits
103         {
104             typedef lt<item> less;
105             typedef cds::atomicity::item_counter item_counter;
106         };
107         typedef cc::MichaelList<gc_type, item, traits > list_type;
108
109         list_type l;
110         test_common( l );
111         test_ordered_iterator( l );
112         test_hp( l );
113     }
114
115     TEST_F( MichaelList_HP, backoff )
116     {
117         struct traits : public cc::michael_list::traits
118         {
119             typedef lt<item> less;
120             typedef cds::atomicity::item_counter item_counter;
121             typedef cds::backoff::empty back_off;
122         };
123         typedef cc::MichaelList<gc_type, 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( MichaelList_HP, seq_cst )
132     {
133         struct traits : public cc::michael_list::traits
134         {
135             typedef lt<item> less;
136             typedef cds::atomicity::item_counter item_counter;
137             typedef cds::opt::v::sequential_consistent memory_model;
138         };
139         typedef cc::MichaelList<gc_type, item, traits > list_type;
140
141         list_type l;
142         test_common( l );
143         test_ordered_iterator( l );
144         test_hp( l );
145     }
146
147     TEST_F( MichaelList_HP, stat )
148     {
149         struct traits: public cc::michael_list::traits
150         {
151             typedef lt<item> less;
152             typedef cds::atomicity::item_counter item_counter;
153             typedef cds::container::michael_list::stat<> stat;
154
155         };
156         typedef cc::MichaelList<gc_type, item, traits > list_type;
157
158         list_type l;
159         test_common( l );
160         test_ordered_iterator( l );
161         test_hp( l );
162     }
163
164     TEST_F( MichaelList_HP, wrapped_stat )
165     {
166         struct traits: public cc::michael_list::traits
167         {
168             typedef lt<item> less;
169             typedef cds::atomicity::item_counter item_counter;
170             typedef cds::container::michael_list::wrapped_stat<> stat;
171
172         };
173         typedef cc::MichaelList<gc_type, item, traits > list_type;
174
175         cds::container::michael_list::stat<> st;
176         list_type l( st );
177         test_common( l );
178         test_ordered_iterator( l );
179         test_hp( l );
180     }
181
182 } // namespace