node_pool.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_NODE_POOL_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_NODE_POOL_HPP
  12. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #include <boost/interprocess/detail/workaround.hpp>
  17. #include <boost/intrusive/slist.hpp>
  18. #include <boost/math/common_factor_ct.hpp>
  19. #include <boost/interprocess/detail/utilities.hpp>
  20. #include <boost/interprocess/allocators/detail/allocator_common.hpp>
  21. #include <boost/container/detail/node_pool_impl.hpp>
  22. #include <cstddef>
  23. //!\file
  24. //!Describes the real adaptive pool shared by many Interprocess adaptive pool allocators
  25. namespace boost {
  26. namespace interprocess {
  27. namespace ipcdetail {
  28. //!Pooled shared memory allocator using single segregated storage. Includes
  29. //!a reference count but the class does not delete itself, this is
  30. //!responsibility of user classes. Node size (NodeSize) and the number of
  31. //!nodes allocated per block (NodesPerBlock) are known at compile time
  32. template< class SegmentManager, std::size_t NodeSize, std::size_t NodesPerBlock >
  33. class private_node_pool
  34. //Inherit from the implementation to avoid template bloat
  35. : public boost::container::container_detail::
  36. private_node_pool_impl<typename SegmentManager::segment_manager_base_type>
  37. {
  38. typedef boost::container::container_detail::private_node_pool_impl
  39. <typename SegmentManager::segment_manager_base_type> base_t;
  40. //Non-copyable
  41. private_node_pool();
  42. private_node_pool(const private_node_pool &);
  43. private_node_pool &operator=(const private_node_pool &);
  44. public:
  45. typedef SegmentManager segment_manager;
  46. typedef typename base_t::size_type size_type;
  47. static const size_type nodes_per_block = NodesPerBlock;
  48. //Deprecated, use nodes_per_block
  49. static const size_type nodes_per_chunk = NodesPerBlock;
  50. //!Constructor from a segment manager. Never throws
  51. private_node_pool(segment_manager *segment_mngr)
  52. : base_t(segment_mngr, NodeSize, NodesPerBlock)
  53. {}
  54. //!Returns the segment manager. Never throws
  55. segment_manager* get_segment_manager() const
  56. { return static_cast<segment_manager*>(base_t::get_segment_manager_base()); }
  57. };
  58. //!Pooled shared memory allocator using single segregated storage. Includes
  59. //!a reference count but the class does not delete itself, this is
  60. //!responsibility of user classes. Node size (NodeSize) and the number of
  61. //!nodes allocated per block (NodesPerBlock) are known at compile time
  62. //!Pooled shared memory allocator using adaptive pool. Includes
  63. //!a reference count but the class does not delete itself, this is
  64. //!responsibility of user classes. Node size (NodeSize) and the number of
  65. //!nodes allocated per block (NodesPerBlock) are known at compile time
  66. template< class SegmentManager
  67. , std::size_t NodeSize
  68. , std::size_t NodesPerBlock
  69. >
  70. class shared_node_pool
  71. : public ipcdetail::shared_pool_impl
  72. < private_node_pool
  73. <SegmentManager, NodeSize, NodesPerBlock>
  74. >
  75. {
  76. typedef ipcdetail::shared_pool_impl
  77. < private_node_pool
  78. <SegmentManager, NodeSize, NodesPerBlock>
  79. > base_t;
  80. public:
  81. shared_node_pool(SegmentManager *segment_mgnr)
  82. : base_t(segment_mgnr)
  83. {}
  84. };
  85. } //namespace ipcdetail {
  86. } //namespace interprocess {
  87. } //namespace boost {
  88. #include <boost/interprocess/detail/config_end.hpp>
  89. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_NODE_POOL_HPP