Removed signal_threaded uRCU
[libcds.git] / test / unit / stack / treiber_stack_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-2017
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_treiber_stack.h"
32
33 #include <cds/gc/dhp.h>
34 #include <cds/container/treiber_stack.h>
35
36 namespace {
37
38     namespace cc = cds::container;
39     typedef cds::gc::DHP gc_type;
40
41     class TreiberStack_DHP : public cds_test::TreiberStack
42     {
43         typedef cds_test::TreiberStack base_class;
44
45     protected:
46         void SetUp()
47         {
48             typedef cc::TreiberStack< gc_type, int > stack_type;
49
50             cds::gc::dhp::smr::construct( stack_type::c_nHazardPtrCount );
51             cds::threading::Manager::attachThread();
52         }
53
54         void TearDown()
55         {
56             cds::threading::Manager::detachThread();
57             cds::gc::dhp::smr::destruct();
58         }
59
60         template <typename Stack>
61         void test()
62         {
63             Stack stack;
64             base_class::test( stack );
65         }
66
67         template <typename Stack>
68         void test_dyn( size_t elimination_size )
69         {
70             Stack stack( elimination_size );
71             base_class::test( stack );
72         }
73     };
74
75     TEST_F( TreiberStack_DHP, defaulted )
76     {
77         typedef cc::TreiberStack< gc_type, int > stack_type;
78
79         test<stack_type>();
80     }
81
82     TEST_F( TreiberStack_DHP, backoff )
83     {
84         typedef cc::TreiberStack< gc_type, int
85             , typename cc::treiber_stack::make_traits<
86                 cds::opt::back_off< cds::backoff::yield>
87             >::type
88         > stack_type;
89
90         test<stack_type>();
91     }
92
93     TEST_F( TreiberStack_DHP, alloc )
94     {
95         // allocator must be rebinded for real value type
96         struct foo
97         {
98             size_t arr[ 1024 * 1024 ];
99             size_t a2[1024 * 1024];
100             size_t a3[1024 * 1024];
101             size_t a4[1024 * 1024];
102         };
103
104         typedef cc::TreiberStack< gc_type, int
105             , typename cc::treiber_stack::make_traits<
106                 cds::opt::back_off< cds::backoff::pause>
107                 ,cds::opt::memory_model<cds::opt::v::relaxed_ordering>
108                 ,cds::opt::allocator< std::allocator< foo >>
109             >::type
110         > stack_type;
111
112         test<stack_type>();
113     }
114
115     TEST_F( TreiberStack_DHP, elimination )
116     {
117         typedef cc::TreiberStack< gc_type, int
118             , typename cc::treiber_stack::make_traits<
119                 cds::opt::enable_elimination<true>
120             >::type
121         > stack_type;
122
123         test<stack_type>();
124     }
125
126     TEST_F( TreiberStack_DHP, elimination_backoff )
127     {
128         struct traits : public cc::treiber_stack::traits
129         {
130             enum {
131                 enable_elimination = true
132             };
133             typedef cds::backoff::pause back_off;
134         };
135         typedef cc::TreiberStack< gc_type, int, traits > stack_type;
136
137         test<stack_type>();
138     }
139
140     TEST_F( TreiberStack_DHP, elimination_dynamic )
141     {
142         typedef cc::TreiberStack< gc_type, int
143             , typename cc::treiber_stack::make_traits<
144                 cds::opt::enable_elimination<true>
145                 , cds::opt::buffer< cds::opt::v::initialized_dynamic_buffer<void *> >
146             >::type
147         > stack_type;
148
149         test_dyn<stack_type>( 4 );
150     }
151
152     TEST_F( TreiberStack_DHP, elimination_stat )
153     {
154         typedef cc::TreiberStack< gc_type, int
155             , typename cc::treiber_stack::make_traits<
156                 cds::opt::enable_elimination<true>
157                 , cds::opt::stat< cc::treiber_stack::stat<> >
158             >::type
159         > stack_type;
160
161         test<stack_type>();
162     }
163
164     TEST_F( TreiberStack_DHP, elimination_dynamic_backoff )
165     {
166         struct traits : public cc::treiber_stack::traits
167         {
168             enum {
169                 enable_elimination = true
170             };
171             typedef cds::opt::v::initialized_dynamic_buffer<void *> buffer;
172             typedef cds::backoff::yield back_off;
173         };
174         typedef cc::TreiberStack< gc_type, int, traits > stack_type;
175
176         test_dyn<stack_type>( 2 );
177     }
178
179 } // namespace