Added copyright and license
[libcds.git] / tests / test-hdr / queue / hdr_intrusive_moirqueue_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_msqueue.h"
32 #include <cds/intrusive/moir_queue.h>
33 #include <cds/gc/hp.h>
34
35 namespace queue {
36
37 #define TEST(X) void IntrusiveQueueHeaderTest::test_##X() { test<X>(); }
38
39     namespace {
40         typedef IntrusiveQueueHeaderTest::base_hook_item< ci::msqueue::node<cds::gc::HP > > base_item_type;
41         typedef IntrusiveQueueHeaderTest::member_hook_item< ci::msqueue::node<cds::gc::HP > > member_item_type;
42
43         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
44             typename ci::msqueue::make_traits<
45                 ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
46             >::type
47         > MoirQueue_HP_default;
48
49         /// HP + item counter
50         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
51             typename ci::msqueue::make_traits<
52                 ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
53                 ,co::item_counter< cds::atomicity::item_counter >
54                 ,co::memory_model< co::v::sequential_consistent >
55             >::type
56         > MoirQueue_HP_default_ic;
57
58         /// HP + stat
59         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
60             typename ci::msqueue::make_traits<
61                 ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
62                 ,co::stat< ci::msqueue::stat<> >
63             >::type
64         > MoirQueue_HP_default_stat;
65
66         // HP base hook
67         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
68             typename ci::msqueue::make_traits<
69                 ci::opt::hook<
70                     ci::msqueue::base_hook< ci::opt::gc<cds::gc::HP> >
71                 >
72                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
73             >::type
74         > MoirQueue_HP_base;
75
76         // HP member hook
77         typedef ci::MoirQueue< cds::gc::HP, member_item_type,
78             typename ci::msqueue::make_traits<
79                 ci::opt::hook<
80                     ci::msqueue::member_hook<
81                         offsetof( member_item_type, hMember ),
82                         ci::opt::gc<cds::gc::HP>
83                     >
84                 >
85                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
86             >::type
87         > MoirQueue_HP_member;
88
89         /// HP base hook + item counter
90         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
91             typename ci::msqueue::make_traits<
92                 ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
93                 ,ci::opt::hook<
94                     ci::msqueue::base_hook< ci::opt::gc<cds::gc::HP> >
95                 >
96                 ,co::item_counter< cds::atomicity::item_counter >
97                 ,co::memory_model< co::v::relaxed_ordering >
98             >::type
99         > MoirQueue_HP_base_ic;
100
101         // HP member hook + item counter
102         typedef ci::MoirQueue< cds::gc::HP, member_item_type,
103             typename ci::msqueue::make_traits<
104                 ci::opt::hook<
105                     ci::msqueue::member_hook<
106                         offsetof( member_item_type, hMember ),
107                         ci::opt::gc<cds::gc::HP>
108                     >
109                 >
110                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
111                 ,co::item_counter< cds::atomicity::item_counter >
112             >::type
113        > MoirQueue_HP_member_ic;
114
115         // HP base hook + stat
116         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
117             typename ci::msqueue::make_traits<
118                 ci::opt::hook<
119                     ci::msqueue::base_hook< ci::opt::gc<cds::gc::HP> >
120                 >
121                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
122                 ,co::stat< ci::msqueue::stat<> >
123             >::type
124         > MoirQueue_HP_base_stat;
125
126         // HP member hook + stat
127         typedef ci::MoirQueue< cds::gc::HP, member_item_type,
128             typename ci::msqueue::make_traits<
129                 ci::opt::hook<
130                     ci::msqueue::member_hook<
131                         offsetof( member_item_type, hMember ),
132                         ci::opt::gc<cds::gc::HP>
133                     >
134                 >
135                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
136                 ,co::stat< ci::msqueue::stat<> >
137             >::type
138         > MoirQueue_HP_member_stat;
139
140         // HP base hook + padding
141         typedef ci::MoirQueue< cds::gc::HP, base_item_type,
142             typename ci::msqueue::make_traits<
143                 ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
144                 ,ci::opt::hook<
145                     ci::msqueue::base_hook< ci::opt::gc<cds::gc::HP> >
146                 >
147                 ,co::padding< 32 >
148             >::type
149         > MoirQueue_HP_base_align;
150
151         // HP member hook + padding
152         typedef ci::MoirQueue< cds::gc::HP, member_item_type,
153             typename ci::msqueue::make_traits<
154                 ci::opt::hook<
155                     ci::msqueue::member_hook<
156                         offsetof( member_item_type, hMember ),
157                         ci::opt::gc<cds::gc::HP>
158                     >
159                 >
160                 ,co::padding< 32 >
161                 ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer >
162             >::type
163         > MoirQueue_HP_member_align;
164
165         // HP base hook + no padding
166         struct traits_MoirQueue_HP_base_noalign : public ci::msqueue::traits {
167             typedef ci::msqueue::base_hook< ci::opt::gc<cds::gc::HP> > hook;
168             typedef IntrusiveQueueHeaderTest::faked_disposer disposer;
169             enum { padding = co::no_special_padding };
170         };
171         typedef ci::MoirQueue< cds::gc::HP, base_item_type, traits_MoirQueue_HP_base_noalign > MoirQueue_HP_base_noalign;
172
173         // HP member hook + no padding
174         struct traits_MoirQueue_HP_member_noalign : public ci::msqueue::traits {
175             typedef ci::msqueue::member_hook <
176                 offsetof( member_item_type, hMember ),
177                 ci::opt::gc < cds::gc::HP >
178             > hook;
179             typedef IntrusiveQueueHeaderTest::faked_disposer disposer;
180             enum { padding = co::no_special_padding };
181         };
182         typedef ci::MoirQueue< cds::gc::HP, member_item_type, traits_MoirQueue_HP_member_noalign > MoirQueue_HP_member_noalign;
183
184
185         // HP base hook + cache padding
186         struct traits_MoirQueue_HP_base_cachealign : public traits_MoirQueue_HP_base_noalign
187         {
188             enum { padding = co::cache_line_padding };
189         };
190         typedef ci::MoirQueue< cds::gc::HP, base_item_type, traits_MoirQueue_HP_base_cachealign > MoirQueue_HP_base_cachealign;
191
192         // HP member hook + cache padding
193         struct traits_MoirQueue_HP_member_cachealign : public traits_MoirQueue_HP_member_noalign
194         {
195             enum { padding = co::cache_line_padding };
196         };
197         typedef ci::MoirQueue< cds::gc::HP, member_item_type, traits_MoirQueue_HP_member_cachealign > MoirQueue_HP_member_cachealign;
198     }
199
200     TEST(MoirQueue_HP_default)
201     TEST(MoirQueue_HP_default_ic)
202     TEST(MoirQueue_HP_default_stat)
203     TEST(MoirQueue_HP_base)
204     TEST(MoirQueue_HP_member)
205     TEST(MoirQueue_HP_base_ic)
206     TEST(MoirQueue_HP_member_ic)
207     TEST(MoirQueue_HP_base_stat)
208     TEST(MoirQueue_HP_member_stat)
209     TEST(MoirQueue_HP_base_align)
210     TEST(MoirQueue_HP_member_align)
211     TEST(MoirQueue_HP_base_noalign)
212     TEST(MoirQueue_HP_member_noalign)
213     TEST(MoirQueue_HP_base_cachealign)
214     TEST(MoirQueue_HP_member_cachealign)
215 }