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: 10 10 100.0 %
Date: 2024-03-15 21:27:27 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             :     // LCOV_EXCL_START
      65             :     /*
      66             :      * We can't guarantee coverage
      67             :      * exercise of this path.
      68             :      */
      69             :     std::size_t new_count = ++a.count;
      70             :     std::size_t old_count_max = a.count_max;
      71             :     while (
      72             :         old_count_max < new_count &&
      73             :         !a.count_max.compare_exchange_weak(
      74             :             old_count_max, new_count))
      75             :     {}
      76             : 
      77             :     std::size_t new_bytes = a.bytes.fetch_add(n) + n;
      78             :     std::size_t old_bytes_max = a.bytes_max;
      79             :     while (
      80             :         old_bytes_max < new_bytes &&
      81             :         !a.bytes_max.compare_exchange_weak(
      82             :             old_bytes_max, new_bytes))
      83             :     {}
      84             : 
      85             :     std::size_t old_alloc_max = a.alloc_max;
      86             :     while (
      87             :         old_alloc_max < n &&
      88             :         !a.alloc_max.compare_exchange_weak(
      89             :             old_alloc_max, n))
      90             :     {}
      91             :     // LCOV_EXCL_STOP
      92           1 : }
      93             : 
      94             : void
      95           1 : recycled_remove_impl(
      96             :     std::size_t n) noexcept
      97             : {
      98           1 :     all_reports_.count--;
      99           1 :     all_reports_.bytes-=n;
     100           1 : }
     101             : 
     102             : } // detail
     103             : } // grammar
     104             : } // urls
     105             : } // boost

Generated by: LCOV version 1.15