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