2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #ifndef CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
32 #define CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H
34 #include <cds/urcu/general_instant.h>
35 #include <cds/container/details/ellen_bintree_base.h>
36 #include <cds/memory/vyukov_queue_pool.h>
37 #include <cds/memory/pool_allocator.h>
39 namespace ellen_bintree_pool {
40 typedef cds::container::ellen_bintree::node_types< cds::urcu::gc< cds::urcu::general_instant<> >, int > node_types; // fake
41 typedef node_types::leaf_node_type leaf_node;
42 typedef node_types::internal_node_type internal_node;
43 typedef node_types::update_desc_type update_desc;
45 // Update descriptor pool based on Vyukov's queue
46 struct update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
48 typedef cds::opt::v::initialized_static_buffer< cds::any_type, 4096 > buffer;
51 typedef cds::memory::vyukov_queue_pool< update_desc, update_desc_pool_traits > update_desc_pool_type;
52 extern update_desc_pool_type s_UpdateDescPool;
54 struct update_desc_pool_accessor {
55 typedef update_desc_pool_type::value_type value_type;
57 update_desc_pool_type& operator()() const
59 return s_UpdateDescPool;
63 // Update descriptor pool based on bounded Vyukov's queue
64 struct bounded_update_desc_pool_traits : public cds::memory::vyukov_queue_pool_traits
66 typedef cds::opt::v::initialized_static_buffer< cds::any_type, 4096 > buffer;
68 typedef cds::memory::bounded_vyukov_queue_pool< update_desc, bounded_update_desc_pool_traits > bounded_update_desc_pool_type;
69 extern bounded_update_desc_pool_type s_BoundedUpdateDescPool;
71 struct bounded_update_desc_pool_accessor {
72 typedef bounded_update_desc_pool_type::value_type value_type;
74 bounded_update_desc_pool_type& operator()() const
76 return s_BoundedUpdateDescPool;
81 // Internal node allocator
82 struct internal_node_counter
84 static cds::atomicity::event_counter m_nAlloc;
85 static cds::atomicity::event_counter m_nFree;
103 template <typename T, typename Alloc = CDS_DEFAULT_ALLOCATOR>
104 class internal_node_allocator
105 : public Alloc::template rebind< T >::other
106 , internal_node_counter
108 typedef typename Alloc::template rebind< T >::other base_class;
110 template <typename Other>
112 typedef internal_node_allocator< Other, Alloc > other;
115 T * allocate( size_t n, void const * pHint = nullptr )
117 internal_node_counter::onAlloc();
118 T * p = base_class::allocate( n, pHint );
122 void deallocate( T * p, size_t n )
124 internal_node_counter::onFree();
125 return base_class::deallocate( p, n );
129 } // namespace ellen_bintree_pool
131 #endif // #ifndef CDSUNIT_ELLEN_BINTREE_UPDATE_DESC_POOL_H