diff options
author | armenqa <[email protected]> | 2024-01-19 12:23:50 +0300 |
---|---|---|
committer | armenqa <[email protected]> | 2024-01-19 13:10:03 +0300 |
commit | 2de0149d0151c514b22bca0760b95b26c9b0b578 (patch) | |
tree | 2bfed9f3bce7e643ddf048bb61ce3dc0a714bcc2 /contrib/libs/cxxsupp/libcxx/include/__memory_resource | |
parent | a8c06d218f12b2406fbce24d194885c5d7b68503 (diff) |
feat contrib: aiogram 3
Relates: https://st.yandex-team.ru/, https://st.yandex-team.ru/
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__memory_resource')
6 files changed, 610 insertions, 0 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/memory_resource.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/memory_resource.h new file mode 100644 index 00000000000..02fdd081cce --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/memory_resource.h @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H +#define _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H + +#include <__config> +#include <cstddef> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.res.class] + +class _LIBCPP_TYPE_VIS memory_resource { + static const size_t __max_align = alignof(max_align_t); + +public: + virtual ~memory_resource(); + + _LIBCPP_NODISCARD_AFTER_CXX17 + [[using __gnu__: __returns_nonnull__, __alloc_size__(2), __alloc_align__(3)]] _LIBCPP_HIDE_FROM_ABI void* + allocate(size_t __bytes, size_t __align = __max_align) { + return do_allocate(__bytes, __align); + } + + [[__gnu__::__nonnull__]] _LIBCPP_HIDE_FROM_ABI void + deallocate(void* __p, size_t __bytes, size_t __align = __max_align) { + do_deallocate(__p, __bytes, __align); + } + + _LIBCPP_HIDE_FROM_ABI bool is_equal(const memory_resource& __other) const noexcept { return do_is_equal(__other); } + +private: + virtual void* do_allocate(size_t, size_t) = 0; + virtual void do_deallocate(void*, size_t, size_t) = 0; + virtual bool do_is_equal(memory_resource const&) const noexcept = 0; +}; + +// [mem.res.eq] + +inline _LIBCPP_HIDE_FROM_ABI bool operator==(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { + return &__lhs == &__rhs || __lhs.is_equal(__rhs); +} + +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept { + return !(__lhs == __rhs); +} + +// [mem.res.global] + +[[__gnu__::__returns_nonnull__]] _LIBCPP_FUNC_VIS memory_resource* get_default_resource() noexcept; +[[__gnu__::__returns_nonnull__]] _LIBCPP_FUNC_VIS memory_resource* set_default_resource(memory_resource*) noexcept; +[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_FUNC_VIS memory_resource* new_delete_resource() noexcept; +[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_FUNC_VIS memory_resource* null_memory_resource() noexcept; + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +#endif // _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/monotonic_buffer_resource.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/monotonic_buffer_resource.h new file mode 100644 index 00000000000..5c35a62b166 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/monotonic_buffer_resource.h @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_MONOTONIC_BUFFER_RESOURCE_H +#define _LIBCPP___MEMORY_RESOURCE_MONOTONIC_BUFFER_RESOURCE_H + +#include <__config> +#include <__memory/addressof.h> +#include <__memory_resource/memory_resource.h> +#include <cstddef> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.res.monotonic.buffer] + +class _LIBCPP_TYPE_VIS monotonic_buffer_resource : public memory_resource { + static const size_t __default_buffer_capacity = 1024; + static const size_t __default_buffer_alignment = 16; + + struct __chunk_footer { + __chunk_footer* __next_; + char* __start_; + char* __cur_; + size_t __align_; + size_t __allocation_size() { return (reinterpret_cast<char*>(this) - __start_) + sizeof(*this); } + void* __try_allocate_from_chunk(size_t, size_t); + }; + + struct __initial_descriptor { + char* __start_; + char* __cur_; + union { + char* __end_; + size_t __size_; + }; + void* __try_allocate_from_chunk(size_t, size_t); + }; + +public: + _LIBCPP_HIDE_FROM_ABI monotonic_buffer_resource() + : monotonic_buffer_resource(nullptr, __default_buffer_capacity, get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI explicit monotonic_buffer_resource(size_t __initial_size) + : monotonic_buffer_resource(nullptr, __initial_size, get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI monotonic_buffer_resource(void* __buffer, size_t __buffer_size) + : monotonic_buffer_resource(__buffer, __buffer_size, get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI explicit monotonic_buffer_resource(memory_resource* __upstream) + : monotonic_buffer_resource(nullptr, __default_buffer_capacity, __upstream) {} + + _LIBCPP_HIDE_FROM_ABI monotonic_buffer_resource(size_t __initial_size, memory_resource* __upstream) + : monotonic_buffer_resource(nullptr, __initial_size, __upstream) {} + + _LIBCPP_HIDE_FROM_ABI monotonic_buffer_resource(void* __buffer, size_t __buffer_size, memory_resource* __upstream) + : __res_(__upstream) { + __initial_.__start_ = static_cast<char*>(__buffer); + if (__buffer != nullptr) { + __initial_.__cur_ = static_cast<char*>(__buffer); + __initial_.__end_ = static_cast<char*>(__buffer) + __buffer_size; + } else { + __initial_.__cur_ = nullptr; + __initial_.__size_ = __buffer_size; + } + __chunks_ = nullptr; + } + + monotonic_buffer_resource(const monotonic_buffer_resource&) = delete; + + _LIBCPP_HIDE_FROM_ABI ~monotonic_buffer_resource() override { release(); } + + monotonic_buffer_resource& operator=(const monotonic_buffer_resource&) = delete; + + _LIBCPP_HIDE_FROM_ABI void release() { + __initial_.__cur_ = __initial_.__start_; + while (__chunks_ != nullptr) { + __chunk_footer* __next = __chunks_->__next_; + __res_->deallocate(__chunks_->__start_, __chunks_->__allocation_size(), __chunks_->__align_); + __chunks_ = __next; + } + } + + _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; } + +protected: + void* do_allocate(size_t __bytes, size_t __alignment) override; // key function + + _LIBCPP_HIDE_FROM_ABI void do_deallocate(void*, size_t, size_t) override {} + + _LIBCPP_HIDE_FROM_ABI bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override { + return this == std::addressof(__other); + } + +private: + __initial_descriptor __initial_; + __chunk_footer* __chunks_; + memory_resource* __res_; +}; + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +#endif // _LIBCPP___MEMORY_RESOURCE_MONOTONIC_BUFFER_RESOURCE_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/polymorphic_allocator.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/polymorphic_allocator.h new file mode 100644 index 00000000000..a5ca39b57e6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/polymorphic_allocator.h @@ -0,0 +1,178 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_POLYMORPHIC_ALLOCATOR_H +#define _LIBCPP___MEMORY_RESOURCE_POLYMORPHIC_ALLOCATOR_H + +#include <__assert> +#include <__config> +#include <__memory_resource/memory_resource.h> +#include <cstddef> +#include <limits> +#include <new> +#include <stdexcept> +#include <tuple> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.poly.allocator.class] + +template <class _ValueType> +class _LIBCPP_TEMPLATE_VIS polymorphic_allocator { +public: + using value_type = _ValueType; + + // [mem.poly.allocator.ctor] + + _LIBCPP_HIDE_FROM_ABI polymorphic_allocator() noexcept : __res_(std::pmr::get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI polymorphic_allocator(memory_resource* __r) noexcept : __res_(__r) {} + + polymorphic_allocator(const polymorphic_allocator&) = default; + + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI polymorphic_allocator(const polymorphic_allocator<_Tp>& __other) noexcept + : __res_(__other.resource()) {} + + polymorphic_allocator& operator=(const polymorphic_allocator&) = delete; + + // [mem.poly.allocator.mem] + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _ValueType* allocate(size_t __n) { + if (__n > __max_size()) { + __throw_bad_array_new_length(); + } + return static_cast<_ValueType*>(__res_->allocate(__n * sizeof(_ValueType), alignof(_ValueType))); + } + + _LIBCPP_HIDE_FROM_ABI void deallocate(_ValueType* __p, size_t __n) { + _LIBCPP_ASSERT(__n <= __max_size(), "deallocate called for size which exceeds max_size()"); + __res_->deallocate(__p, __n * sizeof(_ValueType), alignof(_ValueType)); + } + + template <class _Tp, class... _Ts> + _LIBCPP_HIDE_FROM_ABI void construct(_Tp* __p, _Ts&&... __args) { + std::__user_alloc_construct_impl( + typename __uses_alloc_ctor<_Tp, polymorphic_allocator&, _Ts...>::type(), + __p, + *this, + std::forward<_Ts>(__args)...); + } + + template <class _T1, class _T2, class... _Args1, class... _Args2> + _LIBCPP_HIDE_FROM_ABI void + construct(pair<_T1, _T2>* __p, piecewise_construct_t, tuple<_Args1...> __x, tuple<_Args2...> __y) { + ::new ((void*)__p) pair<_T1, _T2>( + piecewise_construct, + __transform_tuple(typename __uses_alloc_ctor< _T1, polymorphic_allocator&, _Args1... >::type(), + std::move(__x), + typename __make_tuple_indices<sizeof...(_Args1)>::type{}), + __transform_tuple(typename __uses_alloc_ctor< _T2, polymorphic_allocator&, _Args2... >::type(), + std::move(__y), + typename __make_tuple_indices<sizeof...(_Args2)>::type{})); + } + + template <class _T1, class _T2> + _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p) { + construct(__p, piecewise_construct, tuple<>(), tuple<>()); + } + + template <class _T1, class _T2, class _Up, class _Vp> + _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, _Up&& __u, _Vp&& __v) { + construct(__p, + piecewise_construct, + std::forward_as_tuple(std::forward<_Up>(__u)), + std::forward_as_tuple(std::forward<_Vp>(__v))); + } + + template <class _T1, class _T2, class _U1, class _U2> + _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, const pair<_U1, _U2>& __pr) { + construct(__p, piecewise_construct, std::forward_as_tuple(__pr.first), std::forward_as_tuple(__pr.second)); + } + + template <class _T1, class _T2, class _U1, class _U2> + _LIBCPP_HIDE_FROM_ABI void construct(pair<_T1, _T2>* __p, pair<_U1, _U2>&& __pr) { + construct(__p, + piecewise_construct, + std::forward_as_tuple(std::forward<_U1>(__pr.first)), + std::forward_as_tuple(std::forward<_U2>(__pr.second))); + } + + template <class _Tp> + _LIBCPP_HIDE_FROM_ABI void destroy(_Tp* __p) { + __p->~_Tp(); + } + + _LIBCPP_HIDE_FROM_ABI polymorphic_allocator select_on_container_copy_construction() const noexcept { + return polymorphic_allocator(); + } + + _LIBCPP_HIDE_FROM_ABI memory_resource* resource() const noexcept { return __res_; } + +private: + template <class... _Args, size_t... _Is> + _LIBCPP_HIDE_FROM_ABI tuple<_Args&&...> + __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + return std::forward_as_tuple(std::get<_Is>(std::move(__t))...); + } + + template <class... _Args, size_t... _Is> + _LIBCPP_HIDE_FROM_ABI tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...> + __transform_tuple(integral_constant<int, 1>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + using _Tup = tuple<allocator_arg_t const&, polymorphic_allocator&, _Args&&...>; + return _Tup(allocator_arg, *this, std::get<_Is>(std::move(__t))...); + } + + template <class... _Args, size_t... _Is> + _LIBCPP_HIDE_FROM_ABI tuple<_Args&&..., polymorphic_allocator&> + __transform_tuple(integral_constant<int, 2>, tuple<_Args...>&& __t, __tuple_indices<_Is...>) { + using _Tup = tuple<_Args&&..., polymorphic_allocator&>; + return _Tup(std::get<_Is>(std::move(__t))..., *this); + } + + _LIBCPP_HIDE_FROM_ABI size_t __max_size() const noexcept { + return numeric_limits<size_t>::max() / sizeof(value_type); + } + + memory_resource* __res_; +}; + +// [mem.poly.allocator.eq] + +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool +operator==(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator<_Up>& __rhs) noexcept { + return *__lhs.resource() == *__rhs.resource(); +} + +template <class _Tp, class _Up> +inline _LIBCPP_HIDE_FROM_ABI bool +operator!=(const polymorphic_allocator<_Tp>& __lhs, const polymorphic_allocator<_Up>& __rhs) noexcept { + return !(__lhs == __rhs); +} + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___MEMORY_RESOURCE_POLYMORPHIC_ALLOCATOR_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/pool_options.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/pool_options.h new file mode 100644 index 00000000000..11585a0e3bc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/pool_options.h @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_POOL_OPTIONS_H +#define _LIBCPP___MEMORY_RESOURCE_POOL_OPTIONS_H + +#include <__config> +#include <cstddef> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.res.pool.options] + +struct _LIBCPP_TYPE_VIS pool_options { + size_t max_blocks_per_chunk = 0; + size_t largest_required_pool_block = 0; +}; + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +#endif // _LIBCPP___MEMORY_RESOURCE_POOL_OPTIONS_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/synchronized_pool_resource.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/synchronized_pool_resource.h new file mode 100644 index 00000000000..550223c7d96 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/synchronized_pool_resource.h @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H +#define _LIBCPP___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H + +#include <__config> +#include <__memory_resource/memory_resource.h> +#include <__memory_resource/pool_options.h> +#include <__memory_resource/unsynchronized_pool_resource.h> +#include <cstddef> +#if !defined(_LIBCPP_HAS_NO_THREADS) +# include <mutex> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.res.pool.overview] + +class _LIBCPP_TYPE_VIS synchronized_pool_resource : public memory_resource { +public: + _LIBCPP_HIDE_FROM_ABI synchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream) + : __unsync_(__opts, __upstream) {} + + _LIBCPP_HIDE_FROM_ABI synchronized_pool_resource() + : synchronized_pool_resource(pool_options(), get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI explicit synchronized_pool_resource(memory_resource* __upstream) + : synchronized_pool_resource(pool_options(), __upstream) {} + + _LIBCPP_HIDE_FROM_ABI explicit synchronized_pool_resource(const pool_options& __opts) + : synchronized_pool_resource(__opts, get_default_resource()) {} + + synchronized_pool_resource(const synchronized_pool_resource&) = delete; + + ~synchronized_pool_resource() override = default; + + synchronized_pool_resource& operator=(const synchronized_pool_resource&) = delete; + + _LIBCPP_HIDE_FROM_ABI void release() { +# if !defined(_LIBCPP_HAS_NO_THREADS) + unique_lock<mutex> __lk(__mut_); +# endif + __unsync_.release(); + } + + _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __unsync_.upstream_resource(); } + + _LIBCPP_HIDE_FROM_ABI pool_options options() const { return __unsync_.options(); } + +protected: + _LIBCPP_HIDE_FROM_ABI void* do_allocate(size_t __bytes, size_t __align) override { +# if !defined(_LIBCPP_HAS_NO_THREADS) + unique_lock<mutex> __lk(__mut_); +# endif + return __unsync_.allocate(__bytes, __align); + } + + _LIBCPP_HIDE_FROM_ABI void do_deallocate(void* __p, size_t __bytes, size_t __align) override { +# if !defined(_LIBCPP_HAS_NO_THREADS) + unique_lock<mutex> __lk(__mut_); +# endif + return __unsync_.deallocate(__p, __bytes, __align); + } + + bool do_is_equal(const memory_resource& __other) const noexcept override; // key function + +private: +# if !defined(_LIBCPP_HAS_NO_THREADS) + mutex __mut_; +# endif + unsynchronized_pool_resource __unsync_; +}; + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +#endif // _LIBCPP___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H diff --git a/contrib/libs/cxxsupp/libcxx/include/__memory_resource/unsynchronized_pool_resource.h b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/unsynchronized_pool_resource.h new file mode 100644 index 00000000000..7270cf19e21 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxx/include/__memory_resource/unsynchronized_pool_resource.h @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H +#define _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H + +#include <__config> +#include <__memory_resource/memory_resource.h> +#include <__memory_resource/pool_options.h> +#include <cstddef> +#include <cstdint> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 14 + +_LIBCPP_BEGIN_NAMESPACE_STD + +namespace pmr { + +// [mem.res.pool.overview] + +class _LIBCPP_TYPE_VIS unsynchronized_pool_resource : public memory_resource { + class __fixed_pool; + + class __adhoc_pool { + struct __chunk_footer; + __chunk_footer* __first_; + + public: + _LIBCPP_HIDE_FROM_ABI explicit __adhoc_pool() : __first_(nullptr) {} + + void __release_ptr(memory_resource* __upstream); + void* __do_allocate(memory_resource* __upstream, size_t __bytes, size_t __align); + void __do_deallocate(memory_resource* __upstream, void* __p, size_t __bytes, size_t __align); + }; + + static const size_t __min_blocks_per_chunk = 16; + static const size_t __min_bytes_per_chunk = 1024; + static const size_t __max_blocks_per_chunk = (size_t(1) << 20); + static const size_t __max_bytes_per_chunk = (size_t(1) << 30); + + static const int __log2_smallest_block_size = 3; + static const size_t __smallest_block_size = 8; + static const size_t __default_largest_block_size = (size_t(1) << 20); + static const size_t __max_largest_block_size = (size_t(1) << 30); + + size_t __pool_block_size(int __i) const; + int __log2_pool_block_size(int __i) const; + int __pool_index(size_t __bytes, size_t __align) const; + +public: + unsynchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream); + + _LIBCPP_HIDE_FROM_ABI unsynchronized_pool_resource() + : unsynchronized_pool_resource(pool_options(), get_default_resource()) {} + + _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(memory_resource* __upstream) + : unsynchronized_pool_resource(pool_options(), __upstream) {} + + _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(const pool_options& __opts) + : unsynchronized_pool_resource(__opts, get_default_resource()) {} + + unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete; + + _LIBCPP_HIDE_FROM_ABI ~unsynchronized_pool_resource() override { release(); } + + unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete; + + void release(); + + _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; } + + [[__gnu__::__pure__]] pool_options options() const; + +protected: + void* do_allocate(size_t __bytes, size_t __align) override; // key function + + void do_deallocate(void* __p, size_t __bytes, size_t __align) override; + + _LIBCPP_HIDE_FROM_ABI bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override { + return &__other == this; + } + +private: + memory_resource* __res_; + __adhoc_pool __adhoc_pool_; + __fixed_pool* __fixed_pools_; + int __num_fixed_pools_; + uint32_t __options_max_blocks_per_chunk_; +}; + +} // namespace pmr + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 14 + +#endif // _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H |