Removing unused vars
[libcds.git] / tests / unit / ellen_bintree_update_desc_pool.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_UNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
4 #define __CDS_UNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
5
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>
10
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;
16
17     // Update descriptor pool based on Vyukov's queue
18     struct update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
19     {
20         typedef cds::opt::v::static_buffer< cds::any_type, 4096 > buffer;
21     };
22
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;
25
26     struct update_desc_pool_accessor {
27         typedef update_desc_pool_type::value_type     value_type;
28
29         update_desc_pool_type& operator()() const
30         {
31             return s_UpdateDescPool;
32         }
33     };
34
35     // Update descriptor pool based on bounded Vyukov's queue
36     struct bounded_update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
37     {
38         typedef cds::opt::v::static_buffer< cds::any_type, 4096 > buffer;
39     };
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;
42
43     struct bounded_update_desc_pool_accessor {
44         typedef bounded_update_desc_pool_type::value_type     value_type;
45
46         bounded_update_desc_pool_type& operator()() const
47         {
48             return s_BoundedUpdateDescPool;
49         }
50     };
51
52
53     // Internal node allocator
54     struct internal_node_counter
55     {
56         static cds::atomicity::event_counter   m_nAlloc;
57         static cds::atomicity::event_counter   m_nFree;
58
59         static void onAlloc()
60         {
61             ++m_nAlloc;
62         }
63         static void onFree()
64         {
65             ++m_nFree;
66         }
67
68         static void reset()
69         {
70             m_nAlloc.reset();
71             m_nFree.reset();
72         }
73     };
74
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
79     {
80         typedef typename Alloc::template rebind< T >::other  base_class;
81     public:
82         template <typename Other>
83         struct rebind {
84             typedef internal_node_allocator< Other, Alloc > other;
85         };
86
87         T * allocate( size_t n, void const * pHint = nullptr )
88         {
89             internal_node_counter::onAlloc();
90             return base_class::allocate( n, pHint );
91         }
92
93         void deallocate( T * p, size_t n )
94         {
95             internal_node_counter::onFree();
96             return base_class::deallocate( p, n );
97         }
98     };
99
100 } // namespace ellen_bintree_pool
101
102 #endif // #ifndef __CDS_UNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H