mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-25 14:52:28 +00:00
Upgrade to 2022-era LLVM LIBCXX
This commit is contained in:
parent
2f4ca71f26
commit
8e68384e15
2078 changed files with 165657 additions and 65010 deletions
75
third_party/libcxx/__memory_resource/memory_resource.h
vendored
Normal file
75
third_party/libcxx/__memory_resource/memory_resource.h
vendored
Normal file
|
@ -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 >= 17
|
||||
|
||||
_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 >= 17
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H
|
122
third_party/libcxx/__memory_resource/monotonic_buffer_resource.h
vendored
Normal file
122
third_party/libcxx/__memory_resource/monotonic_buffer_resource.h
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 >= 17
|
||||
|
||||
_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_;
|
||||
_LIBCPP_HIDE_FROM_ABI 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) + __buffer_size;
|
||||
__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_VIRTUAL ~monotonic_buffer_resource() override { release(); }
|
||||
|
||||
monotonic_buffer_resource& operator=(const monotonic_buffer_resource&) = delete;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI void release() {
|
||||
if (__initial_.__start_ != nullptr)
|
||||
__initial_.__cur_ = __initial_.__end_;
|
||||
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_VIRTUAL void do_deallocate(void*, size_t, size_t) override {}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI_VIRTUAL 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 >= 17
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_MONOTONIC_BUFFER_RESOURCE_H
|
224
third_party/libcxx/__memory_resource/polymorphic_allocator.h
vendored
Normal file
224
third_party/libcxx/__memory_resource/polymorphic_allocator.h
vendored
Normal file
|
@ -0,0 +1,224 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 <__utility/exception_guard.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 >= 17
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace pmr {
|
||||
|
||||
// [mem.poly.allocator.class]
|
||||
|
||||
template <class _ValueType
|
||||
# if _LIBCPP_STD_VER >= 20
|
||||
= byte
|
||||
# endif
|
||||
>
|
||||
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) {}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI 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));
|
||||
}
|
||||
|
||||
# if _LIBCPP_STD_VER >= 20
|
||||
|
||||
[[nodiscard]] [[using __gnu__: __alloc_size__(2), __alloc_align__(3)]] _LIBCPP_HIDE_FROM_ABI void*
|
||||
allocate_bytes(size_t __nbytes, size_t __alignment = alignof(max_align_t)) {
|
||||
return __res_->allocate(__nbytes, __alignment);
|
||||
}
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI void deallocate_bytes(void* __ptr, size_t __nbytes, size_t __alignment = alignof(max_align_t)) {
|
||||
__res_->deallocate(__ptr, __nbytes, __alignment);
|
||||
}
|
||||
|
||||
template <class _Type>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Type* allocate_object(size_t __n = 1) {
|
||||
if (numeric_limits<size_t>::max() / sizeof(_Type) < __n)
|
||||
std::__throw_bad_array_new_length();
|
||||
return static_cast<_Type*>(allocate_bytes(__n * sizeof(_Type), alignof(_Type)));
|
||||
}
|
||||
|
||||
template <class _Type>
|
||||
_LIBCPP_HIDE_FROM_ABI void deallocate_object(_Type* __ptr, size_t __n = 1) {
|
||||
deallocate_bytes(__ptr, __n * sizeof(_Type), alignof(_Type));
|
||||
}
|
||||
|
||||
template <class _Type, class... _CtorArgs>
|
||||
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Type* new_object(_CtorArgs&&... __ctor_args) {
|
||||
_Type* __ptr = allocate_object<_Type>();
|
||||
auto __guard = std::__make_exception_guard([&] { deallocate_object(__ptr); });
|
||||
construct(__ptr, std::forward<_CtorArgs>(__ctor_args)...);
|
||||
__guard.__complete();
|
||||
return __ptr;
|
||||
}
|
||||
|
||||
template <class _Type>
|
||||
_LIBCPP_HIDE_FROM_ABI void delete_object(_Type* __ptr) {
|
||||
destroy(__ptr);
|
||||
deallocate_object(__ptr);
|
||||
}
|
||||
|
||||
# endif // _LIBCPP_STD_VER >= 20
|
||||
|
||||
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 >= 17
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_POLYMORPHIC_ALLOCATOR_H
|
38
third_party/libcxx/__memory_resource/pool_options.h
vendored
Normal file
38
third_party/libcxx/__memory_resource/pool_options.h
vendored
Normal file
|
@ -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 >= 17
|
||||
|
||||
_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 >= 17
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_POOL_OPTIONS_H
|
94
third_party/libcxx/__memory_resource/synchronized_pool_resource.h
vendored
Normal file
94
third_party/libcxx/__memory_resource/synchronized_pool_resource.h
vendored
Normal file
|
@ -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 >= 17
|
||||
|
||||
_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;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI_VIRTUAL ~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_VIRTUAL 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_VIRTUAL 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 >= 17
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H
|
106
third_party/libcxx/__memory_resource/unsynchronized_pool_resource.h
vendored
Normal file
106
third_party/libcxx/__memory_resource/unsynchronized_pool_resource.h
vendored
Normal file
|
@ -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 >= 17
|
||||
|
||||
_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_VIRTUAL ~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_VIRTUAL 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 >= 17
|
||||
|
||||
#endif // _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
|
Loading…
Add table
Add a link
Reference in a new issue