Skip to content

Commit

Permalink
support BOOST_URL_DISABLE_THREADS
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Feb 21, 2023
1 parent b49fd36 commit 58ed304
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 30 deletions.
14 changes: 13 additions & 1 deletion .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def main(ctx):
'freebsd-clang latest',
'x86-msvc latest'],
# Standards
'>=11')
'>=11') + [
linux_cxx("GCC 12 (no-mutex)", "g++-12", packages="g++-12", buildscript="drone", buildtype="boost",
image="cppalliance/droneubuntu2204:1",
environment={'B2_TOOLSET': 'gcc-12', 'B2_DEFINES': 'BOOST_URL_DISABLE_THREADS=1',
'B2_CXXSTD': '17'}, globalenv={'B2_CI_VERSION': '1', 'B2_VARIANT': 'release'}),
]


# from https://github.com/boostorg/boost-ci
load("@boost_ci//ci/drone/:functions.star", "linux_cxx", "windows_cxx", "osx_cxx", "freebsd_cxx")
Expand Down Expand Up @@ -418,6 +424,7 @@ def generate(compiler_ranges, cxx_range, max_cxx=2, coverage=True, docs=True, as

return jobs


# Returns whether the specified compiler/version support a given standard
# Ex: Checking if GCC 14 supports C++11
# - compiler_supports('gcc', '14', '11') -> True
Expand Down Expand Up @@ -447,6 +454,7 @@ def compiler_supports(compiler, version, cxx):
(cxx == '03' or cxx == '98')
return False


# Get list of available compiler versions in a semver range
# - compilers_in_range('gcc >=10') -> [('gcc', '12'), ('gcc', '11'), ('gcc', '10')]
def compilers_in_range(compiler_range_str):
Expand Down Expand Up @@ -480,6 +488,7 @@ def compilers_in_range(compiler_range_str):
compilers.append((name, supported_version_str))
return compilers


# Get the C++ standard versions in a range of versions
# Each C++ standard version can be represented by the two or
# four char year version.
Expand Down Expand Up @@ -507,6 +516,7 @@ def cxxs_in_range(ranges):
cxxs.append(str(v)[-2:])
return cxxs


# Check if a semver range contains a version
# Each parameter can be a string or a version or range that has already been parsed.
# - version_match('1.2.4', '>1.2.3') -> True
Expand Down Expand Up @@ -560,6 +570,7 @@ def version_match(v, ranges):
break
return any_in_disjunction


# Parse a semver range
# A semver range contains one or more semver comparators.
# Each comparator can have one of the following operators:
Expand Down Expand Up @@ -623,6 +634,7 @@ def parse_semver_range(range_strs):
ranges[-1].append(['<', major + 1, 0, 0])
return ranges


# Parse a semver string
# Ex:
# - parse_semver('1.2.3') -> [1, 2, 3]
Expand Down
53 changes: 29 additions & 24 deletions include/boost/url/grammar/detail/impl/recycled.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#define BOOST_URL_GRAMMAR_DETAIL_IMPL_RECYCLED_IPP

#include <cstdlib>
#include <mutex>
#include <utility>
#include <atomic>

#ifdef BOOST_URL_REPORT
# ifdef _MSC_VER
# include <intrin.h>
Expand All @@ -26,22 +27,20 @@ namespace detail {

struct all_reports
{
std::mutex m;

// current count
std::size_t count = 0;
std::atomic<std::size_t> count = {0};

// current bytes
std::size_t bytes = 0;
std::atomic<std::size_t> bytes = {0};

// highest total ptr count
std::size_t count_max = 0;
std::atomic<std::size_t> count_max = {0};

// highest total bytes
std::size_t bytes_max = 0;
std::atomic<std::size_t> bytes_max = {0};

// largest single allocation
std::size_t alloc_max = 0;
std::atomic<std::size_t> alloc_max = {0};

~all_reports()
{
Expand All @@ -61,30 +60,36 @@ void
recycled_add_impl(
std::size_t n) noexcept
{
std::lock_guard<
std::mutex> m(all_reports_.m);

auto& a = all_reports_;

a.count++;
if( a.count_max < a.count)
a.count_max = a.count;

a.bytes += n;
if( a.bytes_max < a.bytes)
a.bytes_max = a.bytes;

if( a.alloc_max < n)
a.alloc_max = n;
std::size_t new_count = ++a.count;
std::size_t old_count_max = a.count_max;
while (
old_count_max < new_count &&
!a.count_max.compare_exchange_weak(
old_count_max, new_count))
{}

std::size_t new_bytes = a.bytes.fetch_add(n);
std::size_t old_bytes_max = a.bytes_max;
while (
old_bytes_max < new_bytes &&
!a.bytes_max.compare_exchange_weak(
old_bytes_max, new_bytes))
{}

std::size_t old_alloc_max = a.alloc_max;
while (
old_alloc_max < n &&
!a.alloc_max.compare_exchange_weak(
old_alloc_max, n))
{}
}

void
recycled_remove_impl(
std::size_t n) noexcept
{
std::lock_guard<
std::mutex> m(all_reports_.m);

all_reports_.count--;
all_reports_.bytes-=n;
}
Expand Down
1 change: 0 additions & 1 deletion include/boost/url/grammar/detail/recycled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef BOOST_URL_GRAMMAR_DETAIL_RECYCLED_HPP
#define BOOST_URL_GRAMMAR_DETAIL_RECYCLED_HPP

#include <mutex>
#include <utility>

namespace boost {
Expand Down
14 changes: 10 additions & 4 deletions include/boost/url/grammar/impl/recycled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ acquire() ->
{
U* p;
{
#if !defined(BOOST_URL_DISABLE_THREADS)
std::lock_guard<
std::mutex> lock(m_);
#endif
p = head_;
if(p)
{
Expand All @@ -75,10 +77,14 @@ release(U* u) noexcept
{
if(--u->refs != 0)
return;
m_.lock();
u->next = head_;
head_ = u;
m_.unlock();
{
#if !defined(BOOST_URL_DISABLE_THREADS)
std::lock_guard<
std::mutex> lock(m_);
#endif
u->next = head_;
head_ = u;
}
detail::recycled_add(
sizeof(U));
}
Expand Down
13 changes: 13 additions & 0 deletions include/boost/url/grammar/recycled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <type_traits>
#include <stddef.h> // ::max_align_t

#if !defined(BOOST_URL_DISABLE_THREADS)
# include <mutex>
#endif

namespace boost {
namespace urls {
namespace grammar {
Expand Down Expand Up @@ -90,8 +94,14 @@ class recycled
{
T t;
U* next = nullptr;

#if !defined(BOOST_URL_DISABLE_THREADS)
std::atomic<
std::size_t> refs;
#else
std::size_t refs;
#endif


U()
: refs{1}
Expand All @@ -105,7 +115,10 @@ class recycled
void release(U* u) noexcept;

U* head_ = nullptr;

#if !defined(BOOST_URL_DISABLE_THREADS)
std::mutex m_;
#endif
};

//------------------------------------------------
Expand Down

0 comments on commit 58ed304

Please sign in to comment.