|
||||
File indexing completed on 2025-01-30 09:34:56
0001 ////////////////////////////////////////////////////////////////////////////// 0002 // 0003 // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost 0004 // Software License, Version 1.0. (See accompanying file 0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 // See http://www.boost.org/libs/container for documentation. 0008 // 0009 ////////////////////////////////////////////////////////////////////////////// 0010 0011 #ifndef BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP 0012 #define BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP 0013 0014 #if defined (_MSC_VER) 0015 # pragma once 0016 #endif 0017 0018 #include <boost/container/detail/config_begin.hpp> 0019 #include <boost/container/detail/workaround.hpp> 0020 #include <boost/container/detail/auto_link.hpp> 0021 #include <boost/container/pmr/memory_resource.hpp> 0022 #include <boost/container/detail/pool_resource.hpp> 0023 #include <boost/container/detail/thread_mutex.hpp> 0024 0025 #include <cstddef> 0026 0027 namespace boost { 0028 namespace container { 0029 namespace pmr { 0030 0031 //! A synchronized_pool_resource is a general-purpose memory resources having 0032 //! the following qualities: 0033 //! 0034 //! - Each resource owns the allocated memory, and frees it on destruction, 0035 //! even if deallocate has not been called for some of the allocated blocks. 0036 //! 0037 //! - A pool resource consists of a collection of pools, serving 0038 //! requests for different block sizes. Each individual pool manages a 0039 //! collection of chunks that are in turn divided into blocks of uniform size, 0040 //! returned via calls to do_allocate. Each call to do_allocate(size, alignment) 0041 //! is dispatched to the pool serving the smallest blocks accommodating at 0042 //! least size bytes. 0043 //! 0044 //! - When a particular pool is exhausted, allocating a block from that pool 0045 //! results in the allocation of an additional chunk of memory from the upstream 0046 //! allocator (supplied at construction), thus replenishing the pool. With 0047 //! each successive replenishment, the chunk size obtained increases 0048 //! geometrically. [ Note: By allocating memory in chunks, the pooling strategy 0049 //! increases the chance that consecutive allocations will be close together 0050 //! in memory. - end note ] 0051 //! 0052 //! - Allocation requests that exceed the largest block size of any pool are 0053 //! fulfilled directly from the upstream allocator. 0054 //! 0055 //! - A pool_options struct may be passed to the pool resource constructors to 0056 //! tune the largest block size and the maximum chunk size. 0057 //! 0058 //! A synchronized_pool_resource may be accessed from multiple threads without 0059 //! external synchronization and may have thread-specific pools to reduce 0060 //! synchronization costs. 0061 class BOOST_CONTAINER_DECL synchronized_pool_resource 0062 : public memory_resource 0063 { 0064 dtl::thread_mutex m_mut; 0065 pool_resource m_pool_resource; 0066 0067 public: 0068 0069 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(const pool_options&,memory_resource*) 0070 synchronized_pool_resource(const pool_options& opts, memory_resource* upstream) BOOST_NOEXCEPT; 0071 0072 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource() 0073 synchronized_pool_resource() BOOST_NOEXCEPT; 0074 0075 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(memory_resource*) 0076 explicit synchronized_pool_resource(memory_resource* upstream) BOOST_NOEXCEPT; 0077 0078 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(const pool_options&) 0079 explicit synchronized_pool_resource(const pool_options& opts) BOOST_NOEXCEPT; 0080 0081 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) 0082 synchronized_pool_resource(const synchronized_pool_resource&) = delete; 0083 synchronized_pool_resource operator=(const synchronized_pool_resource&) = delete; 0084 #else 0085 private: 0086 synchronized_pool_resource (const synchronized_pool_resource&); 0087 synchronized_pool_resource operator=(const synchronized_pool_resource&); 0088 public: 0089 #endif 0090 0091 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::~unsynchronized_pool_resource() 0092 ~synchronized_pool_resource() BOOST_OVERRIDE; 0093 0094 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::release() 0095 void release(); 0096 0097 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::upstream_resource()const 0098 memory_resource* upstream_resource() const; 0099 0100 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::options()const 0101 pool_options options() const; 0102 0103 protected: 0104 0105 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_allocate() 0106 virtual void* do_allocate(std::size_t bytes, std::size_t alignment) BOOST_OVERRIDE; 0107 0108 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_deallocate(void*,std::size_t,std::size_t) 0109 virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) BOOST_OVERRIDE; 0110 0111 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_is_equal(const memory_resource&)const 0112 virtual bool do_is_equal(const memory_resource& other) const BOOST_NOEXCEPT BOOST_OVERRIDE; 0113 0114 //Non-standard observers 0115 public: 0116 0117 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_count() 0118 std::size_t pool_count() const; 0119 0120 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_index(std::size_t)const 0121 std::size_t pool_index(std::size_t bytes) const; 0122 0123 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_next_blocks_per_chunk(std::size_t)const 0124 std::size_t pool_next_blocks_per_chunk(std::size_t pool_idx) const; 0125 0126 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_block(std::size_t)const 0127 std::size_t pool_block(std::size_t pool_idx) const; 0128 0129 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_cached_blocks(std::size_t)const 0130 std::size_t pool_cached_blocks(std::size_t pool_idx) const; 0131 }; 0132 0133 } //namespace pmr { 0134 } //namespace container { 0135 } //namespace boost { 0136 0137 #include <boost/container/detail/config_end.hpp> 0138 0139 #endif //BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |