]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/container/include/boost/container/pmr/synchronized_pool_resource.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / container / include / boost / container / pmr / synchronized_pool_resource.hpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2015-2015. 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/container for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP
12#define BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP
13
14#if defined (_MSC_VER)
15# pragma once
16#endif
17
18#include <boost/container/detail/config_begin.hpp>
19#include <boost/container/detail/workaround.hpp>
20#include <boost/container/detail/auto_link.hpp>
21#include <boost/container/pmr/memory_resource.hpp>
22#include <boost/container/detail/pool_resource.hpp>
23
24#include <cstddef>
25
26namespace boost {
27namespace container {
28namespace pmr {
29
30//! A synchronized_pool_resource is a general-purpose memory resources having
31//! the following qualities:
32//!
33//! - Each resource owns the allocated memory, and frees it on destruction,
34//! even if deallocate has not been called for some of the allocated blocks.
35//!
36//! - A pool resource consists of a collection of pools, serving
37//! requests for different block sizes. Each individual pool manages a
38//! collection of chunks that are in turn divided into blocks of uniform size,
39//! returned via calls to do_allocate. Each call to do_allocate(size, alignment)
40//! is dispatched to the pool serving the smallest blocks accommodating at
41//! least size bytes.
42//!
43//! - When a particular pool is exhausted, allocating a block from that pool
44//! results in the allocation of an additional chunk of memory from the upstream
45//! allocator (supplied at construction), thus replenishing the pool. With
46//! each successive replenishment, the chunk size obtained increases
47//! geometrically. [ Note: By allocating memory in chunks, the pooling strategy
48//! increases the chance that consecutive allocations will be close together
49//! in memory. - end note ]
50//!
51//! - Allocation requests that exceed the largest block size of any pool are
52//! fulfilled directly from the upstream allocator.
53//!
54//! - A pool_options struct may be passed to the pool resource constructors to
55//! tune the largest block size and the maximum chunk size.
56//!
57//! A synchronized_pool_resource may be accessed from multiple threads without
58//! external synchronization and may have thread-specific pools to reduce
59//! synchronization costs.
60class BOOST_CONTAINER_DECL synchronized_pool_resource
61 : public memory_resource
62{
63 pool_resource m_pool_resource;
64 void *m_opaque_sync;
65
66 public:
67
68 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(const pool_options&,memory_resource*)
69 synchronized_pool_resource(const pool_options& opts, memory_resource* upstream) BOOST_NOEXCEPT;
70
71 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource()
72 synchronized_pool_resource() BOOST_NOEXCEPT;
73
74 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(memory_resource*)
75 explicit synchronized_pool_resource(memory_resource* upstream) BOOST_NOEXCEPT;
76
77 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::unsynchronized_pool_resource(const pool_options&)
78 explicit synchronized_pool_resource(const pool_options& opts) BOOST_NOEXCEPT;
79
80 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
81 synchronized_pool_resource(const synchronized_pool_resource&) = delete;
82 synchronized_pool_resource operator=(const synchronized_pool_resource&) = delete;
83 #else
84 private:
85 synchronized_pool_resource (const synchronized_pool_resource&);
86 synchronized_pool_resource operator=(const synchronized_pool_resource&);
87 public:
88 #endif
89
90 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::~unsynchronized_pool_resource()
91 virtual ~synchronized_pool_resource();
92
93 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::release()
94 void release();
95
96 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::upstream_resource()const
97 memory_resource* upstream_resource() const;
98
99 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::options()const
100 pool_options options() const;
101
102 protected:
103
104 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_allocate()
105 virtual void* do_allocate(std::size_t bytes, std::size_t alignment);
106
107 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_deallocate(void*,std::size_t,std::size_t)
108 virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment);
109
110 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::do_is_equal(const memory_resource&)const
111 virtual bool do_is_equal(const memory_resource& other) const BOOST_NOEXCEPT;
112
113 //Non-standard observers
114 public:
115
116 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_count()
117 std::size_t pool_count() const;
118
119 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_index(std::size_t)const
120 std::size_t pool_index(std::size_t bytes) const;
121
122 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_next_blocks_per_chunk(std::size_t)const
123 std::size_t pool_next_blocks_per_chunk(std::size_t pool_idx) const;
124
125 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_block(std::size_t)const
126 std::size_t pool_block(std::size_t pool_idx) const;
127
128 //! @copydoc ::boost::container::pmr::unsynchronized_pool_resource::pool_cached_blocks(std::size_t)const
129 std::size_t pool_cached_blocks(std::size_t pool_idx) const;
130};
131
132} //namespace pmr {
133} //namespace container {
134} //namespace boost {
135
136#include <boost/container/detail/config_end.hpp>
137
138#endif //BOOST_CONTAINER_PMR_SYNCHRONIZED_POOL_RESOURCE_HPP