| Line | % of fetches | Source |
|---|---|---|
| 1 | // Copyright (c) 2007-2016 Hartmut Kaiser | |
| 2 | // Copyright (c) 2011 Bryce Lelbach | |
| 3 | // | |
| 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 plain_action.hpp | |
| 8 | ||
| 9 | #if !defined(HPX_RUNTIME_ACTIONS_PLAIN_ACTION_NOV_14_2008_0706PM) | |
| 10 | #define HPX_RUNTIME_ACTIONS_PLAIN_ACTION_NOV_14_2008_0706PM | |
| 11 | ||
| 12 | #include <hpx/config.hpp> | |
| 13 | #include <hpx/runtime/actions/basic_action.hpp> | |
| 14 | #include <hpx/runtime/actions/continuation.hpp> | |
| 15 | #include <hpx/runtime/components/console_error_sink.hpp> | |
| 16 | #include <hpx/runtime/naming/address.hpp> | |
| 17 | #include <hpx/traits/component_type_database.hpp> | |
| 18 | #include <hpx/util/detail/count_num_args.hpp> | |
| 19 | #include <hpx/util/detail/pack.hpp> | |
| 20 | #include <hpx/util/detail/pp_strip_parens.hpp> | |
| 21 | #include <hpx/util/unused.hpp> | |
| 22 | ||
| 23 | #include <boost/preprocessor/cat.hpp> | |
| 24 | ||
| 25 | #include <cstdlib> | |
| 26 | #include <sstream> | |
| 27 | #include <stdexcept> | |
| 28 | #include <string> | |
| 29 | #if defined(__NVCC__) | |
| 30 | #include <type_traits> | |
| 31 | #endif | |
| 32 | #include <utility> | |
| 33 | ||
| 34 | #include <hpx/config/warnings_prefix.hpp> | |
| 35 | ||
| 36 | /////////////////////////////////////////////////////////////////////////////// | |
| 37 | namespace hpx { namespace actions | |
| 38 | { | |
| 39 | /// \cond NOINTERNAL | |
| 40 | ||
| 41 | namespace detail | |
| 42 | { | |
| 43 | struct plain_function | |
| 44 | { | |
| 45 | // Only localities are valid targets for a plain action | |
| 46 | static bool is_target_valid(naming::id_type const& id) | |
| 47 | { | |
| 48 | return naming::is_locality(id); | |
| 49 | } | |
| 50 | }; | |
| 51 | } | |
| 52 | ||
| 53 | /////////////////////////////////////////////////////////////////////////// | |
| 54 | // Specialized generic plain (free) action types allowing to hold a | |
| 55 | // different number of arguments | |
| 56 | /////////////////////////////////////////////////////////////////////////// | |
| 57 | template < | |
| 58 | typename R, typename ...Ps, | |
| 59 | typename TF, TF F, typename Derived> | |
| 60 | class basic_action_impl<R (*)(Ps...), TF, F, Derived> | |
| 61 | : public basic_action<detail::plain_function, R(Ps...), Derived> | |
| 62 | { | |
| 63 | public: | |
| 64 | ||
| 65 | typedef void is_plain_action; | |
| 66 | ||
| 67 | static std::string get_action_name(naming::address::address_type /*lva*/) | |
| 68 | { | |
| 69 | std::stringstream name; | |
| 70 | name << "plain action(" << detail::get_action_name<Derived>() << ")"; | |
| 71 | return name.str(); | |
| 72 | } | |
| 73 | ||
| 74 | template <typename ...Ts> | |
| 75 | static R invoke(naming::address::address_type /*lva*/, Ts&&... vs) | |
| 76 | { | |
| 77 | basic_action<detail::plain_function, R(Ps...), Derived>:: | |
| 78 | increment_invocation_count(); | |
| 79 | return F(std::forward<Ts>(vs)...); | |
| 80 | } | |
| 81 | }; | |
| 82 | ||
| 83 | /// \endcond | |
| 84 | }} | |
| 85 | ||
| 86 | namespace hpx { namespace traits | |
| 87 | { | |
| 88 | /// \cond NOINTERNAL | |
| 89 | template <> HPX_ALWAYS_EXPORT | |
| 90 | inline components::component_type | |
| 91 | component_type_database<hpx::actions::detail::plain_function>::get() | |
| 92 | { | |
| 93 | return hpx::components::component_plain_function; | |
| 94 | } | |
| 95 | ||
| 96 | template <> HPX_ALWAYS_EXPORT | |
| 97 | inline void | |
| 98 | component_type_database<hpx::actions::detail::plain_function>::set( | |
| 99 | components::component_type) | |
| 100 | { | |
| 101 | HPX_ASSERT(false); // shouldn't be ever called | |
| 102 | } | |
| 103 | /// \endcond | |
| 104 | }} | |
| 105 | ||
| 106 | /// \def HPX_DEFINE_PLAIN_ACTION(func, name) | |
| 107 | /// \brief Defines a plain action type | |
| 108 | /// | |
| 109 | /// \par Example: | |
| 110 | /// | |
| 111 | /// \code | |
| 112 | /// namespace app | |
| 113 | /// { | |
| 114 | /// void some_global_function(double d) | |
| 115 | /// { | |
| 116 | /// cout << d; | |
| 117 | /// } | |
| 118 | /// | |
| 119 | /// // This will define the action type 'app::some_global_action' which | |
| 120 | /// // represents the function 'app::some_global_function'. | |
| 121 | /// HPX_DEFINE_PLAIN_ACTION(some_global_function, some_global_action); | |
| 122 | /// } | |
| 123 | /// \endcode | |
| 124 | /// | |
| 125 | /// \note Usually this macro will not be used in user code unless the intent is | |
| 126 | /// to avoid defining the action_type in global namespace. Normally, the use of | |
| 127 | /// the macro \a HPX_PLAIN_ACTION is recommended. | |
| 128 | /// | |
| 129 | /// \note The macro \a HPX_DEFINE_PLAIN_ACTION can be used with 1 or 2 | |
| 130 | /// arguments. The second argument is optional. The default value for the | |
| 131 | /// second argument (the typename of the defined action) is derived from the | |
| 132 | /// name of the function (as passed as the first argument) by appending '_action'. | |
| 133 | /// The second argument can be omitted only if the first argument with an | |
| 134 | /// appended suffix '_action' resolves to a valid, unqualified C++ type name. | |
| 135 | /// | |
| 136 | #define HPX_DEFINE_PLAIN_ACTION(...) \ | |
| 137 | HPX_DEFINE_PLAIN_ACTION_(__VA_ARGS__) \ | |
| 138 | /**/ | |
| 139 | ||
| 140 | /// \cond NOINTERNAL | |
| 141 | ||
| 142 | #define HPX_DEFINE_PLAIN_DIRECT_ACTION(...) \ | |
| 143 | HPX_DEFINE_PLAIN_DIRECT_ACTION_(__VA_ARGS__) \ | |
| 144 | /**/ | |
| 145 | ||
| 146 | #define HPX_DEFINE_PLAIN_ACTION_(...) \ | |
| 147 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 148 | HPX_DEFINE_PLAIN_ACTION_, HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 149 | )(__VA_ARGS__)) \ | |
| 150 | /**/ | |
| 151 | ||
| 152 | #define HPX_DEFINE_PLAIN_DIRECT_ACTION_(...) \ | |
| 153 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 154 | HPX_DEFINE_PLAIN_DIRECT_ACTION_, HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 155 | )(__VA_ARGS__)) \ | |
| 156 | /**/ | |
| 157 | ||
| 158 | #define HPX_DEFINE_PLAIN_ACTION_1(func) \ | |
| 159 | HPX_DEFINE_PLAIN_ACTION_2(func, BOOST_PP_CAT(func, _action)) \ | |
| 160 | /**/ | |
| 161 | ||
| 162 | #if defined(__NVCC__) | |
| 163 | #define HPX_DEFINE_PLAIN_ACTION_2(func, name) \ | |
| 164 | struct name : hpx::actions::make_action< \ | |
| 165 | typename std::add_pointer< \ | |
| 166 | typename std::remove_pointer<decltype(&func)>::type \ | |
| 167 | >::type, &func, name>::type {} \ | |
| 168 | /**/ | |
| 169 | #else | |
| 170 | #define HPX_DEFINE_PLAIN_ACTION_2(func, name) \ | |
| 171 | struct name : hpx::actions::make_action< \ | |
| 172 | decltype(&func), &func, name>::type {} \ | |
| 173 | /**/ | |
| 174 | #endif | |
| 175 | ||
| 176 | #define HPX_DEFINE_PLAIN_DIRECT_ACTION_1(func) \ | |
| 177 | HPX_DEFINE_PLAIN_DIRECT_ACTION_2(func, BOOST_PP_CAT(func, _action)) \ | |
| 178 | /**/ | |
| 179 | ||
| 180 | #define HPX_DEFINE_PLAIN_DIRECT_ACTION_2(func, name) \ | |
| 181 | struct name : hpx::actions::make_direct_action< \ | |
| 182 | decltype(&func), &func, name>::type {} \ | |
| 183 | /**/ | |
| 184 | ||
| 185 | /// \endcond | |
| 186 | ||
| 187 | /////////////////////////////////////////////////////////////////////////////// | |
| 188 | /// \def HPX_DECLARE_PLAIN_ACTION(func, name) | |
| 189 | /// \brief Declares a plain action type | |
| 190 | /// | |
| 191 | #define HPX_DECLARE_PLAIN_ACTION(...) \ | |
| 192 | HPX_DECLARE_ACTION(__VA_ARGS__) \ | |
| 193 | /**/ | |
| 194 | ||
| 195 | /// \def HPX_PLAIN_ACTION(func, name) | |
| 196 | /// | |
| 197 | /// \brief Defines a plain action type based on the given function | |
| 198 | /// \a func and registers it with HPX. | |
| 199 | /// | |
| 200 | /// The macro \a HPX_PLAIN_ACTION can be used to define a plain action (e.g. an | |
| 201 | /// action encapsulating a global or free function) based on the given function | |
| 202 | /// \a func. It defines the action type \a name representing the given function. | |
| 203 | /// This macro additionally registers the newly define action type with HPX. | |
| 204 | /// | |
| 205 | /// The parameter \p func is a global or free (non-member) function which | |
| 206 | /// should be encapsulated into a plain action. The parameter \p name is the | |
| 207 | /// name of the action type defined by this macro. | |
| 208 | /// | |
| 209 | /// \par Example: | |
| 210 | /// | |
| 211 | /// \code | |
| 212 | /// namespace app | |
| 213 | /// { | |
| 214 | /// void some_global_function(double d) | |
| 215 | /// { | |
| 216 | /// cout << d; | |
| 217 | /// } | |
| 218 | /// } | |
| 219 | /// | |
| 220 | /// // This will define the action type 'some_global_action' which represents | |
| 221 | /// // the function 'app::some_global_function'. | |
| 222 | /// HPX_PLAIN_ACTION(app::some_global_function, some_global_action); | |
| 223 | /// \endcode | |
| 224 | /// | |
| 225 | /// \note The macro \a HPX_PLAIN_ACTION has to be used at global namespace even | |
| 226 | /// if the wrapped function is located in some other namespace. The newly | |
| 227 | /// defined action type is placed into the global namespace as well. | |
| 228 | /// | |
| 229 | /// \note The macro \a HPX_PLAIN_ACTION_ID can be used with 1, 2, or 3 arguments. | |
| 230 | /// The second and third arguments are optional. The default value for the | |
| 231 | /// second argument (the typename of the defined action) is derived from the | |
| 232 | /// name of the function (as passed as the first argument) by appending '_action'. | |
| 233 | /// The second argument can be omitted only if the first argument with an | |
| 234 | /// appended suffix '_action' resolves to a valid, unqualified C++ type name. | |
| 235 | /// The default value for the third argument is \a hpx::components::factory_check. | |
| 236 | /// | |
| 237 | /// \note Only one of the forms of this macro \a HPX_PLAIN_ACTION or | |
| 238 | /// \a HPX_PLAIN_ACTION_ID should be used for a particular action, | |
| 239 | /// never both. | |
| 240 | /// | |
| 241 | #define HPX_PLAIN_ACTION(...) \ | |
| 242 | HPX_PLAIN_ACTION_(__VA_ARGS__) \ | |
| 243 | /**/ | |
| 244 | ||
| 245 | /// \def HPX_PLAIN_ACTION_ID(func, actionname, actionid) | |
| 246 | /// | |
| 247 | /// \brief Defines a plain action type based on the given function \a func and | |
| 248 | /// registers it with HPX. | |
| 249 | /// | |
| 250 | /// The macro \a HPX_PLAIN_ACTION_ID can be used to define a plain action (e.g. an | |
| 251 | /// action encapsulating a global or free function) based on the given function | |
| 252 | /// \a func. It defines the action type \a actionname representing the given function. | |
| 253 | /// The parameter \a actionid | |
| 254 | /// | |
| 255 | /// The parameter \a actionid specifies an unique integer value which will be | |
| 256 | /// used to represent the action during serialization. | |
| 257 | /// | |
| 258 | /// The parameter \p func is a global or free (non-member) function which | |
| 259 | /// should be encapsulated into a plain action. The parameter \p name is the | |
| 260 | /// name of the action type defined by this macro. | |
| 261 | /// | |
| 262 | /// The second parameter has to be usable as a plain (non-qualified) C++ | |
| 263 | /// identifier, it should not contain special characters which cannot be part | |
| 264 | /// of a C++ identifier, such as '<', '>', or ':'. | |
| 265 | /// | |
| 266 | /// \par Example: | |
| 267 | /// | |
| 268 | /// \code | |
| 269 | /// namespace app | |
| 270 | /// { | |
| 271 | /// void some_global_function(double d) | |
| 272 | /// { | |
| 273 | /// cout << d; | |
| 274 | /// } | |
| 275 | /// } | |
| 276 | /// | |
| 277 | /// // This will define the action type 'some_global_action' which represents | |
| 278 | /// // the function 'app::some_global_function'. | |
| 279 | /// HPX_PLAIN_ACTION_ID(app::some_global_function, some_global_action, | |
| 280 | /// some_unique_id); | |
| 281 | /// \endcode | |
| 282 | /// | |
| 283 | /// \note The macro \a HPX_PLAIN_ACTION_ID has to be used at global namespace even | |
| 284 | /// if the wrapped function is located in some other namespace. The newly | |
| 285 | /// defined action type is placed into the global namespace as well. | |
| 286 | /// | |
| 287 | /// \note Only one of the forms of this macro \a HPX_PLAIN_ACTION or | |
| 288 | /// \a HPX_PLAIN_ACTION_ID should be used for a particular action, | |
| 289 | /// never both. | |
| 290 | /// | |
| 291 | #define HPX_PLAIN_ACTION_ID(func, name, id) \ | |
| 292 | HPX_DEFINE_PLAIN_ACTION(func, name); \ | |
| 293 | HPX_REGISTER_ACTION_DECLARATION(name, name); \ | |
| 294 | HPX_REGISTER_ACTION_ID(name, name, id); \ | |
| 295 | /**/ | |
| 296 | ||
| 297 | /// \cond NOINTERNAL | |
| 298 | ||
| 299 | #define HPX_PLAIN_DIRECT_ACTION(...) \ | |
| 300 | HPX_PLAIN_DIRECT_ACTION_(__VA_ARGS__) \ | |
| 301 | /**/ | |
| 302 | ||
| 303 | /// \endcond | |
| 304 | ||
| 305 | /// \cond NOINTERNAL | |
| 306 | ||
| 307 | // macros for plain actions | |
| 308 | #define HPX_PLAIN_ACTION_(...) \ | |
| 309 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 310 | HPX_PLAIN_ACTION_, HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 311 | )(__VA_ARGS__)) \ | |
| 312 | /**/ | |
| 313 | #define HPX_PLAIN_ACTION_2(func, name) \ | |
| 314 | HPX_DEFINE_PLAIN_ACTION(func, name); \ | |
| 315 | HPX_REGISTER_ACTION_DECLARATION(name, name); \ | |
| 316 | HPX_REGISTER_ACTION(name, name); \ | |
| 317 | /**/ | |
| 318 | #define HPX_PLAIN_ACTION_1(func) \ | |
| 319 | HPX_PLAIN_ACTION_2(func, BOOST_PP_CAT(func, _action)); \ | |
| 320 | /**/ | |
| 321 | ||
| 322 | // same for direct actions | |
| 323 | #define HPX_PLAIN_DIRECT_ACTION_(...) \ | |
| 324 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 325 | HPX_PLAIN_DIRECT_ACTION_, HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 326 | )(__VA_ARGS__)) \ | |
| 327 | /**/ | |
| 328 | #define HPX_PLAIN_DIRECT_ACTION_2(func, name) \ | |
| 329 | HPX_DEFINE_PLAIN_DIRECT_ACTION(func, name); \ | |
| 330 | HPX_REGISTER_ACTION_DECLARATION(name, name); \ | |
| 331 | HPX_REGISTER_ACTION(name, name); \ | |
| 332 | /**/ | |
| 333 | #define HPX_PLAIN_DIRECT_ACTION_1(func) \ | |
| 334 | HPX_PLAIN_DIRECT_ACTION_2(func, BOOST_PP_CAT(func, _action)); \ | |
| 335 | /**/ | |
| 336 | #define HPX_PLAIN_DIRECT_ACTION_ID(func, name, id) \ | |
| 337 | HPX_DEFINE_PLAIN_DIRECT_ACTION(func, name); \ | |
| 338 | HPX_REGISTER_ACTION_DECLARATION(name, name); \ | |
| 339 | HPX_REGISTER_ACTION_ID(name, name, id); \ | |
| 340 | /**/ | |
| 341 | ||
| 342 | /// \endcond | |
| 343 | ||
| 344 | #include <hpx/config/warnings_suffix.hpp> | |
| 345 | ||
| 346 | #endif | |
| 347 | ||
| 348 |
Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.