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

STEllAR-GROUP / hpx / #880

05 Feb 2023 12:51AM UTC coverage: 85.952% (-0.6%) from 86.575%
#880

push

StellarBot
Merge #6129

6129: Modernize module from levels 22, 23 r=hkaiser a=hkaiser

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Modules:
- core/executors
- core/async_local
- core/timed_execution

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

45 of 45 new or added lines in 13 files covered. (100.0%)

173593 of 201964 relevant lines covered (85.95%)

1868047.33 hits per line

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

81.4
/libs/full/async_distributed/include/hpx/async_distributed/async_callback.hpp
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
#pragma once
8

9
#include <hpx/config.hpp>
10
#include <hpx/actions_base/traits/extract_action.hpp>
11
#include <hpx/actions_base/traits/is_client.hpp>
12
#include <hpx/actions_base/traits/is_distribution_policy.hpp>
13
#include <hpx/actions_base/traits/is_valid_action.hpp>
14
#include <hpx/async_base/launch_policy.hpp>
15
#include <hpx/async_base/traits/is_launch_policy.hpp>
16
#include <hpx/async_distributed/async_callback_fwd.hpp>
17
#include <hpx/async_distributed/detail/async_implementations_fwd.hpp>
18
#include <hpx/components/client_base.hpp>
19
#include <hpx/functional/traits/is_action.hpp>
20
#include <hpx/futures/future.hpp>
21
#include <hpx/futures/traits/promise_local_result.hpp>
22

23
#include <type_traits>
24
#include <utility>
25

