File indexing completed on 2025-01-18 09:30:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CONTAINER_DETAIL_NODE_POOL_HPP
0012 #define BOOST_CONTAINER_DETAIL_NODE_POOL_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024
0025 #include <boost/container/detail/mutex.hpp>
0026 #include <boost/container/detail/pool_common_alloc.hpp>
0027 #include <boost/container/detail/node_pool_impl.hpp>
0028 #include <boost/container/detail/mutex.hpp>
0029 #include <boost/move/utility_core.hpp>
0030 #include <cstddef>
0031 #include <cassert>
0032
0033 namespace boost {
0034 namespace container {
0035 namespace dtl {
0036
0037
0038
0039
0040
0041 template< std::size_t NodeSize, std::size_t NodesPerBlock >
0042 class private_node_pool
0043
0044 : public boost::container::dtl::
0045 private_node_pool_impl<fake_segment_manager>
0046 {
0047 typedef boost::container::dtl::
0048 private_node_pool_impl<fake_segment_manager> base_t;
0049
0050 private_node_pool(const private_node_pool &);
0051 private_node_pool &operator=(const private_node_pool &);
0052
0053 public:
0054 typedef typename base_t::multiallocation_chain multiallocation_chain;
0055 static const std::size_t nodes_per_block = NodesPerBlock;
0056
0057
0058 private_node_pool()
0059 : base_t(0, NodeSize, NodesPerBlock)
0060 {}
0061
0062 };
0063
0064 template< std::size_t NodeSize
0065 , std::size_t NodesPerBlock
0066 >
0067 class shared_node_pool
0068 : public private_node_pool<NodeSize, NodesPerBlock>
0069 {
0070 private:
0071 typedef private_node_pool<NodeSize, NodesPerBlock> private_node_allocator_t;
0072
0073 public:
0074 typedef typename private_node_allocator_t::free_nodes_t free_nodes_t;
0075 typedef typename private_node_allocator_t::multiallocation_chain multiallocation_chain;
0076
0077
0078 shared_node_pool()
0079 : private_node_allocator_t(){}
0080
0081
0082 ~shared_node_pool()
0083 {}
0084
0085
0086 void *allocate_node()
0087 {
0088
0089 scoped_lock<default_mutex> guard(mutex_);
0090
0091 return private_node_allocator_t::allocate_node();
0092 }
0093
0094
0095 void deallocate_node(void *ptr)
0096 {
0097
0098 scoped_lock<default_mutex> guard(mutex_);
0099
0100 private_node_allocator_t::deallocate_node(ptr);
0101 }
0102
0103
0104
0105 void allocate_nodes(const std::size_t n, multiallocation_chain &chain)
0106 {
0107
0108 scoped_lock<default_mutex> guard(mutex_);
0109
0110 return private_node_allocator_t::allocate_nodes(n, chain);
0111 }
0112
0113 void deallocate_nodes(multiallocation_chain &chain)
0114 {
0115
0116 scoped_lock<default_mutex> guard(mutex_);
0117
0118 private_node_allocator_t::deallocate_nodes(chain);
0119 }
0120
0121
0122 void deallocate_free_blocks()
0123 {
0124
0125 scoped_lock<default_mutex> guard(mutex_);
0126
0127 private_node_allocator_t::deallocate_free_blocks();
0128 }
0129
0130
0131 void purge_blocks()
0132 {
0133
0134 scoped_lock<default_mutex> guard(mutex_);
0135
0136 private_node_allocator_t::purge_blocks();
0137 }
0138
0139 std::size_t num_free_nodes()
0140 {
0141
0142 scoped_lock<default_mutex> guard(mutex_);
0143
0144 return private_node_allocator_t::num_free_nodes();
0145 }
0146
0147 private:
0148 default_mutex mutex_;
0149 };
0150
0151 }
0152 }
0153 }
0154
0155 #include <boost/container/detail/config_end.hpp>
0156
0157 #endif