• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #862

10 Jan 2023 05:30PM UTC coverage: 86.582% (-0.05%) from 86.634%
#862

push

StellarBot
Merge #6130

6130: Remove the mutex lock in the critical path of get_partitioner. r=hkaiser a=JiakunYan

Remove the mutex lock in the critical path of hpx::resource::detail::get_partitioner.

The protected variable `partitioner_ref` is only set once during initialization.

Co-authored-by: Jiakun Yan <jiakunyan1998@gmail.com>

6 of 6 new or added lines in 1 file covered. (100.0%)

174767 of 201851 relevant lines covered (86.58%)

2069816.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.18
/libs/core/program_options/src/config_file.cpp
1
// Copyright Vladimir Prus 2002-2004.
2
//  SPDX-License-Identifier: BSL-1.0
3
// Distributed under the Boost Software License, Version 1.0.
4
// (See accompanying file LICENSE_1_0.txt
5
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/program_options/config.hpp>
8
#include <hpx/assert.hpp>
9
#include <hpx/program_options/detail/config_file.hpp>
10
#include <hpx/program_options/detail/convert.hpp>
11
#include <hpx/program_options/errors.hpp>
12

13
#include <fstream>
14
#include <set>
15
#include <string>
16

17
namespace hpx::program_options::detail {
18

19
    common_config_file_iterator::common_config_file_iterator(
7✔
20
        std::set<std::string> const& allowed_options, bool allow_unregistered)
21
      : allowed_options(allowed_options)
7✔
22
      , m_allow_unregistered(allow_unregistered)
7✔
23
    {
14✔
24
        for (auto const& allowed_option : allowed_options)
57✔
25
        {
26
            add_option(allowed_option.c_str());
50✔
27
        }
28
    }
7✔
29

30
    void common_config_file_iterator::add_option(char const* name)
50✔
31
    {
32
        std::string s(name);
50✔
33
        HPX_ASSERT(!s.empty());
50✔
34
        if (*s.rbegin() == '*')
50✔
35
        {
36
            s.resize(s.size() - 1);
2✔
37
            bool bad_prefixes(false);
2✔
38
            // If 's' is a prefix of one of allowed suffix, then
39
            // lower_bound will return that element.
40
            // If some element is prefix of 's', then lower_bound will
41
            // return the next element.
42
            std::set<std::string>::iterator i = allowed_prefixes.lower_bound(s);
2✔
43
            if (i != allowed_prefixes.end())
2✔
44
            {
45
                if (i->find(s) == 0)
×
46
                    bad_prefixes = true;
×
47
            }
×
48
            if (i != allowed_prefixes.begin())
2✔
49
            {
50
                --i;
×
51
                if (s.find(*i) == 0)
×
52
                    bad_prefixes = true;
×
53
            }
×
54
            if (bad_prefixes)
2✔
55
                throw error("options '" + std::string(name) + "' and '" + *i +
×
56
                    "*' will both match the same arguments from the "
57
                    "configuration file");
58
            allowed_prefixes.insert(s);
2✔
59
        }
2✔
60
    }
50✔
61

62
    namespace {
63

64
        inline std::string trim_ws(std::string const& s)
163✔
65
        {
66
            std::string::size_type n, n2;
67
            n = s.find_first_not_of(" \t\r\n");
163✔
68
            if (n == std::string::npos)
163✔
69
                return std::string();
12✔
70
            else
71
            {
72
                n2 = s.find_last_not_of(" \t\r\n");
151✔
73
                return s.substr(n, n2 - n + 1);
151✔
74
            }
75
        }
163✔
76
    }    // namespace
77

78
    void common_config_file_iterator::get()
56✔
79
    {
80
        std::string s;
56✔
81
        std::string::size_type n;
82
        bool found = false;
56✔
83

84
        while (this->getline(s))
72✔
85
        {
86
            // strip '#' comments and whitespace
87
            if ((n = s.find('#')) != std::string::npos)
65✔
88
                s = s.substr(0, n);
3✔
89
            s = trim_ws(s);
65✔
90

91
            if (!s.empty())
65✔
92
            {
93
                // Handle section name
94
                if (*s.begin() == '[' && *s.rbegin() == ']')
56✔
95
                {
96
                    m_prefix = s.substr(1, s.size() - 2);
7✔
97
                    if (*m_prefix.rbegin() != '.')
7✔
98
                        m_prefix += '.';
7✔
99
                }
7✔
100
                else if ((n = s.find('=')) != std::string::npos)
49✔
101
                {
102
                    std::string name = m_prefix + trim_ws(s.substr(0, n));
49✔
103
                    std::string value = trim_ws(s.substr(n + 1));
49✔
104

105
                    bool registered = allowed_option(name);
49✔
106
                    if (!registered && !m_allow_unregistered)
49✔
107
                        throw unknown_option(name);
×
108

109
                    found = true;
49✔
110

111
                    auto& v = this->value();
49✔
112
                    v.string_key = name;
49✔
113
                    v.value.clear();
49✔
114
                    v.value.push_back(value);
49✔
115
                    v.unregistered = !registered;
49✔
116
                    v.original_tokens.clear();
49✔
117
                    v.original_tokens.push_back(HPX_MOVE(name));
49✔
118
                    v.original_tokens.push_back(HPX_MOVE(value));
49✔
119
                    break;
120
                }
49✔
121
                else
122
                {
123
                    throw invalid_config_file_syntax(
×
124
                        s, invalid_syntax::unrecognized_line);
125
                }
126
            }
7✔
127
        }
128
        if (!found)
56✔
129
            found_eof();
7✔
130
    }
56✔
131

132
    bool common_config_file_iterator::allowed_option(std::string const& s) const
49✔
133
    {
134
        std::set<std::string>::const_iterator i = allowed_options.find(s);
49✔
135
        if (i != allowed_options.end())
49✔
136
            return true;
41✔
137
        // If s is "pa" where "p" is allowed prefix then
138
        // lower_bound should find the element after "p".
139
        // This depends on 'allowed_prefixes' invariant.
140
        i = allowed_prefixes.lower_bound(s);
8✔
141
        if (i != allowed_prefixes.begin() && s.find(*--i) == 0)
8✔
142
            return true;
2✔
143
        return false;
6✔
144
    }
49✔
145

146
#if defined(__COMO_VERSION__) && __COMO_VERSION__ >= 4303 ||                   \
147
    (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION >= 741)
148
    template <>
149
    bool basic_config_file_iterator<wchar_t>::getline(std::string& s)
150
    {
151
        std::wstring ws;
152
        // On Comeau, using two-argument version causes
153
        // call to some internal function with std::wstring, and '\n'
154
        // (not L'\n') and compile can't resolve that call.
155

156
        if (std::getline(*is, ws, L'\n'))
157
        {
158
            s = to_utf8(ws);
159
            return true;
160
        }
161
        else
162
        {
163
            return false;
164
        }
165
    }
166
#endif
167
}    // namespace hpx::program_options::detail
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc