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

STEllAR-GROUP / hpx / #867

15 Jan 2023 08:00PM UTC coverage: 86.487% (+0.5%) from 85.951%
#867

push

StellarBot
Merge #6135

6135: Fixing warnings reported by MSVC analysis r=hkaiser a=hkaiser

- adding MSVC specific #pragma's to suppress the benign warnings


Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

120 of 120 new or added lines in 33 files covered. (100.0%)

174599 of 201880 relevant lines covered (86.49%)

1945607.64 hits per line

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

81.82
/libs/full/components/include/hpx/components/get_ptr.hpp
1
//  Copyright (c) 2007-2021 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
/// \file hpx/components/get_ptr.hpp
8

9
#pragma once
10

11
#include <hpx/config.hpp>
12
#include <hpx/assert.hpp>
13
#include <hpx/async_base/launch_policy.hpp>
14
#include <hpx/components/client_base.hpp>
15
#include <hpx/components_base/agas_interface.hpp>
16
#include <hpx/components_base/component_type.hpp>
17
#include <hpx/components_base/get_lva.hpp>
18
#include <hpx/components_base/traits/component_pin_support.hpp>
19
#include <hpx/components_base/traits/component_type_is_compatible.hpp>
20
#include <hpx/functional/bind_back.hpp>
21
#include <hpx/modules/errors.hpp>
22
#include <hpx/naming_base/address.hpp>
23
#include <hpx/naming_base/id_type.hpp>
24

25
#include <memory>
26