26
///////////////////////////////////////////////////////////////////////////////
27
namespace hpx::detail {
28

29
    // launch
30
    template <typename Action, typename Policy>
31
    struct async_cb_action_dispatch<Action, Policy,
32
        std::enable_if_t<traits::is_launch_policy_v<Policy>>>
33
    {
34
        // id_type
35
        template <typename Policy_, typename Callback, typename... Ts>
36
        HPX_FORCEINLINE static hpx::future<
37
            typename traits::promise_local_result<typename traits::
38
                    extract_action<Action>::remote_result_type>::type>
39
        call(Policy_&& launch_policy, hpx::id_type const& id, Callback&& cb,
34✔
40
            Ts&&... ts)
41
        {
42
            return hpx::detail::async_cb_impl<Action>(
34✔
43
                HPX_FORWARD(Policy_, launch_policy), id,
34✔
44
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
34✔
45
        }
46

47
        template <typename Policy_, typename Client, typename Stub,
48
            typename Callback, typename... Ts>
49
        HPX_FORCEINLINE static hpx::future<
50
            typename traits::promise_local_result<typename traits::
51
                    extract_action<Action>::remote_result_type>::type>
52
        call(Policy_&& launch_policy,
×
53
            components::client_base<Client, Stub> const& c, Callback&& cb,
54
            Ts&&... ts)
55
        {
56
            typedef typename components::client_base<Client,
57
                Stub>::server_component_type component_type;
58

59
            static_assert(traits::is_valid_action_v<Action, component_type>,
60
                "The action to invoke is not supported by the target");
61

62
            return hpx::detail::async_cb_impl<Action>(
×
63
                HPX_FORWARD(Policy_, launch_policy), c.get_id(),
×
64
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
×
65
        }
66

67
        // distribution policy
68
        template <typename Policy_, typename DistPolicy, typename Callback,
69
            typename... Ts>
70
        HPX_FORCEINLINE static typename std::enable_if<
71
            traits::is_distribution_policy<DistPolicy>::value,
72
            hpx::future<typename traits::promise_local_result<typename traits::
73
                    extract_action<Action>::remote_result_type>::type>>::type
74
        call(Policy_&& launch_policy, DistPolicy const& policy, Callback&& cb,
16✔
75
            Ts&&... ts)
76
        {
77
            return policy.template async_cb<Action>(
32✔
78
                HPX_FORWARD(Policy_, launch_policy), HPX_FORWARD(Callback, cb),
16✔
79
                HPX_FORWARD(Ts, ts)...);
16✔
80
        }
81
    };
82

83
    // hpx::id_type
84
    template <typename Action>
85
    struct async_cb_action_dispatch<Action, hpx::id_type>
86
    {
87
        template <typename Callback, typename... Ts>
88
        HPX_FORCEINLINE static hpx::future<
89
            typename traits::promise_local_result<typename traits::
90
                    extract_action<Action>::remote_result_type>::type>
91
        call(hpx::id_type const& id, Callback&& cb, Ts&&... ts)
18✔
92
        {
93
            return async_cb_action_dispatch<Action,
18✔
94
                hpx::detail::async_policy>::call(launch::async, id,
18✔
95
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
18✔
96
        }
97
    };
98

99
    // component::client
100
    template <typename Action, typename Client>
101
    struct async_cb_action_dispatch<Action, Client,
102
        typename std::enable_if<traits::is_client<Client>::value>::type>
103
    {
104
        template <typename Client_, typename Stub, typename Callback,
105
            typename... Ts>
106
        HPX_FORCEINLINE static hpx::future<
107
            typename traits::promise_local_result<typename traits::
108
                    extract_action<Action>::remote_result_type>::type>
109
        call(components::client_base<Client_, Stub> const& c, Callback&& cb,
×
110
            Ts&&... ts)
111
        {
112
            typedef typename components::client_base<Client_,
113
                Stub>::server_component_type component_type;
114

115
            static_assert(traits::is_valid_action_v<Action, component_type>,
116
                "The action to invoke is not supported by the target");
117

118
            return async_cb_action_dispatch<Action,
×
119
                hpx::detail::async_policy>::call(launch::async, c.get_id(),
×
120
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
×
121
        }
122
    };
123

124
    // distribution policy
125
    template <typename Action, typename Policy>
126
    struct async_cb_action_dispatch<Action, Policy,
127
        typename std::enable_if<
128
            traits::is_distribution_policy<Policy>::value>::type>
129
    {
130
        template <typename DistPolicy, typename Callback, typename... Ts>
131
        HPX_FORCEINLINE static hpx::future<
132
            typename traits::promise_local_result<typename traits::
133
                    extract_action<Action>::remote_result_type>::type>
134
        call(DistPolicy const& policy, Callback&& cb, Ts&&... ts)
8✔
135
        {
136
            return async_cb_action_dispatch<Action,
8✔
137
                hpx::detail::async_policy>::call(launch::async, policy,
8✔
138
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
8✔
139
        }
140
    };
141
}    // namespace hpx::detail
142

143
namespace hpx {
144

145
    template <typename Action, typename F, typename... Ts>
146
    HPX_FORCEINLINE auto async_cb(F&& f, Ts&&... ts)
50✔
147
        -> decltype(detail::async_cb_action_dispatch<Action,
148
            typename std::decay<F>::type>::call(HPX_FORWARD(F, f),
149
            HPX_FORWARD(Ts, ts)...))
150
    {
151
        return detail::async_cb_action_dispatch<Action,
50✔
152
            typename std::decay<F>::type>::call(HPX_FORWARD(F, f),
50✔
153
            HPX_FORWARD(Ts, ts)...);
50✔
154
    }
155
}    // namespace hpx
156

157
///////////////////////////////////////////////////////////////////////////////
158
namespace hpx::detail {
159

160
    // any action
161
    template <typename Action>
162
    struct async_cb_dispatch<Action,
163
        typename std::enable_if<traits::is_action<Action>::value>::type>
164
    {
165
        template <typename Component, typename Signature, typename Derived,
166
            typename Callback, typename... Ts>
167
        HPX_FORCEINLINE static hpx::future<
168
            typename traits::promise_local_result<typename traits::
169
                    extract_action<Derived>::remote_result_type>::type>
170
        call(hpx::actions::basic_action<Component, Signature, Derived> const&,
12✔
171
            hpx::id_type const& id, Callback&& cb, Ts&&... ts)
172
        {
173
            return async_cb<Derived>(
12✔
174
                id, HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
12✔
175
        }
176

177
        template <typename Component, typename Signature, typename Derived,
178
            typename Client, typename Stub, typename Callback, typename... Ts>
179
        HPX_FORCEINLINE static hpx::future<
180
            typename traits::promise_local_result<typename traits::
181
                    extract_action<Derived>::remote_result_type>::type>
182
        call(hpx::actions::basic_action<Component, Signature, Derived> const&,
183
            components::client_base<Client, Stub> const& c, Callback&& cb,
184
            Ts&&... ts)
185
        {
186
            typedef typename components::client_base<Client,
187
                Stub>::server_component_type component_type;
188

189
            static_assert(traits::is_valid_action_v<Action, component_type>,
190
                "The action to invoke is not supported by the target");
191

192
            return async_cb<Derived>(
193
                c.get_id(), HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
194
        }
195

196
        template <typename Component, typename Signature, typename Derived,
197
            typename DistPolicy, typename Callback, typename... Ts>
198
        HPX_FORCEINLINE static hpx::future<
199
            typename traits::promise_local_result<typename traits::
200
                    extract_action<Derived>::remote_result_type>::type>
201
        call(hpx::actions::basic_action<Component, Signature, Derived> const&,
6✔
202
            DistPolicy const& policy, Callback&& cb, Ts&&... ts)
203
        {
204
            return async_cb<Derived>(
6✔
205
                policy, HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
6✔
206
        }
207
    };
208

209
    template <typename Policy>
210
    struct async_cb_dispatch<Policy,
211
        typename std::enable_if<traits::is_launch_policy<Policy>::value>::type>
212
    {
213
        template <typename Policy_, typename Component, typename Signature,
214
            typename Derived, typename Callback, typename... Ts>
215
        HPX_FORCEINLINE static hpx::future<
216
            typename traits::promise_local_result<typename traits::
217
                    extract_action<Derived>::remote_result_type>::type>
218
        call(Policy_&& launch_policy,
10✔
219
            hpx::actions::basic_action<Component, Signature, Derived> const&,
220
            hpx::id_type const& id, Callback&& cb, Ts&&... ts)
221
        {
222
            return async_cb<Derived>(HPX_FORWARD(Policy_, launch_policy), id,
20✔
223
                HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
10✔
224
        }
225

226
        template <typename Policy_, typename Component, typename Signature,
227
            typename Derived, typename Client, typename Stub, typename Callback,
228
            typename... Ts>
229
        HPX_FORCEINLINE static hpx::future<
230
            typename traits::promise_local_result<typename traits::
231
                    extract_action<Derived>::remote_result_type>::type>
232
        call(Policy_&& launch_policy,
233
            hpx::actions::basic_action<Component, Signature, Derived> const&,
234
            components::client_base<Client, Stub> const& c, Callback&& cb,
235
            Ts&&... ts)
236
        {
237
            typedef typename components::client_base<Client,
238
                Stub>::server_component_type component_type;
239

240
            static_assert(traits::is_valid_action_v<Derived, component_type>,
241
                "The action to invoke is not supported by the target");
242

243
            return async_cb<Derived>(HPX_FORWARD(Policy_, launch_policy),
244
                c.get_id(), HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
245
        }
246

247
        template <typename Policy_, typename Component, typename Signature,
248
            typename Derived, typename DistPolicy, typename Callback,
249
            typename... Ts>
250
        HPX_FORCEINLINE static hpx::future<
251
            typename traits::promise_local_result<typename traits::
252
                    extract_action<Derived>::remote_result_type>::type>
253
        call(Policy_&& launch_policy,
6✔
254
            hpx::actions::basic_action<Component, Signature, Derived> const&,
255
            DistPolicy const& policy, Callback&& cb, Ts&&... ts)
256
        {
257
            return async_cb<Derived>(HPX_FORWARD(Policy_, launch_policy),
12✔
258
                policy, HPX_FORWARD(Callback, cb), HPX_FORWARD(Ts, ts)...);
6✔
259
        }
260
    };
261
}    // namespace hpx::detail
262

263
namespace hpx {
264

265
    // different versions of clang-format disagree
266
    // clang-format off
267
    template <typename F, typename... Ts>
268
    HPX_FORCEINLINE auto async_cb(F&& f, Ts&&... ts) -> decltype(
34✔
269
        detail::async_cb_dispatch< std::decay_t<F>>::call(
270
            HPX_FORWARD(F, f), HPX_FORWARD(Ts, ts)...))
271
    // clang-format on
272
    {
273
        return detail::async_cb_dispatch<std::decay_t<F>>::call(
34✔
274
            HPX_FORWARD(F, f), HPX_FORWARD(Ts, ts)...);
34✔
275
    }
276
}    // 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

© 2026 Coveralls, Inc