Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:34:59

0001 //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/json
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) // non dll-interface class used as base for dll-interface class
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         // VFALCO Is always false ok?
0076         return false;
0077     }
0078 };
0079 
0080 #ifdef _MSC_VER
0081 #pragma warning(pop)
0082 #endif
0083 
0084 } // detail
0085 } // namespace json
0086 } // namespace boost
0087 
0088 #endif