Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:36

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H
0010 #define _LIBCPP___CXX03___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__memory_resource/memory_resource.h>
0014 #include <__cxx03/__memory_resource/pool_options.h>
0015 #include <__cxx03/__memory_resource/unsynchronized_pool_resource.h>
0016 #include <__cxx03/cstddef>
0017 #include <__cxx03/mutex>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 #if _LIBCPP_STD_VER >= 17
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 
0027 namespace pmr {
0028 
0029 // [mem.res.pool.overview]
0030 
0031 class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI synchronized_pool_resource : public memory_resource {
0032 public:
0033   _LIBCPP_HIDE_FROM_ABI synchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream)
0034       : __unsync_(__opts, __upstream) {}
0035 
0036   _LIBCPP_HIDE_FROM_ABI synchronized_pool_resource()
0037       : synchronized_pool_resource(pool_options(), get_default_resource()) {}
0038 
0039   _LIBCPP_HIDE_FROM_ABI explicit synchronized_pool_resource(memory_resource* __upstream)
0040       : synchronized_pool_resource(pool_options(), __upstream) {}
0041 
0042   _LIBCPP_HIDE_FROM_ABI explicit synchronized_pool_resource(const pool_options& __opts)
0043       : synchronized_pool_resource(__opts, get_default_resource()) {}
0044 
0045   synchronized_pool_resource(const synchronized_pool_resource&) = delete;
0046 
0047   _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~synchronized_pool_resource() override = default;
0048 
0049   synchronized_pool_resource& operator=(const synchronized_pool_resource&) = delete;
0050 
0051   _LIBCPP_HIDE_FROM_ABI void release() {
0052 #  if !defined(_LIBCPP_HAS_NO_THREADS)
0053     unique_lock<mutex> __lk(__mut_);
0054 #  endif
0055     __unsync_.release();
0056   }
0057 
0058   _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __unsync_.upstream_resource(); }
0059 
0060   _LIBCPP_HIDE_FROM_ABI pool_options options() const { return __unsync_.options(); }
0061 
0062 protected:
0063   _LIBCPP_HIDE_FROM_ABI_VIRTUAL void* do_allocate(size_t __bytes, size_t __align) override {
0064 #  if !defined(_LIBCPP_HAS_NO_THREADS)
0065     unique_lock<mutex> __lk(__mut_);
0066 #  endif
0067     return __unsync_.allocate(__bytes, __align);
0068   }
0069 
0070   _LIBCPP_HIDE_FROM_ABI_VIRTUAL void do_deallocate(void* __p, size_t __bytes, size_t __align) override {
0071 #  if !defined(_LIBCPP_HAS_NO_THREADS)
0072     unique_lock<mutex> __lk(__mut_);
0073 #  endif
0074     return __unsync_.deallocate(__p, __bytes, __align);
0075   }
0076 
0077   bool do_is_equal(const memory_resource& __other) const noexcept override; // key function
0078 
0079 private:
0080 #  if !defined(_LIBCPP_HAS_NO_THREADS)
0081   mutex __mut_;
0082 #  endif
0083   unsynchronized_pool_resource __unsync_;
0084 };
0085 
0086 } // namespace pmr
0087 
0088 _LIBCPP_END_NAMESPACE_STD
0089 
0090 #endif // _LIBCPP_STD_VER >= 17
0091 
0092 #endif // _LIBCPP___CXX03___MEMORY_RESOURCE_SYNCHRONIZED_POOL_RESOURCE_H