[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __memory_resource / unsynchronized_pool_resource.h
blob92da16c559fea84ebe7c316a8520ef9d2e63a5f3
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
10 #define _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
12 #include <__config>
13 #include <__cstddef/size_t.h>
14 #include <__memory_resource/memory_resource.h>
15 #include <__memory_resource/pool_options.h>
16 #include <cstdint>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
20 #endif
22 #if _LIBCPP_STD_VER >= 17
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 namespace pmr {
28 // [mem.res.pool.overview]
30 class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI unsynchronized_pool_resource : public memory_resource {
31 class __fixed_pool;
33 class __adhoc_pool {
34 struct __chunk_footer;
35 __chunk_footer* __first_;
37 public:
38 _LIBCPP_HIDE_FROM_ABI explicit __adhoc_pool() : __first_(nullptr) {}
40 void __release_ptr(memory_resource* __upstream);
41 void* __do_allocate(memory_resource* __upstream, size_t __bytes, size_t __align);
42 void __do_deallocate(memory_resource* __upstream, void* __p, size_t __bytes, size_t __align);
45 static const size_t __min_blocks_per_chunk = 16;
46 static const size_t __min_bytes_per_chunk = 1024;
47 static const size_t __max_blocks_per_chunk = (size_t(1) << 20);
48 static const size_t __max_bytes_per_chunk = (size_t(1) << 30);
50 static const int __log2_smallest_block_size = 3;
51 static const size_t __smallest_block_size = 8;
52 static const size_t __default_largest_block_size = (size_t(1) << 20);
53 static const size_t __max_largest_block_size = (size_t(1) << 30);
55 size_t __pool_block_size(int __i) const;
56 int __log2_pool_block_size(int __i) const;
57 int __pool_index(size_t __bytes, size_t __align) const;
59 public:
60 unsynchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream);
62 _LIBCPP_HIDE_FROM_ABI unsynchronized_pool_resource()
63 : unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
65 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(memory_resource* __upstream)
66 : unsynchronized_pool_resource(pool_options(), __upstream) {}
68 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(const pool_options& __opts)
69 : unsynchronized_pool_resource(__opts, get_default_resource()) {}
71 unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
73 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~unsynchronized_pool_resource() override { release(); }
75 unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete;
77 void release();
79 _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
81 [[__gnu__::__pure__]] pool_options options() const;
83 protected:
84 void* do_allocate(size_t __bytes, size_t __align) override; // key function
86 void do_deallocate(void* __p, size_t __bytes, size_t __align) override;
88 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
89 return &__other == this;
92 private:
93 memory_resource* __res_;
94 __adhoc_pool __adhoc_pool_;
95 __fixed_pool* __fixed_pools_;
96 int __num_fixed_pools_;
97 uint32_t __options_max_blocks_per_chunk_;
100 } // namespace pmr
102 _LIBCPP_END_NAMESPACE_STD
104 #endif // _LIBCPP_STD_VER >= 17
106 #endif // _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H