27
///////////////////////////////////////////////////////////////////////////////
28
namespace hpx {
29

30
    /// \cond NOINTERNAL
31
    namespace detail {
32

33
        ///////////////////////////////////////////////////////////////////////
34
        struct get_ptr_deleter
486,271✔
35
        {
36
            explicit get_ptr_deleter(hpx::id_type const& id) noexcept
37,555✔
37
              : id_(id)
37,555✔
38
            {
39
            }
37,555✔
40

41
            template <typename Component>
42
            void operator()(Component* p)
35,550✔
43
            {
44
                id_ = hpx::invalid_id;    // release component
35,549✔
45
                traits::component_pin_support<Component>::unpin(p);
35,549✔
46
            }
35,549✔
47

48
            hpx::id_type id_;    // holds component alive
49
        };
50

51
        struct get_ptr_no_unpin_deleter
26✔
52
        {
53
            explicit get_ptr_no_unpin_deleter(hpx::id_type const& id) noexcept
2✔
54
              : id_(id)
2✔
55
            {
56
            }
2✔
57

58
            template <typename Component>
59
            void operator()(Component*)
2✔
60
            {
61
                id_ = hpx::invalid_id;    // release component
2✔
62
            }
2✔
63

64
            hpx::id_type id_;    // holds component alive
65
        };
66

67
        struct get_ptr_for_migration_deleter
26,338✔
68
        {
69
            explicit get_ptr_for_migration_deleter(
2,026✔
70
                hpx::id_type const& id) noexcept
71
              : id_(id)
2,026✔
72
            {
73
            }
2,026✔
74

75
            template <typename Component>
76
            void operator()(Component* p)
2,026✔
77
            {
78
                bool was_migrated =
2,026✔
79
                    traits::component_pin_support<Component>::unpin(p);
2,026✔
80

81
                if (was_migrated)
2,026✔
82
                {
83
                    components::component_type type =
×
84
                        components::get_component_type<Component>();
×
85
                    components::deleter(type)(id_.get_gid(),
×
86
                        naming::address(naming::get_gid_from_locality_id(
×
87
                                            agas::get_locality_id()),
×
88
                            type, p));
×
89
                }
×
90
                id_ = hpx::invalid_id;    // release credits
2,026✔
91
            }
2,026✔
92

93
            hpx::id_type id_;    // holds component alive
94
        };
95

96
        template <typename Component, typename Deleter>
97
        std::shared_ptr<Component> get_ptr_postproc(
41,061✔
98
            naming::address const& addr, hpx::id_type const& id)
99
        {
100
            if (agas::get_locality_id() !=
82,122✔
101
                naming::get_locality_id_from_gid(addr.locality_))
41,057✔
102
            {
103
                HPX_THROW_EXCEPTION(hpx::error::bad_parameter,
1,476✔
104
                    "hpx::get_ptr_postproc<Component, Deleter>",
105
                    "the given component id does not belong to a local object");
106
                return std::shared_ptr<Component>();
107
            }
108

109
            if (!traits::component_type_is_compatible<Component>::call(addr))
39,581✔
110
            {
111
                HPX_THROW_EXCEPTION(hpx::error::bad_component_type,
×
112
                    "hpx::get_ptr_postproc<Component, Deleter>",
113
                    "requested component type does not match the given "
114
                    "component id");
115
                return std::shared_ptr<Component>();
116
            }
117

118
            Component* p = get_lva<Component>::call(addr.address_);
39,584✔
119
            std::shared_ptr<Component> ptr(p, Deleter(id));
39,581✔
120

121
            // the shared_ptr pins the component
122
            traits::component_pin_support<Component>::pin(ptr.get());
39,584✔
123
            return ptr;
39,584✔
124
        }
41,060✔
125

126
        ///////////////////////////////////////////////////////////////////////
127
        // This is similar to get_ptr<> below, except that the shared_ptr will
128
        // delete the local instance when it goes out of scope.
129
        template <typename Component>
130
        std::shared_ptr<Component> get_ptr_for_migration(
2,026✔
131
            naming::address const& addr, hpx::id_type const& id)
132
        {
133
            return get_ptr_postproc<Component, get_ptr_for_migration_deleter>(
2,026✔
134
                addr, id);
2,026✔
135
        }
136
    }    // namespace detail
137
    /// \endcond
138

139
    /// \brief Returns a future referring to the pointer to the
140
    ///  underlying memory of a component
141
    ///
142
    /// The function hpx::get_ptr can be used to extract a future
143
    /// referring to the pointer to the underlying memory of a given component.
144
    ///
145
    /// \param id  [in] The global id of the component for which the pointer
146
    ///            to the underlying memory should be retrieved.
147
    ///
148
    /// \tparam    The only template parameter has to be the type of the
149
    ///            server side component.
150
    ///
151
    /// \returns   This function returns a future representing the pointer to
152
    ///            the underlying memory for the component instance with the
153
    ///            given \a id.
154
    ///
155
    /// \note      This function will successfully return the requested result
156
    ///            only if the given component is currently located on the
157
    ///            calling locality. Otherwise the function will raise an
158
    ///            error.
159
    ///
160
    /// \note      The component instance the returned pointer refers to can
161
    ///            not be migrated as long as there is at least one copy of the
162
    ///            returned shared_ptr alive.
163
    ///
164
    template <typename Component>
165
    hpx::future<std::shared_ptr<Component>> get_ptr(hpx::id_type const& id)
39,035✔
166
    {
167
        hpx::future<naming::address> f = agas::resolve(id);
39,034✔
168
        return f.then(hpx::launch::sync,
39,035✔
169
            [=](hpx::future<naming::address> f) -> std::shared_ptr<Component> {
195,161✔
170
                return detail::get_ptr_postproc<Component,
39,035✔
171
                    detail::get_ptr_deleter>(f.get(), id);
39,035✔
172
            });
173
    }
39,034✔
174

175
    /// \brief Returns a future referring to the pointer to the
176
    ///  underlying memory of a component
177
    ///
178
    /// The function hpx::get_ptr can be used to extract a future
179
    /// referring to the pointer to the underlying memory of a given component.
180
    ///
181
    /// \param c   [in] A client side representation of the component for which
182
    ///            the pointer to the underlying memory should be retrieved.
183
    ///
184
    /// \returns   This function returns a future representing the pointer to
185
    ///            the underlying memory for the component instance with the
186
    ///            given \a id.
187
    ///
188
    /// \note      This function will successfully return the requested result
189
    ///            only if the given component is currently located on the
190
    ///            calling locality. Otherwise the function will raise an
191
    ///            error.
192
    ///
193
    /// \note      The component instance the returned pointer refers to can
194
    ///            not be migrated as long as there is at least one copy of the
195
    ///            returned shared_ptr alive.
196
    ///
197
    template <typename Derived, typename Stub>
198
    hpx::future<std::shared_ptr<
199
        typename components::client_base<Derived, Stub>::server_component_type>>
200
    get_ptr(components::client_base<Derived, Stub> const& c)
×
201
    {
202
        typedef typename components::client_base<Derived,
203
            Stub>::server_component_type component_type;
204

205
        return get_ptr<component_type>(c.get_id());
×
206
    }
207

208
    /// \brief Returns the pointer to the underlying memory of a component
209
    ///
210
    /// The function hpx::get_ptr_sync can be used to extract the pointer to
211
    /// the underlying memory of a given component.
212
    ///
213
    /// \param p   [in] The parameter \a p represents a placeholder type to
214
    ///            turn make the call synchronous.
215
    /// \param id  [in] The global id of the component for which the pointer
216
    ///            to the underlying memory should be retrieved.
217
    /// \param ec  [in,out] this represents the error status on exit, if this
218
    ///            is pre-initialized to \a hpx#throws the function will throw
219
    ///            on error instead.
220
    ///
221
    /// \tparam    The only template parameter has to be the type of the
222
    ///            server side component.
223
    ///
224
    /// \returns   This function returns the pointer to the underlying memory
225
    ///            for the component instance with the given \a id.
226
    ///
227
    /// \note      This function will successfully return the requested result
228
    ///            only if the given component is currently located on the
229
    ///            requesting locality. Otherwise the function will raise and
230
    ///            error.
231
    ///
232
    /// \note      The component instance the returned pointer refers to can
233
    ///            not be migrated as long as there is at least one copy of the
234
    ///            returned shared_ptr alive.
235
    ///
236
    /// \note      As long as \a ec is not pre-initialized to \a hpx::throws this
237
    ///            function doesn't throw but returns the result code using the
238
    ///            parameter \a ec. Otherwise it throws an instance of
239
    ///            hpx::exception.
240
    ///
241
#if defined(DOXYGEN)
242
    template <typename Component>
243
    std::shared_ptr<Component> get_ptr(
244
        launch::sync_policy p, hpx::id_type const& id, error_code& ec = throws);
245
#else
246
    template <typename Component>
247
    std::shared_ptr<Component> get_ptr(
2✔
248
        launch::sync_policy, hpx::id_type const& id, error_code& ec = throws)
249
    {
250
        // shortcut for local, non-migratable objects
251
        naming::gid_type gid = id.get_gid();
2✔
252
        if (naming::refers_to_local_lva(gid) &&
2✔
253
            naming::get_locality_id_from_gid(gid) == agas::get_locality_id(ec))
2✔
254
        {
255
            return std::shared_ptr<Component>(
2✔
256
                get_lva<Component>::call(
2✔
257
                    reinterpret_cast<hpx::naming::address_type>(gid.get_lsb())),
2✔
258
                detail::get_ptr_no_unpin_deleter(id));
2✔
259
        }
260

261
        hpx::future<std::shared_ptr<Component>> ptr = get_ptr<Component>(id);
×
262
        return ptr.get(ec);
×
263
    }
2✔
264
#endif
265

266
    /// \brief Returns the pointer to the underlying memory of a component
267
    ///
268
    /// The function hpx::get_ptr_sync can be used to extract the pointer to
269
    /// the underlying memory of a given component.
270
    ///
271
    /// \param p   [in] The parameter \a p represents a placeholder type to
272
    ///            turn make the call synchronous.
273
    /// \param c   [in] A client side representation of the component for which
274
    ///            the pointer to the underlying memory should be retrieved.
275
    /// \param ec  [in,out] this represents the error status on exit, if this
276
    ///            is pre-initialized to \a hpx#throws the function will throw
277
    ///            on error instead.
278
    ///
279
    /// \returns   This function returns the pointer to the underlying memory
280
    ///            for the component instance with the given \a id.
281
    ///
282
    /// \note      This function will successfully return the requested result
283
    ///            only if the given component is currently located on the
284
    ///            requesting locality. Otherwise the function will raise and
285
    ///            error.
286
    ///
287
    /// \note      The component instance the returned pointer refers to can
288
    ///            not be migrated as long as there is at least one copy of the
289
    ///            returned shared_ptr alive.
290
    ///
291
    /// \note      As long as \a ec is not pre-initialized to \a hpx::throws this
292
    ///            function doesn't throw but returns the result code using the
293
    ///            parameter \a ec. Otherwise it throws an instance of
294
    ///            hpx::exception.
295
    ///
296
    template <typename Derived, typename Stub>
297
    std::shared_ptr<
298
        typename components::client_base<Derived, Stub>::server_component_type>
299
    get_ptr(launch::sync_policy p,
300
        components::client_base<Derived, Stub> const& c,
301
        error_code& ec = throws)
302
    {
303
        using component_type = typename components::client_base<Derived,
304
            Stub>::server_component_type;
305

306
        return get_ptr<component_type>(p, c.get_id(), ec);
307
    }
308
}    // namespace hpx
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