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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

28.57
/libs/core/threading_base/src/thread_description.cpp
1
//  Copyright (c) 2016-2025 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
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
#include <hpx/config.hpp>
8
#include <hpx/assert.hpp>
9
#include <hpx/modules/errors.hpp>
10
#include <hpx/modules/format.hpp>
11
#include <hpx/threading_base/thread_data.hpp>
12
#include <hpx/threading_base/thread_description.hpp>
13

14
#include <ostream>
15
#include <string>
16

17
namespace hpx::threads {
18

19
    std::ostream& operator<<(
×
20
        std::ostream& os, [[maybe_unused]] thread_description const& d)
21
    {
22
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
23
        if (d.kind() == thread_description::data_type::description)
24
        {
25
            os << d.get_description();
26
        }
27
        else
28
        {
29
            HPX_ASSERT(d.kind() == thread_description::data_type::address);
30
            os << d.get_address();    //-V128
31
        }
32
#else
33
        os << "<unknown>";
×
34
#endif
35
        return os;
×
36
    }
37

38
    std::string as_string([[maybe_unused]] thread_description const& desc)
5✔
39
    {
40
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
41
        if (desc.kind() == threads::thread_description::data_type::description)
42
            return desc ? desc.get_description() : "<unknown>";
43

44
        return hpx::util::format("address: {:#x}", desc.get_address());
45
#else
46
        return "<unknown>";
5✔
47
#endif
48
    }
49

50
    /* The priority of description is altname, id::name, id::address */
51
    void thread_description::init_from_alternative_name(
×
52
        [[maybe_unused]] char const* altname)
53
    {
54
#if defined(HPX_HAVE_THREAD_DESCRIPTION) &&                                    \
55
    !defined(HPX_HAVE_THREAD_DESCRIPTION_FULL)
56
        if (altname != nullptr)
57
        {
58
            data_.type_ = data_type::description;
59
            data_.desc_ = altname;
60
            return;
61
        }
62

63
        if (hpx::threads::thread_id_type const id = hpx::threads::get_self_id())
64
        {
65
            // get the current task description
66
            thread_description const desc =
67
                hpx::threads::get_thread_description(id);
68
            data_.type_ = desc.kind();
69

70
            // if the current task has a description, use it.
71
            if (data_.type_ == data_type::description)
72
            {
73
                data_.desc_ = desc.get_description();
74
            }
75
            else
76
            {
77
                // otherwise, use the address of the task.
78
                HPX_ASSERT(data_.type_ == data_type::address);
79
                data_.addr_ = desc.get_address();
80
            }
81
        }
82
        else
83
        {
84
            data_.type_ = data_type::description;
85
            data_.desc_ = "<unknown>";
86
        }
87
#endif
88
    }
×
89

90
    threads::thread_description get_thread_description(
5✔
91
        thread_id_type const& id, error_code& /* ec */)
92
    {
93
        return id ? get_thread_id_data(id)->get_description() :
94
                    threads::thread_description("<unknown>");
5✔
95
    }
96

97
    threads::thread_description set_thread_description(thread_id_type const& id,
93✔
98
        threads::thread_description const& desc, error_code& ec)
99
    {
100
        if (HPX_UNLIKELY(!id))
93✔
101
        {
102
            HPX_THROWS_IF(ec, hpx::error::null_thread_id,
×
103
                "hpx::threads::set_thread_description",
104
                "null thread id encountered");
105
            return {};
×
106
        }
107
        if (&ec != &throws)
93✔
108
            ec = make_success_code();
×
109

110
        return get_thread_id_data(id)->set_description(desc);
93✔
111
    }
112

113
    ///////////////////////////////////////////////////////////////////////////
114
    threads::thread_description get_thread_lco_description(
×
115
        thread_id_type const& id, error_code& ec)
116
    {
117
        if (HPX_UNLIKELY(!id))
×
118
        {
119
            HPX_THROWS_IF(ec, hpx::error::null_thread_id,
×
120
                "hpx::threads::get_thread_lco_description",
121
                "null thread id encountered");
122
            return nullptr;
123
        }
124

125
        if (&ec != &throws)
×
126
            ec = make_success_code();
×
127

128
        return get_thread_id_data(id)->get_lco_description();
×
129
    }
130

131
    threads::thread_description set_thread_lco_description(
×
132
        thread_id_type const& id, threads::thread_description const& desc,
133
        error_code& ec)
134
    {
135
        if (HPX_UNLIKELY(!id))
×
136
        {
137
            HPX_THROWS_IF(ec, hpx::error::null_thread_id,
×
138
                "hpx::threads::set_thread_lco_description",
139
                "null thread id encountered");
140
            return nullptr;
141
        }
142

143
        if (&ec != &throws)
×
144
            ec = make_success_code();
×
145

146
        return get_thread_id_data(id)->set_lco_description(desc);
×
147
    }
148
}    // namespace hpx::threads
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