Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2022 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/url |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#include <boost/url/detail/config.hpp> |
11 |
|
|
#include <boost/url/grammar/detail/recycled.hpp> |
12 |
|
|
#include <cstdlib> |
13 |
|
|
#include <utility> |
14 |
|
|
#include <atomic> |
15 |
|
|
|
16 |
|
|
#ifdef BOOST_URL_REPORT |
17 |
|
|
# ifdef _MSC_VER |
18 |
|
|
# include <intrin.h> |
19 |
|
|
# endif |
20 |
|
|
#endif |
21 |
|
|
|
22 |
|
|
namespace boost { |
23 |
|
|
namespace urls { |
24 |
|
|
namespace grammar { |
25 |
|
|
namespace detail { |
26 |
|
|
|
27 |
|
|
struct all_reports |
28 |
|
|
{ |
29 |
|
|
// current count |
30 |
|
|
std::atomic<std::size_t> count = {0}; |
31 |
|
|
|
32 |
|
|
// current bytes |
33 |
|
|
std::atomic<std::size_t> bytes = {0}; |
34 |
|
|
|
35 |
|
|
// highest total ptr count |
36 |
|
|
std::atomic<std::size_t> count_max = {0}; |
37 |
|
|
|
38 |
|
|
// highest total bytes |
39 |
|
|
std::atomic<std::size_t> bytes_max = {0}; |
40 |
|
|
|
41 |
|
|
// largest single allocation |
42 |
|
|
std::atomic<std::size_t> alloc_max = {0}; |
43 |
|
|
|
44 |
|
72 |
~all_reports() |
45 |
|
|
{ |
46 |
|
|
// breakpoint here to view report |
47 |
|
|
#ifdef BOOST_URL_REPORT |
48 |
|
|
# ifdef _MSC_VER |
49 |
|
|
if(count_max > 0) |
50 |
|
|
::__debugbreak(); |
51 |
|
|
# endif |
52 |
|
|
#endif |
53 |
|
72 |
} |
54 |
|
|
}; |
55 |
|
|
|
56 |
|
|
static all_reports all_reports_; |
57 |
|
|
} // detail |
58 |
|
|
|
59 |
|
|
namespace see_below { |
60 |
|
|
void |
61 |
|
1 |
recycled_add_impl( |
62 |
|
|
std::size_t n) noexcept |
63 |
|
|
{ |
64 |
|
1 |
auto& a = detail::all_reports_; |
65 |
|
|
|
66 |
|
|
// LCOV_EXCL_START |
67 |
|
|
/* |
68 |
|
|
* We can't guarantee coverage |
69 |
|
|
* exercise of this path. |
70 |
|
|
*/ |
71 |
|
− |
std::size_t new_count = ++a.count; |
72 |
|
− |
std::size_t old_count_max = a.count_max; |
73 |
|
− |
while ( |
74 |
|
− |
old_count_max < new_count && |
75 |
|
− |
!a.count_max.compare_exchange_weak( |
76 |
|
|
old_count_max, new_count)) |
77 |
|
|
{} |
78 |
|
|
|
79 |
|
− |
std::size_t new_bytes = a.bytes.fetch_add(n) + n; |
80 |
|
− |
std::size_t old_bytes_max = a.bytes_max; |
81 |
|
− |
while ( |
82 |
|
− |
old_bytes_max < new_bytes && |
83 |
|
− |
!a.bytes_max.compare_exchange_weak( |
84 |
|
|
old_bytes_max, new_bytes)) |
85 |
|
|
{} |
86 |
|
|
|
87 |
|
− |
std::size_t old_alloc_max = a.alloc_max; |
88 |
|
− |
while ( |
89 |
|
− |
old_alloc_max < n && |
90 |
|
− |
!a.alloc_max.compare_exchange_weak( |
91 |
|
|
old_alloc_max, n)) |
92 |
|
|
{} |
93 |
|
|
// LCOV_EXCL_STOP |
94 |
|
1 |
} |
95 |
|
|
|
96 |
|
|
void |
97 |
|
1 |
recycled_remove_impl( |
98 |
|
|
std::size_t n) noexcept |
99 |
|
|
{ |
100 |
|
1 |
detail::all_reports_.count--; |
101 |
|
1 |
detail::all_reports_.bytes-=n; |
102 |
|
1 |
} |
103 |
|
|
} // see_below |
104 |
|
|
} // grammar |
105 |
|
|
} // urls |
106 |
|
|
} // boost |
107 |
|
|
|