Merge pull request #58 from rfw/patch-1
[libcds.git] / tests / test-hdr / map / hdr_splitlist_map_lazy_rcu_shb.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 "map/hdr_map.h"
32 #include <cds/urcu/signal_buffered.h>
33 #include <cds/container/lazy_list_rcu.h>
34 #include <cds/container/split_list_map_rcu.h>
35
36 namespace map {
37
38 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
39     namespace {
40         typedef cds::urcu::gc< cds::urcu::signal_buffered<> >  rcu_type;
41
42         struct RCU_SHB_cmp_traits: public cc::split_list::traits
43         {
44             typedef cc::lazy_list_tag                   ordered_list;
45             typedef HashMapHdrTest::hash_int            hash;
46             typedef HashMapHdrTest::simple_item_counter item_counter;
47             typedef cc::opt::v::relaxed_ordering        memory_model;
48             enum { dynamic_bucket_table = false };
49
50             struct ordered_list_traits: public cc::lazy_list::traits
51             {
52                 typedef HashMapHdrTest::cmp   compare;
53             };
54         };
55
56         struct RCU_SHB_less_traits: public cc::split_list::traits
57         {
58             typedef cc::lazy_list_tag                   ordered_list;
59             typedef HashMapHdrTest::hash_int            hash;
60             typedef HashMapHdrTest::simple_item_counter item_counter;
61             typedef cc::opt::v::sequential_consistent                      memory_model;
62             enum { dynamic_bucket_table = true };
63
64             struct ordered_list_traits: public cc::lazy_list::traits
65             {
66                 typedef HashMapHdrTest::less   less;
67             };
68         };
69
70         struct RCU_cmpmix_traits: public cc::split_list::traits
71         {
72             typedef cc::lazy_list_tag                   ordered_list;
73             typedef HashMapHdrTest::hash_int            hash;
74             typedef HashMapHdrTest::simple_item_counter item_counter;
75
76             struct ordered_list_traits: public cc::lazy_list::traits
77             {
78                 typedef HashMapHdrTest::cmp   compare;
79                 typedef std::less<HashMapHdrTest::key_type>     less;
80             };
81         };
82
83         struct RCU_cmpmix_stat_traits : public RCU_cmpmix_traits
84         {
85             typedef cc::split_list::stat<> stat;
86         };
87
88     }
89 #endif
90
91     void HashMapHdrTest::Split_Lazy_RCU_SHB_cmp()
92     {
93 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
94         // traits-based version
95         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_SHB_cmp_traits > map_type;
96         test_rcu< map_type >();
97
98         // option-based version
99         typedef cc::SplitListMap< rcu_type,
100             key_type,
101             value_type,
102             cc::split_list::make_traits<
103                 cc::split_list::ordered_list<cc::lazy_list_tag>
104                 ,cc::opt::hash< hash_int >
105                 ,cc::opt::item_counter< simple_item_counter >
106                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
107                 ,cc::split_list::dynamic_bucket_table< true >
108                 ,cc::split_list::ordered_list_traits<
109                     cc::lazy_list::make_traits<
110                         cc::opt::compare< cmp >
111                     >::type
112                 >
113             >::type
114         > opt_map;
115         test_rcu< opt_map >();
116 #endif
117     }
118
119     void HashMapHdrTest::Split_Lazy_RCU_SHB_less()
120     {
121 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
122         // traits-based version
123         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_SHB_less_traits > map_type;
124         test_rcu< map_type >();
125
126         // option-based version
127         typedef cc::SplitListMap< rcu_type,
128             key_type,
129             value_type,
130             cc::split_list::make_traits<
131                 cc::split_list::ordered_list<cc::lazy_list_tag>
132                 ,cc::opt::hash< hash_int >
133                 ,cc::opt::item_counter< simple_item_counter >
134                 ,cc::opt::memory_model< cc::opt::v::relaxed_ordering >
135                 ,cc::split_list::dynamic_bucket_table< false >
136                 ,cc::split_list::ordered_list_traits<
137                     cc::lazy_list::make_traits<
138                         cc::opt::less< less >
139                     >::type
140                 >
141             >::type
142         > opt_map;
143         test_rcu< opt_map >();
144 #endif
145     }
146
147     void HashMapHdrTest::Split_Lazy_RCU_SHB_cmpmix()
148     {
149 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
150         // traits-based version
151         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_cmpmix_traits > map_type;
152         test_rcu< map_type >();
153
154         // option-based version
155         typedef cc::SplitListMap< rcu_type,
156             key_type,
157             value_type,
158             cc::split_list::make_traits<
159                 cc::split_list::ordered_list<cc::lazy_list_tag>
160                 ,cc::opt::hash< hash_int >
161                 ,cc::opt::item_counter< simple_item_counter >
162                 ,cc::split_list::ordered_list_traits<
163                     cc::lazy_list::make_traits<
164                     cc::opt::less< std::less<key_type> >
165                         ,cc::opt::compare< cmp >
166                     >::type
167                 >
168             >::type
169         > opt_map;
170         test_rcu< opt_map >();
171 #endif
172     }
173
174     void HashMapHdrTest::Split_Lazy_RCU_SHB_cmpmix_stat()
175     {
176 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
177         // traits-based version
178         typedef cc::SplitListMap< rcu_type, key_type, value_type, RCU_cmpmix_stat_traits > map_type;
179         test_rcu< map_type >();
180
181         // option-based version
182         typedef cc::SplitListMap< rcu_type,
183             key_type,
184             value_type,
185             cc::split_list::make_traits<
186                 cc::split_list::ordered_list<cc::lazy_list_tag>
187                 ,cc::opt::hash< hash_int >
188                 ,cc::opt::item_counter< simple_item_counter >
189                 ,cc::opt::stat< cc::split_list::stat<> >
190                 ,cc::split_list::ordered_list_traits<
191                     cc::lazy_list::make_traits<
192                     cc::opt::less< std::less<key_type> >
193                         ,cc::opt::compare< cmp >
194                     >::type
195                 >
196             >::type
197         > opt_map;
198         test_rcu< opt_map >();
199 #endif
200     }
201
202 } // namespace map