Added copyright and license
[libcds.git] / tests / test-hdr / stack / hdr_intrusive_elimination_stack_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 "hdr_intrusive_treiber_stack.h"
32 #include <cds/gc/hp.h>
33 #include <cds/intrusive/treiber_stack.h>
34
35 namespace stack {
36
37 #define TEST(X)     void TestIntrusiveStack::X() { test<defs::X>(); }
38 #define TEST_DYN(X)     void TestIntrusiveStack::X() { test_elimination<defs::X>(); }
39
40     namespace defs {
41         typedef cds::intrusive::TreiberStack< cds::gc::HP,
42             TestIntrusiveStack::base_hook_item<cds::gc::HP>
43             , typename ci::treiber_stack::make_traits<
44                 cds::opt::enable_elimination<true>
45             >::type
46         > Elimination_HP_default;
47
48         typedef cds::intrusive::TreiberStack< cds::gc::HP,
49             TestIntrusiveStack::base_hook_item<cds::gc::HP>
50             , typename ci::treiber_stack::make_traits<
51                 cds::opt::enable_elimination<true>
52                 ,ci::opt::memory_model< ci::opt::v::relaxed_ordering >
53             >::type
54         > Elimination_HP_default_relaxed;
55
56         // HZP GC + base hook
57         typedef cds::intrusive::TreiberStack< cds::gc::HP,
58             TestIntrusiveStack::base_hook_item<cds::gc::HP>
59             , typename ci::treiber_stack::make_traits<
60                 cds::opt::enable_elimination<true>
61                 ,ci::opt::hook<
62                     ci::treiber_stack::base_hook<
63                         ci::opt::gc<cds::gc::HP>
64                     >
65                 >
66             >::type
67         > Elimination_HP_base;
68
69         typedef cds::intrusive::TreiberStack< cds::gc::HP,
70             TestIntrusiveStack::base_hook_item<cds::gc::HP>
71             , typename ci::treiber_stack::make_traits<
72                 cds::opt::enable_elimination<true>
73                 ,ci::opt::hook<
74                     ci::treiber_stack::base_hook<
75                         ci::opt::gc<cds::gc::HP>
76                     >
77                 >
78                 ,ci::opt::buffer< ci::opt::v::dynamic_buffer<void *> >
79             >::type
80         > Elimination_HP_base_dyn;
81
82         typedef cds::intrusive::TreiberStack< cds::gc::HP,
83             TestIntrusiveStack::base_hook_item<cds::gc::HP>
84             , typename ci::treiber_stack::make_traits<
85                 cds::opt::enable_elimination<true>
86                 ,ci::opt::hook<
87                     ci::treiber_stack::base_hook<
88                         ci::opt::gc<cds::gc::HP>
89                     >
90                 >
91                 ,ci::opt::memory_model< ci::opt::v::relaxed_ordering >
92             >::type
93         > Elimination_HP_base_relaxed;
94
95         // HZP GC + base hook + disposer
96         typedef cds::intrusive::TreiberStack< cds::gc::HP,
97             TestIntrusiveStack::base_hook_item<cds::gc::HP>
98             , typename ci::treiber_stack::make_traits<
99                 cds::opt::enable_elimination<true>
100                 ,ci::opt::hook<
101                     ci::treiber_stack::base_hook< ci::opt::gc<cds::gc::HP> >
102                 >
103                 ,ci::opt::disposer< TestIntrusiveStack::faked_disposer >
104             >::type
105         > Elimination_HP_base_disposer;
106
107         typedef cds::intrusive::TreiberStack< cds::gc::HP,
108             TestIntrusiveStack::base_hook_item<cds::gc::HP>
109             , typename ci::treiber_stack::make_traits<
110                 cds::opt::enable_elimination<true>
111                 ,ci::opt::hook<
112                     ci::treiber_stack::base_hook< ci::opt::gc<cds::gc::HP> >
113                 >
114                 ,ci::opt::disposer< TestIntrusiveStack::faked_disposer >
115                 ,ci::opt::memory_model< ci::opt::v::relaxed_ordering >
116             >::type
117         > Elimination_HP_base_disposer_relaxed;
118
119         // HZP GC + member hook
120         typedef cds::intrusive::TreiberStack< cds::gc::HP,
121             TestIntrusiveStack::member_hook_item<cds::gc::HP>
122             , typename ci::treiber_stack::make_traits<
123                 cds::opt::enable_elimination<true>
124                 ,ci::opt::hook<
125                     ci::treiber_stack::member_hook<
126                         offsetof(TestIntrusiveStack::member_hook_item<cds::gc::HP>, hMember),
127                         ci::opt::gc<cds::gc::HP>
128                     >
129                 >
130             >::type
131         > Elimination_HP_member;
132
133         typedef cds::intrusive::TreiberStack< cds::gc::HP,
134             TestIntrusiveStack::member_hook_item<cds::gc::HP>
135             , typename ci::treiber_stack::make_traits<
136                 cds::opt::enable_elimination<true>
137                 ,ci::opt::hook<
138                     ci::treiber_stack::member_hook<
139                         offsetof(TestIntrusiveStack::member_hook_item<cds::gc::HP>, hMember),
140                         ci::opt::gc<cds::gc::HP>
141                     >
142                 >
143                 ,ci::opt::buffer< ci::opt::v::dynamic_buffer<void *> >
144             >::type
145         > Elimination_HP_member_dyn;
146
147         typedef cds::intrusive::TreiberStack< cds::gc::HP,
148             TestIntrusiveStack::member_hook_item<cds::gc::HP>
149             , typename ci::treiber_stack::make_traits<
150                 cds::opt::enable_elimination<true>
151                 ,ci::opt::hook<
152                     ci::treiber_stack::member_hook<
153                         offsetof(TestIntrusiveStack::member_hook_item<cds::gc::HP>, hMember),
154                         ci::opt::gc<cds::gc::HP>
155                     >
156                 >
157                 ,ci::opt::memory_model< ci::opt::v::relaxed_ordering >
158             >::type
159         > Elimination_HP_member_relaxed;
160
161         // HZP GC + member hook + disposer
162         typedef cds::intrusive::TreiberStack< cds::gc::HP,
163             TestIntrusiveStack::member_hook_item<cds::gc::HP>
164             , typename ci::treiber_stack::make_traits<
165                 cds::opt::enable_elimination<true>
166                 ,ci::opt::hook<
167                     ci::treiber_stack::member_hook<
168                         offsetof(TestIntrusiveStack::member_hook_item<cds::gc::HP>, hMember),
169                         ci::opt::gc<cds::gc::HP>
170                     >
171                 >
172                 ,ci::opt::disposer< TestIntrusiveStack::faked_disposer >
173             >::type
174         > Elimination_HP_member_disposer;
175
176         typedef cds::intrusive::TreiberStack< cds::gc::HP,
177             TestIntrusiveStack::member_hook_item<cds::gc::HP>
178             , typename ci::treiber_stack::make_traits<
179                 cds::opt::enable_elimination<true>
180                 ,ci::opt::hook<
181                     ci::treiber_stack::member_hook<
182                         offsetof(TestIntrusiveStack::member_hook_item<cds::gc::HP>, hMember),
183                         ci::opt::gc<cds::gc::HP>
184                     >
185                 >
186                 ,ci::opt::disposer< TestIntrusiveStack::faked_disposer >
187                 ,ci::opt::memory_model< ci::opt::v::relaxed_ordering >
188             >::type
189         > Elimination_HP_member_disposer_relaxed;
190     }
191
192     TEST(Elimination_HP_default)
193     TEST(Elimination_HP_base)
194     TEST_DYN(Elimination_HP_base_dyn)
195     TEST(Elimination_HP_base_disposer)
196     TEST(Elimination_HP_member)
197     TEST_DYN(Elimination_HP_member_dyn)
198     TEST(Elimination_HP_member_disposer)
199
200     TEST(Elimination_HP_default_relaxed)
201     TEST(Elimination_HP_base_relaxed)
202     TEST(Elimination_HP_base_disposer_relaxed)
203     TEST(Elimination_HP_member_relaxed)
204     TEST(Elimination_HP_member_disposer_relaxed)
205
206 } // namespace stack