| Line | % of fetches | Source |
|---|---|---|
| 1 | // Copyright (c) 2007-2016 Hartmut Kaiser | |
| 2 | // | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 5 | ||
| 6 | /// \file hpx/runtime/trigger_lco.hpp | |
| 7 | ||
| 8 | #if !defined(HPX_RUNTIME_TRIGGER_LCO_JUN_22_2015_0618PM) | |
| 9 | #define HPX_RUNTIME_TRIGGER_LCO_JUN_22_2015_0618PM | |
| 10 | ||
| 11 | #include <hpx/config.hpp> | |
| 12 | #include <hpx/lcos_fwd.hpp> | |
| 13 | #include <hpx/runtime/actions/continuation_fwd.hpp> | |
| 14 | #include <hpx/runtime/actions/action_priority.hpp> | |
| 15 | #include <hpx/runtime/applier/detail/apply_implementations_fwd.hpp> | |
| 16 | #include <hpx/runtime/naming/address.hpp> | |
| 17 | #include <hpx/runtime/naming/name.hpp> | |
| 18 | #include <hpx/util/decay.hpp> | |
| 19 | ||
| 20 | #include <boost/exception_ptr.hpp> | |
| 21 | ||
| 22 | #include <type_traits> | |
| 23 | #include <utility> | |
| 24 | ||
| 25 | namespace hpx | |
| 26 | { | |
| 27 | /////////////////////////////////////////////////////////////////////////// | |
| 28 | /// \brief Trigger the LCO referenced by the given id | |
| 29 | /// | |
| 30 | /// \param id [in] This represents the id of the LCO which should be | |
| 31 | /// triggered. | |
| 32 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 33 | /// triggered. | |
| 34 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 35 | /// send all credits in \a id along with the generated | |
| 36 | /// message. The default value is \a true. | |
| 37 | HPX_API_EXPORT void trigger_lco_event(naming::id_type const& id, | |
| 38 | naming::address && addr, bool move_credits = true); | |
| 39 | ||
| 40 | /////////////////////////////////////////////////////////////////////////// | |
| 41 | /// \brief Trigger the LCO referenced by the given id | |
| 42 | /// | |
| 43 | /// \param id [in] This represents the id of the LCO which should be | |
| 44 | /// triggered. | |
| 45 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 46 | /// send all credits in \a id along with the generated | |
| 47 | /// message. The default value is \a true. | |
| 48 | inline void trigger_lco_event(naming::id_type const& id, | |
| 49 | bool move_credits = true) | |
| 50 | { | |
| 51 | trigger_lco_event(id, naming::address(), move_credits); | |
| 52 | } | |
| 53 | ||
| 54 | /// \brief Trigger the LCO referenced by the given id | |
| 55 | /// | |
| 56 | /// \param id [in] This represents the id of the LCO which should be | |
| 57 | /// triggered. | |
| 58 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 59 | /// triggered. | |
| 60 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 61 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 62 | /// send all credits in \a id along with the generated | |
| 63 | /// message. The default value is \a true. | |
| 64 | HPX_API_EXPORT void trigger_lco_event(naming::id_type const& id, | |
| 65 | naming::address && addr, naming::id_type const& cont, | |
| 66 | bool move_credits = true); | |
| 67 | ||
| 68 | /// \brief Trigger the LCO referenced by the given id | |
| 69 | /// | |
| 70 | /// \param id [in] This represents the id of the LCO which should be | |
| 71 | /// triggered. | |
| 72 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 73 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 74 | /// send all credits in \a id along with the generated | |
| 75 | /// message. The default value is \a true. | |
| 76 | inline void trigger_lco_event(naming::id_type const& id, | |
| 77 | naming::id_type const& cont, bool move_credits = true) | |
| 78 | { | |
| 79 | trigger_lco_event(id, naming::address(), cont, move_credits); | |
| 80 | } | |
| 81 | ||
| 82 | /// \brief Set the result value for the LCO referenced by the given id | |
| 83 | /// | |
| 84 | /// \param id [in] This represents the id of the LCO which should | |
| 85 | /// receive the given value. | |
| 86 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 87 | /// triggered. | |
| 88 | /// \param t [in] This is the value which should be sent to the LCO. | |
| 89 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 90 | /// send all credits in \a id along with the generated | |
| 91 | /// message. The default value is \a true. | |
| 92 | template <typename Result> | |
| 93 | void set_lco_value(naming::id_type const& id, | |
| 94 | naming::address && addr, Result && t, bool move_credits = true); | |
| 95 | ||
| 96 | /// \brief Set the result value for the LCO referenced by the given id | |
| 97 | /// | |
| 98 | /// \param id [in] This represents the id of the LCO which should | |
| 99 | /// receive the given value. | |
| 100 | /// \param t [in] This is the value which should be sent to the LCO. | |
| 101 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 102 | /// send all credits in \a id along with the generated | |
| 103 | /// message. The default value is \a true. | |
| 104 | template <typename Result> | |
| 105 | typename std::enable_if< | |
| 106 | !std::is_same<typename util::decay<Result>::type, naming::address>::value | |
| 107 | >::type | |
| 108 | set_lco_value(naming::id_type const& id, Result && t, bool move_credits = true) | |
| 109 | { | |
| 110 | set_lco_value(id, naming::address(), std::forward<Result>(t), move_credits); | |
| 111 | } | |
| 112 | ||
| 113 | /// \brief Set the result value for the LCO referenced by the given id | |
| 114 | /// | |
| 115 | /// \param id [in] This represents the id of the LCO which should | |
| 116 | /// receive the given value. | |
| 117 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 118 | /// triggered. | |
| 119 | /// \param t [in] This is the value which should be sent to the LCO. | |
| 120 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 121 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 122 | /// send all credits in \a id along with the generated | |
| 123 | /// message. The default value is \a true. | |
| 124 | template <typename Result> | |
| 125 | void set_lco_value(naming::id_type const& id, | |
| 126 | naming::address && addr, Result && t, naming::id_type const& cont, | |
| 127 | bool move_credits = true); | |
| 128 | ||
| 129 | /// \brief Set the result value for the LCO referenced by the given id | |
| 130 | /// | |
| 131 | /// \param id [in] This represents the id of the LCO which should | |
| 132 | /// receive the given value. | |
| 133 | /// \param t [in] This is the value which should be sent to the LCO. | |
| 134 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 135 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 136 | /// send all credits in \a id along with the generated | |
| 137 | /// message. The default value is \a true. | |
| 138 | template <typename Result> | |
| 139 | typename std::enable_if< | |
| 140 | !std::is_same<typename util::decay<Result>::type, naming::address>::value | |
| 141 | >::type | |
| 142 | set_lco_value(naming::id_type const& id, Result && t, | |
| 143 | naming::id_type const& cont, bool move_credits = true) | |
| 144 | { | |
| 145 | set_lco_value(id, naming::address(), std::forward<Result>(t), cont, | |
| 146 | move_credits); | |
| 147 | } | |
| 148 | ||
| 149 | /// \brief Set the error state for the LCO referenced by the given id | |
| 150 | /// | |
| 151 | /// \param id [in] This represents the id of the LCO which should | |
| 152 | /// receive the error value. | |
| 153 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 154 | /// triggered. | |
| 155 | /// \param e [in] This is the error value which should be sent to | |
| 156 | /// the LCO. | |
| 157 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 158 | /// send all credits in \a id along with the generated | |
| 159 | /// message. The default value is \a true. | |
| 160 | HPX_API_EXPORT void set_lco_error(naming::id_type const& id, | |
| 161 | naming::address && addr, boost::exception_ptr const& e, | |
| 162 | bool move_credits = true); | |
| 163 | ||
| 164 | /// \brief Set the error state for the LCO referenced by the given id | |
| 165 | /// | |
| 166 | /// \param id [in] This represents the id of the LCO which should | |
| 167 | /// receive the error value. | |
| 168 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 169 | /// triggered. | |
| 170 | /// \param e [in] This is the error value which should be sent to | |
| 171 | /// the LCO. | |
| 172 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 173 | /// send all credits in \a id along with the generated | |
| 174 | /// message. The default value is \a true. | |
| 175 | HPX_API_EXPORT void set_lco_error(naming::id_type const& id, | |
| 176 | naming::address && addr, boost::exception_ptr && e, | |
| 177 | bool move_credits = true); | |
| 178 | ||
| 179 | /// \brief Set the error state for the LCO referenced by the given id | |
| 180 | /// | |
| 181 | /// \param id [in] This represents the id of the LCO which should | |
| 182 | /// receive the error value. | |
| 183 | /// \param e [in] This is the error value which should be sent to | |
| 184 | /// the LCO. | |
| 185 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 186 | /// send all credits in \a id along with the generated | |
| 187 | /// message. The default value is \a true. | |
| 188 | inline void set_lco_error(naming::id_type const& id, | |
| 189 | boost::exception_ptr const& e, bool move_credits = true) | |
| 190 | { | |
| 191 | set_lco_error(id, naming::address(), e, move_credits); | |
| 192 | } | |
| 193 | ||
| 194 | /// \brief Set the error state for the LCO referenced by the given id | |
| 195 | /// | |
| 196 | /// \param id [in] This represents the id of the LCO which should | |
| 197 | /// receive the error value. | |
| 198 | /// \param e [in] This is the error value which should be sent to | |
| 199 | /// the LCO. | |
| 200 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 201 | /// send all credits in \a id along with the generated | |
| 202 | /// message. The default value is \a true. | |
| 203 | inline void set_lco_error(naming::id_type const& id, | |
| 204 | boost::exception_ptr && e, bool move_credits = true) | |
| 205 | { | |
| 206 | set_lco_error(id, naming::address(), std::move(e), move_credits); | |
| 207 | } | |
| 208 | ||
| 209 | /// \brief Set the error state for the LCO referenced by the given id | |
| 210 | /// | |
| 211 | /// \param id [in] This represents the id of the LCO which should | |
| 212 | /// receive the error value. | |
| 213 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 214 | /// triggered. | |
| 215 | /// \param e [in] This is the error value which should be sent to | |
| 216 | /// the LCO. | |
| 217 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 218 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 219 | /// send all credits in \a id along with the generated | |
| 220 | /// message. The default value is \a true. | |
| 221 | HPX_API_EXPORT void set_lco_error(naming::id_type const& id, | |
| 222 | naming::address && addr, boost::exception_ptr const& e, | |
| 223 | naming::id_type const& cont, bool move_credits = true); | |
| 224 | ||
| 225 | /// \brief Set the error state for the LCO referenced by the given id | |
| 226 | /// | |
| 227 | /// \param id [in] This represents the id of the LCO which should | |
| 228 | /// receive the error value. | |
| 229 | /// \param addr [in] This represents the addr of the LCO which should be | |
| 230 | /// triggered. | |
| 231 | /// \param e [in] This is the error value which should be sent to | |
| 232 | /// the LCO. | |
| 233 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 234 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 235 | /// send all credits in \a id along with the generated | |
| 236 | /// message. The default value is \a true. | |
| 237 | HPX_API_EXPORT void set_lco_error(naming::id_type const& id, | |
| 238 | naming::address && addr, boost::exception_ptr && e, | |
| 239 | naming::id_type const& cont, bool move_credits = true); | |
| 240 | ||
| 241 | /// \brief Set the error state for the LCO referenced by the given id | |
| 242 | /// | |
| 243 | /// \param id [in] This represents the id of the LCO which should | |
| 244 | /// receive the error value. | |
| 245 | /// \param e [in] This is the error value which should be sent to | |
| 246 | /// the LCO. | |
| 247 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 248 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 249 | /// send all credits in \a id along with the generated | |
| 250 | /// message. The default value is \a true. | |
| 251 | inline void set_lco_error(naming::id_type const& id, | |
| 252 | boost::exception_ptr const& e, naming::id_type const& cont, | |
| 253 | bool move_credits = true) | |
| 254 | { | |
| 255 | set_lco_error(id, naming::address(), e, cont, move_credits); | |
| 256 | } | |
| 257 | ||
| 258 | /// \brief Set the error state for the LCO referenced by the given id | |
| 259 | /// | |
| 260 | /// \param id [in] This represents the id of the LCO which should | |
| 261 | /// receive the error value. | |
| 262 | /// \param e [in] This is the error value which should be sent to | |
| 263 | /// the LCO. | |
| 264 | /// \param cont [in] This represents the LCO to trigger after completion. | |
| 265 | /// \param move_credits [in] If this is set to \a true then it is ok to | |
| 266 | /// send all credits in \a id along with the generated | |
| 267 | /// message. The default value is \a true. | |
| 268 | inline void set_lco_error(naming::id_type const& id, | |
| 269 | boost::exception_ptr && e, naming::id_type const& cont, | |
| 270 | bool move_credits = true) | |
| 271 | { | |
| 272 | set_lco_error(id, naming::address(), std::move(e), cont, move_credits); | |
| 273 | } | |
| 274 | ||
| 275 | ////////////////////////////////////////////////////////////////////////// | |
| 276 | // forward declare the required overload of apply. | |
| 277 | template <typename Action, typename ...Ts> | |
| 278 | bool apply(naming::id_type const& gid, Ts&&... vs); | |
| 279 | ||
| 280 | template < | |
| 281 | typename Component, typename Signature, typename Derived, | |
| 282 | typename Cont, typename ...Ts> | |
| 283 | bool apply_continue( | |
| 284 | hpx::actions::basic_action<Component, Signature, Derived>, | |
| 285 | Cont&& cont, naming::id_type const& gid, Ts&&... vs); | |
| 286 | ||
| 287 | template <typename Component, typename Signature, typename Derived, | |
| 288 | typename ...Ts> | |
| 289 | inline bool | |
| 290 | apply_c(hpx::actions::basic_action<Component, Signature, Derived>, | |
| 291 | naming::id_type const& contgid, naming::id_type const& gid, | |
| 292 | Ts&&... vs); | |
| 293 | ||
| 294 | ////////////////////////////////////////////////////////////////////////// | |
| 295 | // handling special case of triggering an LCO | |
| 296 | /////////////////////////////////////////////////////////////////////////// | |
| 297 | namespace detail | |
| 298 | { | |
| 299 | template <typename T> | |
| 300 | struct make_rvalue_impl | |
| 301 | { | |
| 302 | typedef T && type; | |
| 303 | ||
| 304 | template <typename U> | |
| 305 | HPX_FORCEINLINE static T && call(U& u) | |
| 306 | { | |
| 307 | return std::move(u); | |
| 308 | } | |
| 309 | }; | |
| 310 | ||
| 311 | template <typename T> | |
| 312 | struct make_rvalue_impl<T const> | |
| 313 | { | |
| 314 | typedef T type; | |
| 315 | ||
| 316 | template <typename U> | |
| 317 | HPX_FORCEINLINE static T call(U const& u) | |
| 318 | { | |
| 319 | return u; | |
| 320 | } | |
| 321 | }; | |
| 322 | ||
| 323 | template <typename T> | |
| 324 | struct make_rvalue_impl<T&> | |
| 325 | { | |
| 326 | typedef T type; | |
| 327 | ||
| 328 | HPX_FORCEINLINE static T call(T& u) | |
| 329 | { | |
| 330 | return u; | |
| 331 | } | |
| 332 | }; | |
| 333 | ||
| 334 | template <typename T> | |
| 335 | struct make_rvalue_impl<T const&> | |
| 336 | { | |
| 337 | typedef T type; | |
| 338 | ||
| 339 | HPX_FORCEINLINE static T call(T const& u) | |
| 340 | { | |
| 341 | return u; | |
| 342 | } | |
| 343 | }; | |
| 344 | ||
| 345 | template <typename T> | |
| 346 | HPX_FORCEINLINE typename detail::make_rvalue_impl<T>::type | |
| 347 | make_rvalue(typename std::remove_reference<T>::type& v) | |
| 348 | { | |
| 349 | return detail::make_rvalue_impl<T>::call(v); | |
| 350 | } | |
| 351 | ||
| 352 | template <typename T> | |
| 353 | HPX_FORCEINLINE typename detail::make_rvalue_impl<T>::type | |
| 354 | make_rvalue(typename std::remove_reference<T>::type&& v) | |
| 355 | { | |
| 356 | return detail::make_rvalue_impl<T>::call(v); | |
| 357 | } | |
| 358 | } | |
| 359 | ||
| 360 | template <typename Result> | |
| 361 | void set_lco_value(naming::id_type const& id, naming::address && addr, | |
| 362 | Result && t, bool move_credits) | |
| 363 | { | |
| 364 | typedef typename util::decay<Result>::type remote_result_type; | |
| 365 | typedef typename traits::promise_local_result< | |
| 366 | remote_result_type | |
| 367 | >::type local_result_type; | |
| 368 | typedef typename lcos::base_lco_with_value< | |
| 369 | local_result_type, remote_result_type | |
| 370 | >::set_value_action set_value_action; | |
| 371 | ||
| 372 | if (move_credits && | |
| 373 | id.get_management_type() != naming::id_type::unmanaged) | |
| 374 | { | |
| 375 | naming::id_type target(id.get_gid(), | |
| 376 | naming::id_type::managed_move_credit); | |
| 377 | id.make_unmanaged(); | |
| 378 | ||
| 379 | detail::apply_impl<set_value_action>(target, std::move(addr), | |
| 380 | actions::action_priority<set_value_action>(), | |
| 381 | detail::make_rvalue<Result>(t)); | |
| 382 | } | |
| 383 | else | |
| 384 | { | |
| 385 | detail::apply_impl<set_value_action>(id, std::move(addr), | |
| 386 | actions::action_priority<set_value_action>(), | |
| 387 | detail::make_rvalue<Result>(t)); | |
| 388 | } | |
| 389 | } | |
| 390 | ||
| 391 | template <typename Result> | |
| 392 | void set_lco_value(naming::id_type const& id, naming::address && addr, | |
| 393 | Result && t, naming::id_type const& cont, bool move_credits) | |
| 394 | { | |
| 395 | typedef typename util::decay<Result>::type remote_result_type; | |
| 396 | typedef typename traits::promise_local_result< | |
| 397 | remote_result_type | |
| 398 | >::type local_result_type; | |
| 399 | typedef typename lcos::base_lco_with_value< | |
| 400 | local_result_type, remote_result_type | |
| 401 | >::set_value_action set_value_action; | |
| 402 | ||
| 403 | if (move_credits && | |
| 404 | id.get_management_type() != naming::id_type::unmanaged) | |
| 405 | { | |
| 406 | naming::id_type target(id.get_gid(), | |
| 407 | naming::id_type::managed_move_credit); | |
| 408 | id.make_unmanaged(); | |
| 409 | ||
| 410 | detail::apply_impl<set_value_action>( | |
| 411 | actions::typed_continuation< | |
| 412 | local_result_type, remote_result_type>(cont), | |
| 413 | target, std::move(addr), | |
| 414 | detail::make_rvalue<Result>(t)); | |
| 415 | } | |
| 416 | else | |
| 417 | { | |
| 418 | detail::apply_impl<set_value_action>( | |
| 419 | actions::typed_continuation< | |
| 420 | local_result_type, remote_result_type>(cont), | |
| 421 | id, std::move(addr), | |
| 422 | detail::make_rvalue<Result>(t)); | |
| 423 | } | |
| 424 | } | |
| 425 | } | |
| 426 | ||
| 427 | #endif | |
| 428 |
Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.