3 #ifndef CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
4 #define CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
6 #include <cds/urcu/general_instant.h>
7 #include <cds/container/details/ellen_bintree_base.h>
8 #include <cds/memory/vyukov_queue_pool.h>
9 #include <cds/memory/pool_allocator.h>
11 namespace ellen_bintree_pool {
12 typedef cds::container::ellen_bintree::node_types< cds::urcu::gc< cds::urcu::general_instant<> >, int > node_types; // fake
13 typedef node_types::leaf_node_type leaf_node;
14 typedef node_types::internal_node_type internal_node;
15 typedef node_types::update_desc_type update_desc;
17 // Update descriptor pool based on Vyukov's queue
18 struct update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
20 typedef cds::opt::v::static_buffer< cds::any_type, 4096 > buffer;
23 typedef cds::memory::vyukov_queue_pool< update_desc, update_desc_pool_traits > update_desc_pool_type;
24 extern update_desc_pool_type s_UpdateDescPool;
26 struct update_desc_pool_accessor {
27 typedef update_desc_pool_type::value_type value_type;
29 update_desc_pool_type& operator()() const
31 return s_UpdateDescPool;
35 // Update descriptor pool based on bounded Vyukov's queue
36 struct bounded_update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
38 typedef cds::opt::v::static_buffer< cds::any_type, 4096 > buffer;
40 typedef cds::memory::bounded_vyukov_queue_pool< update_desc, bounded_update_desc_pool_traits > bounded_update_desc_pool_type;
41 extern bounded_update_desc_pool_type s_BoundedUpdateDescPool;
43 struct bounded_update_desc_pool_accessor {
44 typedef bounded_update_desc_pool_type::value_type value_type;
46 bounded_update_desc_pool_type& operator()() const
48 return s_BoundedUpdateDescPool;
53 // Internal node allocator
54 struct internal_node_counter
56 static cds::atomicity::event_counter m_nAlloc;
57 static cds::atomicity::event_counter m_nFree;
75 template <typename T, typename Alloc = CDS_DEFAULT_ALLOCATOR>
76 class internal_node_allocator
77 : public Alloc::template rebind< T >::other
78 , internal_node_counter
80 typedef typename Alloc::template rebind< T >::other base_class;
82 template <typename Other>
84 typedef internal_node_allocator< Other, Alloc > other;
87 T * allocate( size_t n, void const * pHint = nullptr )
89 internal_node_counter::onAlloc();
90 return base_class::allocate( n, pHint );
93 void deallocate( T * p, size_t n )
95 internal_node_counter::onFree();
96 return base_class::deallocate( p, n );
100 } // namespace ellen_bintree_pool
102 #endif // #ifndef CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H