• 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

70.0
/libs/full/naming_base/src/id_type.cpp
1
//  Copyright (c) 2007-2023 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/memory.hpp>
10
#include <hpx/naming_base/id_type.hpp>
11

12
#include <atomic>
13
#include <ostream>
14
#include <vector>
15

16
///////////////////////////////////////////////////////////////////////////////
17
namespace hpx {
18

19
    ///////////////////////////////////////////////////////////////////////////
20
    namespace naming::detail {
21

22
        void (*gid_managed_deleter)(id_type_impl const* p) noexcept = nullptr;
23
        void (*gid_unmanaged_deleter)(id_type_impl const* p) noexcept = nullptr;
24

25
        util::internal_allocator<id_type_impl> id_type_impl::alloc_;
26

46,141✔
27
        id_type_impl::deleter_type id_type_impl::get_deleter(
28
            hpx::id_type::management_type t) noexcept
29
        {
46,141✔
30
            switch (t)
31
            {
45,000✔
32
            case hpx::id_type::management_type::unmanaged:
45,000✔
33
                return gid_unmanaged_deleter;
34

1,141✔
35
            case hpx::id_type::management_type::managed:
36
                [[fallthrough]];
37
            case hpx::id_type::management_type::managed_move_credit:
1,141✔
38
                return gid_managed_deleter;
39

40
            default:
41
                HPX_ASSERT(false);    // invalid management type
42
                break;
43
            }
×
44
            return gid_unmanaged_deleter;
45
        }
46

47
        // support functions for hpx::intrusive_ptr
124,323✔
48
        void intrusive_ptr_add_ref(id_type_impl* p) noexcept
49
        {
50
            p->count_.increment();
124,323✔
51
        }
52

170,269✔
53
        void intrusive_ptr_release(id_type_impl* p) noexcept
54
        {
170,269✔
55
            if (0 == p->count_.decrement())
56
            {
46,141✔
57
                // The thread that decrements the reference count to zero must
58
                // perform an acquire to ensure that it doesn't start
170,269✔
59
                // destructing the object until all previous writes have
60
                // drained.
61
                std::atomic_thread_fence(std::memory_order_acquire);
62

×
63
                id_type_impl::get_deleter(p->get_management_type())(p);
64
            }
×
65
        }
×
66
    }    // namespace naming::detail
67

68
    ///////////////////////////////////////////////////////////////////////////
×
69
    id_type& id_type::operator++()    // pre-increment
70
    {
71
        ++(*gid_);
×
72
        return *this;
73
    }
74

75
    id_type id_type::operator++(int) const    // post-increment
438✔
76
    {
77
        return {(*gid_)++, management_type::unmanaged};
78
    }
79

×
80
    // comparison is required as well
81
    bool operator==(id_type const& lhs, id_type const& rhs) noexcept
82
    {
83
        if (!lhs)
408✔
84
        {
85
            return !rhs;
86
        }
87
        if (!rhs)
88
        {
2,010✔
89
            return !lhs;
90
        }
91
        return *lhs.gid_ == *rhs.gid_;
92
    }
93

94
    bool operator<(id_type const& lhs, id_type const& rhs) noexcept
95
    {
96
        // LHS is null, rhs is not.
97
        if (!lhs && rhs)
98
        {
99
            return true;
100
        }
2,010✔
101
        // RHS is null.
102
        if (!rhs)
103
        {
3✔
104
            return false;
105
        }
106
        return *lhs.gid_ < *rhs.gid_;
107
    }
×
108

109
    std::ostream& operator<<(std::ostream& os, id_type const& id)
110
    {
111
        if (!id)
3✔
112
        {
113
            os << "{invalid}";
3✔
114
        }
115
        else
116
        {
117
            os << id.get_gid();
118
        }
119
        return os;
120
    }
121
}    // namespace hpx
122

123
namespace hpx::naming {
124

125
    ///////////////////////////////////////////////////////////////////////////
126
    inline constexpr char const* const management_type_names[] = {
127
        "management_type::unknown_deleter",       // -1
×
128
        "management_type::unmanaged",             // 0
129
        "management_type::managed",               // 1
130
        "management_type::managed_move_credit"    // 2
×
131
    };
132

133
    char const* get_management_type_name(
134
        hpx::id_type::management_type m) noexcept
135
    {
×
136
        if (m < hpx::id_type::management_type::unknown_deleter ||
137
            m > hpx::id_type::management_type::managed_move_credit)
138
        {
139
            return "invalid";
140
        }
141
        return management_type_names[static_cast<int>(m) + 1];
142
    }
11✔
143
}    // namespace hpx::naming
144

145
///////////////////////////////////////////////////////////////////////////////
146
namespace hpx::traits {
147

148
    hpx::id_type get_remote_result<hpx::id_type, naming::gid_type>::call(
20✔
149
        naming::gid_type const& rhs)
150
    {
151
        bool const has_credits = naming::detail::has_credits(rhs);
152
        return {rhs,
153
            has_credits ? hpx::id_type::management_type::managed :
1✔
154
                          hpx::id_type::management_type::unmanaged};
155
    }
156

157
    // we need to specialize this template to allow for automatic conversion of
1✔
158
    // the vector<naming::gid_type> to a vector<hpx::id_type>
1✔
159
    std::vector<hpx::id_type> get_remote_result<std::vector<hpx::id_type>,
2✔
160
        std::vector<naming::gid_type>>::
161
        call(std::vector<naming::gid_type> const& rhs)
162
    {
1✔
163
        std::vector<hpx::id_type> result;
1✔
164
        result.reserve(rhs.size());
165
        for (naming::gid_type const& r : rhs)
166
        {
1✔
167
            bool const has_credits = naming::detail::has_credits(r);
×
168
            result.emplace_back(r,
169
                has_credits ? hpx::id_type::management_type::managed :
170
                              hpx::id_type::management_type::unmanaged);
171
        }
172
        return result;
173
    }
174
}    // namespace hpx::traits
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

© 2026 Coveralls, Inc