3 #ifndef CDSUNIT_MAP_TYPE_ELLEN_BINTREE_H
4 #define CDSUNIT_MAP_TYPE_ELLEN_BINTREE_H
6 #include "map2/map_type.h"
8 #include <cds/container/ellen_bintree_map_rcu.h>
9 #include <cds/container/ellen_bintree_map_hp.h>
10 #include <cds/container/ellen_bintree_map_dhp.h>
12 #include "ellen_bintree_update_desc_pool.h"
13 #include "print_ellenbintree_stat.h"
17 template <class GC, typename Key, typename T, typename Traits = cc::ellen_bintree::traits >
18 class EllenBinTreeMap : public cc::EllenBinTreeMap< GC, Key, T, Traits >
20 typedef cc::EllenBinTreeMap< GC, Key, T, Traits > base_class;
22 template <typename Config>
23 EllenBinTreeMap( Config const& /*cfg*/)
28 static CDS_CONSTEXPR bool const c_bExtractSupported = true;
29 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
32 struct tag_EllenBinTreeMap;
34 template <typename Key, typename Value>
35 struct map_type< tag_EllenBinTreeMap, Key, Value >: public map_type_base< Key, Value >
37 typedef map_type_base< Key, Value > base_class;
38 typedef typename base_class::compare compare;
39 typedef typename base_class::less less;
41 struct ellen_bintree_props {
43 typedef cc::ellen_bintree::map_node<cds::gc::HP, Key, Value> leaf_node;
44 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
45 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
48 typedef cc::ellen_bintree::map_node<cds::gc::DHP, Key, Value> leaf_node;
49 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
50 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
53 typedef cc::ellen_bintree::map_node<rcu_gpi, Key, Value> leaf_node;
54 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
55 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
58 typedef cc::ellen_bintree::map_node<rcu_gpb, Key, Value> leaf_node;
59 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
60 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
63 typedef cc::ellen_bintree::map_node<rcu_gpt, Key, Value> leaf_node;
64 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
65 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
67 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
69 typedef cc::ellen_bintree::map_node<rcu_shb, Key, Value> leaf_node;
70 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
71 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
74 typedef cc::ellen_bintree::map_node<rcu_sht, Key, Value> leaf_node;
75 typedef cc::ellen_bintree::internal_node< Key, leaf_node > internal_node;
76 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node > update_desc;
81 struct traits_EllenBinTreeMap: public cc::ellen_bintree::make_set_traits<
83 ,co::node_allocator< ellen_bintree_pool::internal_node_allocator< int > >
84 ,co::item_counter< cds::atomicity::item_counter >
87 struct traits_EllenBinTreeMap_hp : traits_EllenBinTreeMap {
88 typedef cds::memory::pool_allocator< typename ellen_bintree_props::hp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
90 typedef EllenBinTreeMap< cds::gc::HP, Key, Value, traits_EllenBinTreeMap_hp >EllenBinTreeMap_hp;
92 struct traits_EllenBinTreeMap_dhp : traits_EllenBinTreeMap {
93 typedef cds::memory::pool_allocator< typename ellen_bintree_props::dhp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
95 typedef EllenBinTreeMap< cds::gc::DHP, Key, Value, traits_EllenBinTreeMap_dhp >EllenBinTreeMap_dhp;
97 struct traits_EllenBinTreeMap_gpi : traits_EllenBinTreeMap {
98 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpi::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
100 typedef EllenBinTreeMap< rcu_gpi, Key, Value, traits_EllenBinTreeMap_gpi >EllenBinTreeMap_rcu_gpi;
102 struct traits_EllenBinTreeMap_gpb : traits_EllenBinTreeMap {
103 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
105 typedef EllenBinTreeMap< rcu_gpb, Key, Value, traits_EllenBinTreeMap_gpb >EllenBinTreeMap_rcu_gpb;
107 struct traits_EllenBinTreeMap_gpt : traits_EllenBinTreeMap {
108 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpt::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
110 typedef EllenBinTreeMap< rcu_gpt, Key, Value, traits_EllenBinTreeMap_gpt >EllenBinTreeMap_rcu_gpt;
112 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
113 struct traits_EllenBinTreeMap_shb : traits_EllenBinTreeMap {
114 typedef cds::memory::pool_allocator< typename ellen_bintree_props::shb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
116 typedef EllenBinTreeMap< rcu_shb, Key, Value, traits_EllenBinTreeMap_shb >EllenBinTreeMap_rcu_shb;
118 struct traits_EllenBinTreeMap_sht : traits_EllenBinTreeMap {
119 typedef cds::memory::pool_allocator< typename ellen_bintree_props::sht::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
121 typedef EllenBinTreeMap< rcu_sht, Key, Value, traits_EllenBinTreeMap_sht >EllenBinTreeMap_rcu_sht;
124 struct traits_EllenBinTreeMap_yield : public traits_EllenBinTreeMap
126 typedef cds::backoff::yield back_off;
128 struct traits_EllenBinTreeMap_hp_yield : traits_EllenBinTreeMap_yield {
129 typedef cds::memory::pool_allocator< typename ellen_bintree_props::hp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
131 typedef EllenBinTreeMap< cds::gc::HP, Key, Value, traits_EllenBinTreeMap_hp_yield >EllenBinTreeMap_hp_yield;
133 struct traits_EllenBinTreeMap_dhp_yield : traits_EllenBinTreeMap_yield {
134 typedef cds::memory::pool_allocator< typename ellen_bintree_props::dhp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
136 typedef EllenBinTreeMap< cds::gc::DHP, Key, Value, traits_EllenBinTreeMap_dhp_yield >EllenBinTreeMap_dhp_yield;
138 struct traits_EllenBinTreeMap_gpb_yield : traits_EllenBinTreeMap_yield {
139 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
141 typedef EllenBinTreeMap< rcu_gpb, Key, Value, traits_EllenBinTreeMap_gpb_yield >EllenBinTreeMap_rcu_gpb_yield;
144 struct traits_EllenBinTreeMap_stat: public cc::ellen_bintree::make_set_traits<
146 ,cc::ellen_bintree::update_desc_allocator<
147 cds::memory::pool_allocator< typename ellen_bintree_props::hp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor >
149 ,co::node_allocator< ellen_bintree_pool::internal_node_allocator< int > >
150 ,co::stat< cc::ellen_bintree::stat<> >
151 ,co::item_counter< cds::atomicity::item_counter >
155 struct traits_EllenBinTreeMap_stat_hp : public traits_EllenBinTreeMap_stat
157 typedef cds::memory::pool_allocator< typename ellen_bintree_props::hp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
159 typedef EllenBinTreeMap< cds::gc::HP, Key, Value, traits_EllenBinTreeMap_stat_hp > EllenBinTreeMap_hp_stat;
161 struct traits_EllenBinTreeMap_stat_dhp : public traits_EllenBinTreeMap_stat
163 typedef cds::memory::pool_allocator< typename ellen_bintree_props::dhp_gc::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
165 typedef EllenBinTreeMap< cds::gc::HP, Key, Value, traits_EllenBinTreeMap_stat_dhp > EllenBinTreeMap_dhp_stat;
167 struct traits_EllenBinTreeMap_stat_gpi : public traits_EllenBinTreeMap_stat
169 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpi::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
171 typedef EllenBinTreeMap< rcu_gpi, Key, Value, traits_EllenBinTreeMap_stat_gpi > EllenBinTreeMap_rcu_gpi_stat;
173 struct traits_EllenBinTreeMap_stat_gpb : public traits_EllenBinTreeMap_stat
175 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
177 typedef EllenBinTreeMap< rcu_gpb, Key, Value, traits_EllenBinTreeMap_stat_gpb > EllenBinTreeMap_rcu_gpb_stat;
179 struct traits_EllenBinTreeMap_stat_gpt : public traits_EllenBinTreeMap_stat
181 typedef cds::memory::pool_allocator< typename ellen_bintree_props::gpt::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
183 typedef EllenBinTreeMap< rcu_gpt, Key, Value, traits_EllenBinTreeMap_stat_gpt > EllenBinTreeMap_rcu_gpt_stat;
185 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
186 struct traits_EllenBinTreeMap_stat_shb : public traits_EllenBinTreeMap_stat
188 typedef cds::memory::pool_allocator< typename ellen_bintree_props::shb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
190 typedef EllenBinTreeMap< rcu_shb, Key, Value, traits_EllenBinTreeMap_stat_shb > EllenBinTreeMap_rcu_shb_stat;
192 struct traits_EllenBinTreeMap_stat_sht : public traits_EllenBinTreeMap_stat
194 typedef cds::memory::pool_allocator< typename ellen_bintree_props::sht::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
196 typedef EllenBinTreeMap< rcu_sht, Key, Value, traits_EllenBinTreeMap_stat_sht > EllenBinTreeMap_rcu_sht_stat;
200 template <typename GC, typename Key, typename T, typename Traits>
201 static inline void print_stat( EllenBinTreeMap<GC, Key, T, Traits> const& s )
203 CPPUNIT_MSG( s.statistics() );
205 template <typename GC, typename Key, typename T, typename Traits>
206 static inline void additional_cleanup( EllenBinTreeMap<GC, Key, T, Traits>& /*s*/ )
208 ellen_bintree_pool::internal_node_counter::reset();
210 namespace ellen_bintree_check {
211 static inline void check_stat( cds::intrusive::ellen_bintree::empty_stat const& /*s*/ )
213 // This check is not valid for thread-based RCU
215 CPPUNIT_CHECK_CURRENT_EX( ellen_bintree_pool::internal_node_counter::m_nAlloc.get() == ellen_bintree_pool::internal_node_counter::m_nFree.get(),
216 "m_nAlloc=" << ellen_bintree_pool::internal_node_counter::m_nAlloc.get()
217 << ", m_nFree=" << ellen_bintree_pool::internal_node_counter::m_nFree.get()
222 static inline void check_stat( cds::intrusive::ellen_bintree::stat<> const& stat )
224 CPPUNIT_CHECK_CURRENT_EX( stat.m_nInternalNodeCreated == stat.m_nInternalNodeDeleted,
225 "m_nInternalNodeCreated=" << stat.m_nInternalNodeCreated
226 << " m_nInternalNodeDeleted=" << stat.m_nInternalNodeDeleted );
227 CPPUNIT_CHECK_CURRENT_EX( stat.m_nUpdateDescCreated == stat.m_nUpdateDescDeleted,
228 "m_nUpdateDescCreated=" << stat.m_nUpdateDescCreated
229 << " m_nUpdateDescDeleted=" << stat.m_nUpdateDescDeleted );
230 CPPUNIT_CHECK_CURRENT_EX( ellen_bintree_pool::internal_node_counter::m_nAlloc.get() == stat.m_nInternalNodeCreated,
231 "allocated=" << ellen_bintree_pool::internal_node_counter::m_nAlloc.get()
232 << "m_nInternalNodeCreated=" << stat.m_nInternalNodeCreated );
234 } // namespace ellen_bintree_check
235 template <typename GC, typename Key, typename T, typename Traits>
236 static inline void additional_check( EllenBinTreeMap<GC, Key, T, Traits>& s )
239 ellen_bintree_check::check_stat( s.statistics() );
242 template <typename GC, typename Key, typename T, typename Traits>
243 static inline void check_before_cleanup( EllenBinTreeMap<GC, Key, T, Traits>& m )
245 CPPUNIT_MSG( " Check internal consistency (single-threaded)..." );
246 CPPUNIT_CHECK_CURRENT( m.check_consistency() );
250 #endif // ifndef CDSUNIT_MAP_TYPE_ELLEN_BINTREE_H