HP and DHP SMR totally refactored
[libcds.git] / test / unit / tree / ellen_bintree_set_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_tree_set_hp.h"
32
33 #include <cds/container/ellen_bintree_set_dhp.h>
34 #include "test_ellen_bintree_update_desc_pool.h"
35
36 namespace {
37     namespace cc = cds::container;
38     typedef cds::gc::DHP gc_type;
39
40     class EllenBinTreeSet_DHP : public cds_test::container_tree_set_hp
41     {
42     protected:
43         typedef cds_test::container_tree_set_hp base_class;
44         typedef int key_type;
45
46         struct generic_traits: public cc::ellen_bintree::traits
47         {
48             typedef base_class::key_extractor key_extractor;
49         };
50
51         void SetUp()
52         {
53             typedef cc::EllenBinTreeSet< gc_type, key_type, int_item > set_type;
54
55             cds::gc::dhp::smr::construct( set_type::c_nHazardPtrCount );
56             cds::threading::Manager::attachThread();
57         }
58
59         void TearDown()
60         {
61             cds::threading::Manager::detachThread();
62             cds::gc::dhp::smr::destruct();
63         }
64     };
65
66
67     TEST_F( EllenBinTreeSet_DHP, compare )
68     {
69         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
70             typename cc::ellen_bintree::make_set_traits<
71                 cc::opt::type_traits< generic_traits >
72                 ,cds::opt::compare< cmp >
73             >::type
74         > set_type;
75
76         set_type s;
77         test( s );
78     }
79
80     TEST_F( EllenBinTreeSet_DHP, less )
81     {
82         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
83             typename cc::ellen_bintree::make_set_traits<
84                 cc::opt::type_traits< generic_traits >
85                 ,cds::opt::less< base_class::less >
86             >::type
87         > set_type;
88
89         set_type s;
90         test( s );
91     }
92
93     TEST_F( EllenBinTreeSet_DHP, cmpmix )
94     {
95         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item,
96             typename cc::ellen_bintree::make_set_traits<
97                 cc::opt::type_traits< generic_traits >
98                 ,cds::opt::less< base_class::less >
99                 ,cds::opt::compare< cmp >
100             >::type
101         > set_type;
102
103         set_type s;
104         test( s );
105     }
106
107     TEST_F( EllenBinTreeSet_DHP, update_desc_pool )
108     {
109         struct set_traits: public generic_traits
110         {
111             typedef cmp compare;
112             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
113         };
114         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
115
116         set_type s;
117         test( s );
118     }
119
120     TEST_F( EllenBinTreeSet_DHP, update_desc_lazy_pool )
121     {
122         struct set_traits: public generic_traits
123         {
124             typedef cmp compare;
125             typedef cds::memory::pool_allocator< cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
126         };
127         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
128
129         set_type s;
130         test( s );
131     }
132
133     TEST_F( EllenBinTreeSet_DHP, item_counting )
134     {
135         struct set_traits: public generic_traits
136         {
137             typedef cmp compare;
138             typedef base_class::less less;
139             typedef cds::atomicity::item_counter item_counter;
140             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
141         };
142         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
143
144         set_type s;
145         test( s );
146     }
147
148     TEST_F( EllenBinTreeSet_DHP, backoff )
149     {
150         struct set_traits: public generic_traits
151         {
152             typedef cmp compare;
153             typedef base_class::less less;
154             typedef cds::atomicity::item_counter item_counter;
155             typedef cds::backoff::yield back_off;
156             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::lazy_pool_accessor> update_desc_allocator;
157         };
158         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
159
160         set_type s;
161         test( s );
162     }
163
164     TEST_F( EllenBinTreeSet_DHP, stat )
165     {
166         struct set_traits: public generic_traits
167         {
168             typedef base_class::less less;
169             typedef cds::atomicity::item_counter item_counter;
170             typedef cds::backoff::yield back_off;
171             typedef cc::ellen_bintree::stat<> stat;
172             typedef cds::memory::pool_allocator<cds_test::update_desc, cds_test::pool_accessor> update_desc_allocator;
173         };
174         typedef cc::EllenBinTreeSet< gc_type, key_type, int_item, set_traits > set_type;
175
176         set_type s;
177         test( s );
178     }
179
180 } // namespace