LCOV - code coverage report
Current view: top level - libs/url/src/grammar/detail - recycled.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 21 24 87.5 %
Date: 2024-01-19 15:42:53 Functions: 3 3 100.0 %

          Line data    Source code
       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          72 :     {
      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             : 
      58             : void
      59           1 : recycled_add_impl(
      60             :     std::size_t n) noexcept
      61             : {
      62           1 :     auto& a = all_reports_;
      63             : 
      64           1 :     std::size_t new_count = ++a.count;
      65           1 :     std::size_t old_count_max = a.count_max;
      66           0 :     while (
      67           2 :         old_count_max < new_count &&
      68           2 :         !a.count_max.compare_exchange_weak(
      69             :             old_count_max, new_count))
      70             :     {}
      71             : 
      72           1 :     std::size_t new_bytes = a.bytes.fetch_add(n) + n;
      73           1 :     std::size_t old_bytes_max = a.bytes_max;
      74           0 :     while (
      75           2 :         old_bytes_max < new_bytes &&
      76           2 :         !a.bytes_max.compare_exchange_weak(
      77             :             old_bytes_max, new_bytes))
      78             :     {}
      79             : 
      80           1 :     std::size_t old_alloc_max = a.alloc_max;
      81           0 :     while (
      82           2 :         old_alloc_max < n &&
      83           2 :         !a.alloc_max.compare_exchange_weak(
      84             :             old_alloc_max, n))
      85             :     {}
      86           1 : }
      87             : 
      88             : void
      89           1 : recycled_remove_impl(
      90             :     std::size_t n) noexcept
      91             : {
      92           1 :     all_reports_.count--;
      93           1 :     all_reports_.bytes-=n;
      94           1 : }
      95             : 
      96             : } // detail
      97             : } // grammar
      98             : } // urls
      99             : } // boost

Generated by: LCOV version 1.15