• 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

48.15
/libs/full/components_base/src/server/component_base.cpp
1
//  Copyright (c) 2015 Thomas Heller
2
//  Copyright (c) 2018-2023 Hartmut Kaiser
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#include <hpx/assert.hpp>
10
#include <hpx/components_base/agas_interface.hpp>
11
#include <hpx/components_base/component_type.hpp>
12
#include <hpx/components_base/server/component_base.hpp>
13
#include <hpx/modules/async_base.hpp>
14
#include <hpx/modules/errors.hpp>
15
#include <hpx/naming_base/address.hpp>
16
#include <hpx/naming_base/id_type.hpp>
17

18
#include <cstdint>
19
#include <mutex>
20

21
namespace hpx::components::detail {
22

23
    base_component::~base_component()
1,055✔
24
    {
25
        if (gid_)
26
        {
27
            error_code ec;
28
            agas::unbind(launch::sync, gid_, 1, ec);
1,055✔
29
        }
30
    }
1,055✔
31

32
    naming::gid_type base_component::get_base_gid_dynamic(
×
33
        naming::gid_type const& assign_gid, naming::address const& addr,
34
        naming::gid_type (*f)(naming::gid_type)) const
35
    {
36
        if (!gid_)
37
        {
38
            if (!assign_gid)
39
            {
40
                if (f != nullptr)
×
41
                {
42
                    gid_ = f(hpx::detail::get_next_id());
×
43
                }
44
                else
45
                {
46
                    gid_ = hpx::detail::get_next_id();
×
47
                }
48

49
                if (!agas::bind_gid_local(gid_, addr))
×
50
                {
51
                    naming::gid_type const g = gid_;
52
                    gid_ = naming::invalid_gid;    // invalidate GID
53

54
                    HPX_THROW_EXCEPTION(hpx::error::duplicate_component_address,
×
55
                        "component_base<Component>::get_base_gid",
56
                        "failed to bind id: {} to locality: {}", g,
57
                        agas::get_locality_id());
58
                }
59
            }
60
            else
61
            {
62
                gid_ = assign_gid;
×
63
                naming::detail::strip_credits_from_gid(gid_);
64

65
                if (!agas::bind(
×
66
                        launch::sync, gid_, addr, agas::get_locality_id()))
67
                {
68
                    naming::gid_type const g = gid_;
69
                    gid_ = naming::invalid_gid;    // invalidate GID
70

71
                    HPX_THROW_EXCEPTION(hpx::error::duplicate_component_address,
×
72
                        "component_base<Component>::get_base_gid",
73
                        "failed to rebind id: {} to locality: {}", g,
74
                        agas::get_locality_id());
75
                }
76
            }
77
        }
78

79
        std::unique_lock l(gid_.get_mutex());
×
80

81
        naming::gid_type gid = gid_;
82
        if (!naming::detail::has_credits(gid_))
×
83
        {
84
            return gid;
85
        }
86

87
        // on first invocation take all credits to avoid a self reference
88
        naming::detail::strip_credits_from_gid(
89
            const_cast<naming::gid_type&>(gid_));
90

91
        HPX_ASSERT(naming::detail::has_credits(gid));
92

93
        // We have to assume this credit was split as otherwise the gid returned
94
        // at this point will control the lifetime of the component.
95
        naming::detail::set_credit_split_mask_for_gid(gid);
96
        return gid;
97
    }
98

99
    naming::gid_type base_component::get_base_gid(naming::address const& addr,
1,087✔
100
        naming::gid_type (*f)(naming::gid_type)) const
101
    {
102
        if (!gid_)
103
        {
104
            // generate purely local gid
105
            if (f != nullptr)
1,055✔
106
            {
107
                gid_ = f(naming::gid_type(addr.address_));
×
108
            }
109
            else
110
            {
111
                gid_ = naming::gid_type(addr.address_);
1,055✔
112
            }
113

114
            naming::detail::set_credit_for_gid(
115
                gid_, static_cast<std::int64_t>(HPX_GLOBALCREDIT_INITIAL));
116
            gid_ = naming::replace_component_type(gid_, addr.type_);
1,055✔
117
            gid_ = naming::replace_locality_id(gid_, agas::get_locality_id());
1,055✔
118

119
            // there is no need to explicitly bind this id in AGAS as the id
120
            // can be directly resolved to the address it contains.
121
        }
122

123
        std::unique_lock l(gid_.get_mutex());
1,087✔
124

125
        naming::gid_type gid = gid_;
126
        if (!naming::detail::has_credits(gid_))
1,087✔
127
        {
128
            return gid;
129
        }
130

131
        // on first invocation take all credits to avoid a self reference
132
        naming::detail::strip_credits_from_gid(gid_);
133

134
        HPX_ASSERT(naming::detail::has_credits(gid));
135

136
        // We have to assume this credit was split as otherwise the gid
137
        // returned at this point will control the lifetime of the
138
        // component.
139
        naming::detail::set_credit_split_mask_for_gid(gid);
140
        return gid;
141
    }
142

143
    hpx::id_type base_component::get_id(naming::gid_type gid)
32✔
144
    {
145
        // all credits should have been taken already
146
        HPX_ASSERT(!naming::detail::has_credits(gid));
147

148
        // any (subsequent) invocation causes the credits to be replenished
149
        agas::replenish_credits(gid);
32✔
150
        return {gid, hpx::id_type::management_type::managed};
32✔
151
    }
152

153
    hpx::id_type base_component::get_unmanaged_id(naming::gid_type const& gid)
×
154
    {
155
        return {gid, hpx::id_type::management_type::managed};
×
156
    }
157
}    // namespace hpx::components::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