adaptive_node_pool.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_ADAPTIVE_NODE_POOL_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_ADAPTIVE_NODE_POOL_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. #include <boost/interprocess/detail/utilities.hpp>
  22. #include <boost/interprocess/detail/math_functions.hpp>
  23. #include <boost/intrusive/set.hpp>
  24. #include <boost/intrusive/slist.hpp>
  25. #include <boost/interprocess/detail/type_traits.hpp>
  26. #include <boost/interprocess/mem_algo/detail/mem_algo_common.hpp>
  27. #include <boost/interprocess/allocators/detail/node_tools.hpp>
  28. #include <boost/interprocess/allocators/detail/allocator_common.hpp>
  29. #include <cstddef>
  30. #include <boost/config/no_tr1/cmath.hpp>
  31. #include <boost/container/detail/adaptive_node_pool_impl.hpp>
  32. #include <boost/assert.hpp>
  33. //!\file
  34. //!Describes the real adaptive pool shared by many Interprocess pool allocators
  35. namespace boost {
  36. namespace interprocess {
  37. namespace ipcdetail {
  38. template< class SegmentManager
  39. , std::size_t NodeSize
  40. , std::size_t NodesPerBlock
  41. , std::size_t MaxFreeBlocks
  42. , unsigned char OverheadPercent
  43. >
  44. class private_adaptive_node_pool
  45. : public boost::container::dtl::private_adaptive_node_pool_impl_rt
  46. < typename SegmentManager::segment_manager_base_type
  47. , ::boost::container::adaptive_pool_flag::size_ordered |
  48. ::boost::container::adaptive_pool_flag::address_ordered
  49. >
  50. {
  51. typedef boost::container::dtl::private_adaptive_node_pool_impl_rt
  52. < typename SegmentManager::segment_manager_base_type
  53. , ::boost::container::adaptive_pool_flag::size_ordered |
  54. ::boost::container::adaptive_pool_flag::address_ordered
  55. > base_t;
  56. //Non-copyable
  57. private_adaptive_node_pool();
  58. private_adaptive_node_pool(const private_adaptive_node_pool &);
  59. private_adaptive_node_pool &operator=(const private_adaptive_node_pool &);
  60. public:
  61. typedef SegmentManager segment_manager;
  62. typedef typename base_t::size_type size_type;
  63. static const size_type nodes_per_block = NodesPerBlock;
  64. //!Constructor from a segment manager. Never throws
  65. private_adaptive_node_pool(segment_manager *segment_mngr)
  66. : base_t(segment_mngr, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent)
  67. {}
  68. //!Returns the segment manager. Never throws
  69. segment_manager* get_segment_manager() const
  70. { return static_cast<segment_manager*>(base_t::get_segment_manager_base()); }
  71. };
  72. //!Pooled shared memory allocator using adaptive pool. Includes
  73. //!a reference count but the class does not delete itself, this is
  74. //!responsibility of user classes. Node size (NodeSize) and the number of
  75. //!nodes allocated per block (NodesPerBlock) are known at compile time
  76. template< class SegmentManager
  77. , std::size_t NodeSize
  78. , std::size_t NodesPerBlock
  79. , std::size_t MaxFreeBlocks
  80. , unsigned char OverheadPercent
  81. >
  82. class shared_adaptive_node_pool
  83. : public ipcdetail::shared_pool_impl
  84. < private_adaptive_node_pool
  85. <SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent>
  86. >
  87. {
  88. typedef ipcdetail::shared_pool_impl
  89. < private_adaptive_node_pool
  90. <SegmentManager, NodeSize, NodesPerBlock, MaxFreeBlocks, OverheadPercent>
  91. > base_t;
  92. public:
  93. shared_adaptive_node_pool(SegmentManager *segment_mgnr)
  94. : base_t(segment_mgnr)
  95. {}
  96. };
  97. } //namespace ipcdetail {
  98. } //namespace interprocess {
  99. } //namespace boost {
  100. #include <boost/interprocess/detail/config_end.hpp>
  101. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_ADAPTIVE_NODE_POOL_HPP