node_pool.hpp 3.8 KB

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