detail/shared_resource.hpp
68.8% Lines (22/32)
61.5% List of functions (8/13)
Functions (13)
Function
Calls
Lines
Branches
Blocks
boost::json::detail::shared_resource_impl<boost::json::monotonic_resource>::shared_resource_impl<>()
:47
11x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::static_resource>::shared_resource_impl<unsigned char (&) [1024]>(unsigned char (&) [1024])
:47
1x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::storage_ptr_test::throwing>::shared_resource_impl<>()
:47
1x
100.0%
–
80.0%
boost::json::detail::shared_resource_impl<boost::json::unique_resource>::shared_resource_impl<>()
:47
8x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::monotonic_resource>::do_allocate(unsigned long, unsigned long)
:54
27x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::static_resource>::do_allocate(unsigned long, unsigned long)
:54
0
0.0%
–
0.0%
boost::json::detail::shared_resource_impl<boost::json::storage_ptr_test::throwing>::do_allocate(unsigned long, unsigned long)
:54
0
0.0%
–
0.0%
boost::json::detail::shared_resource_impl<boost::json::unique_resource>::do_allocate(unsigned long, unsigned long)
:54
22x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::monotonic_resource>::do_deallocate(void*, unsigned long, unsigned long)
:62
27x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::static_resource>::do_deallocate(void*, unsigned long, unsigned long)
:62
0
0.0%
–
0.0%
boost::json::detail::shared_resource_impl<boost::json::storage_ptr_test::throwing>::do_deallocate(void*, unsigned long, unsigned long)
:62
0
0.0%
–
0.0%
boost::json::detail::shared_resource_impl<boost::json::unique_resource>::do_deallocate(void*, unsigned long, unsigned long)
:62
22x
100.0%
–
100.0%
boost::json::detail::shared_resource_impl<boost::json::monotonic_resource>::do_is_equal(boost::container::pmr::memory_resource const&) const
:71
0
0.0%
–
0.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/json | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_JSON_DETAIL_SHARED_RESOURCE_HPP | ||
| 11 | #define BOOST_JSON_DETAIL_SHARED_RESOURCE_HPP | ||
| 12 | |||
| 13 | #include <boost/container/pmr/memory_resource.hpp> | ||
| 14 | #include <atomic> | ||
| 15 | #include <utility> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace json { | ||
| 19 | namespace detail { | ||
| 20 | |||
| 21 | #ifdef _MSC_VER | ||
| 22 | #pragma warning(push) | ||
| 23 | #pragma warning(disable: 4275) // non dll-interface class used as base for dll-interface class | ||
| 24 | #endif | ||
| 25 | |||
| 26 | struct BOOST_SYMBOL_VISIBLE | ||
| 27 | shared_resource | ||
| 28 | : container::pmr::memory_resource | ||
| 29 | { | ||
| 30 | BOOST_JSON_DECL | ||
| 31 | shared_resource(); | ||
| 32 | |||
| 33 | BOOST_JSON_DECL | ||
| 34 | ~shared_resource(); | ||
| 35 | |||
| 36 | std::atomic<std::size_t> refs{ 1 }; | ||
| 37 | }; | ||
| 38 | |||
| 39 | template<class T> | ||
| 40 | class shared_resource_impl final | ||
| 41 | : public shared_resource | ||
| 42 | { | ||
| 43 | T t; | ||
| 44 | |||
| 45 | public: | ||
| 46 | template<class... Args> | ||
| 47 | 21x | shared_resource_impl( | |
| 48 | Args&&... args) | ||
| 49 | 21x | : t(std::forward<Args>(args)...) | |
| 50 | { | ||
| 51 | 21x | } | |
| 52 | |||
| 53 | void* | ||
| 54 | 49x | do_allocate( | |
| 55 | std::size_t n, | ||
| 56 | std::size_t align) override | ||
| 57 | { | ||
| 58 | 49x | return t.allocate(n, align); | |
| 59 | } | ||
| 60 | |||
| 61 | void | ||
| 62 | 49x | do_deallocate( | |
| 63 | void* p, | ||
| 64 | std::size_t n, | ||
| 65 | std::size_t align) override | ||
| 66 | { | ||
| 67 | 49x | return t.deallocate(p, n, align); | |
| 68 | } | ||
| 69 | |||
| 70 | bool | ||
| 71 | 12x | do_is_equal( | |
| 72 | memory_resource const&) const noexcept override | ||
| 73 | { | ||
| 74 | // VFALCO Is always false ok? | ||
| 75 | 12x | return false; | |
| 76 | } | ||
| 77 | }; | ||
| 78 | |||
| 79 | #ifdef _MSC_VER | ||
| 80 | #pragma warning(pop) | ||
| 81 | #endif | ||
| 82 | |||
| 83 | } // detail | ||
| 84 | } // namespace json | ||
| 85 | } // namespace boost | ||
| 86 | |||
| 87 | #endif | ||
| 88 |