File indexing completed on 2025-07-14 08:34:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_DETAIL_SHARED_RESOURCE_HPP
0011 #define BOOST_JSON_DETAIL_SHARED_RESOURCE_HPP
0012
0013 #include <boost/container/pmr/memory_resource.hpp>
0014 #include <boost/json/memory_resource.hpp>
0015 #include <atomic>
0016 #include <utility>
0017
0018 namespace boost {
0019 namespace json {
0020 namespace detail {
0021
0022 #ifdef _MSC_VER
0023 #pragma warning(push)
0024 #pragma warning(disable: 4275)
0025 #endif
0026
0027 struct BOOST_SYMBOL_VISIBLE
0028 shared_resource
0029 : container::pmr::memory_resource
0030 {
0031 BOOST_JSON_DECL
0032 shared_resource();
0033
0034 BOOST_JSON_DECL
0035 ~shared_resource();
0036
0037 std::atomic<std::size_t> refs{ 1 };
0038 };
0039
0040 template<class T>
0041 class shared_resource_impl final
0042 : public shared_resource
0043 {
0044 T t;
0045
0046 public:
0047 template<class... Args>
0048 shared_resource_impl(
0049 Args&&... args)
0050 : t(std::forward<Args>(args)...)
0051 {
0052 }
0053
0054 void*
0055 do_allocate(
0056 std::size_t n,
0057 std::size_t align) override
0058 {
0059 return t.allocate(n, align);
0060 }
0061
0062 void
0063 do_deallocate(
0064 void* p,
0065 std::size_t n,
0066 std::size_t align) override
0067 {
0068 return t.deallocate(p, n, align);
0069 }
0070
0071 bool
0072 do_is_equal(
0073 memory_resource const&) const noexcept override
0074 {
0075
0076 return false;
0077 }
0078 };
0079
0080 #ifdef _MSC_VER
0081 #pragma warning(pop)
0082 #endif
0083
0084 }
0085 }
0086 }
0087
0088 #endif