Skip to content

Commit

Permalink
Merge pull request #1473 from STEllAR-GROUP/fixing_action_move_tests
Browse files Browse the repository at this point in the history
Fixing action move tests
  • Loading branch information
sithhell committed Apr 22, 2015
2 parents de9bde7 + 2b89f4a commit b0346d4
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 50 deletions.
32 changes: 31 additions & 1 deletion hpx/lcos/future.hpp
Expand Up @@ -1335,6 +1335,11 @@ namespace hpx { namespace actions
util::placeholders::_1));
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -1452,6 +1457,11 @@ namespace hpx { namespace actions
util::placeholders::_1));
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -1567,6 +1577,11 @@ namespace hpx { namespace actions
util::placeholders::_1));
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -1684,6 +1699,11 @@ namespace hpx { namespace actions
util::placeholders::_1));
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -1747,8 +1767,13 @@ namespace hpx { namespace traits
///////////////////////////////////////////////////////////////////////////
template <typename R>
struct serialize_as_future<lcos::future<R> >
: boost::mpl::true_
: boost::mpl::false_
{
static bool call_if(lcos::future<R>& f)
{
return f.valid() && !f.is_ready();
}

static void call(lcos::future<R>& f)
{
f.wait();
Expand All @@ -1759,6 +1784,11 @@ namespace hpx { namespace traits
struct serialize_as_future<lcos::shared_future<R> >
: boost::mpl::true_
{
static bool call_if(lcos::shared_future<R>& f)
{
return f.valid() && !f.is_ready();
}

static void call(lcos::shared_future<R>& f)
{
f.wait();
Expand Down
60 changes: 39 additions & 21 deletions hpx/lcos/local/detail/invoke_when_ready.hpp
Expand Up @@ -142,20 +142,51 @@ namespace hpx { namespace lcos { namespace local { namespace detail
}
}

template <typename F, typename ...Ts>
future<typename util::result_of<
typename util::decay<F>::type(typename util::decay<Ts>::type...)
>::type>
invoke_when_ready_delayed(F&& f, Ts&&... vs)
{
typedef when_ready<
typename util::decay<F>::type
, util::tuple<typename util::decay<Ts>::type...>
> invoker_type;

// launch a new thread with high priority which performs the 'waiting'
boost::intrusive_ptr<invoker_type> p(new invoker_type(
std::forward<F>(f), std::forward<Ts>(vs)...));
threads::register_thread_nullary(
util::deferred_call(&invoker_type::apply, p)
, "hpx::lcos::local::detail::invoke_when_ready",
threads::pending, true, threads::thread_priority_boost);

using traits::future_access;
return future_access<typename invoker_type::type>::create(std::move(p));
}

///////////////////////////////////////////////////////////////////////////
template <typename F, typename ...Ts>
typename boost::disable_if<
util::detail::any_of<
traits::serialize_as_future<typename util::decay<F>::type>,
traits::serialize_as_future<typename util::decay<Ts>::type>...>
, future<typename util::result_of<
typename util::decay<F>::type(typename util::decay<Ts>::type...)
>::type>
>::type invoke_when_ready(F&& f, Ts&&... vs)
>::type
invoke_when_ready(F&& f, Ts&&... vs)
{
typedef typename util::decay<F>::type function_type;

if (traits::serialize_as_future<function_type>::call_if(f))
{
return invoke_when_ready_delayed(std::forward<F>(f),
std::forward<Ts>(vs)...);
}

typedef typename util::result_of<
typename util::decay<F>::type(typename util::decay<Ts>::type...)
>::type result_type;
function_type(typename util::decay<Ts>::type...)
>::type result_type;
typedef typename boost::is_void<result_type>::type is_void;

return invoke_fused_now(is_void(),
Expand All @@ -165,28 +196,15 @@ namespace hpx { namespace lcos { namespace local { namespace detail
template <typename F, typename ...Ts>
typename boost::enable_if<
util::detail::any_of<
traits::serialize_as_future<typename util::decay<F>::type>,
traits::serialize_as_future<typename util::decay<Ts>::type>...>
, future<typename util::result_of<
typename util::decay<F>::type(typename util::decay<Ts>::type...)
>::type>
>::type invoke_when_ready(F&& f, Ts&&... vs)
>::type
invoke_when_ready(F&& f, Ts&&... vs)
{
typedef when_ready<
typename util::decay<F>::type
, util::tuple<typename util::decay<Ts>::type...>
> invoker_type;

// launch a new thread with high priority which performs the 'waiting'
boost::intrusive_ptr<invoker_type> p(new invoker_type(
std::forward<F>(f), std::forward<Ts>(vs)...));
threads::register_thread_nullary(
util::deferred_call(&invoker_type::apply, p)
, "hpx::lcos::local::detail::invoke_when_ready",
threads::pending, true, threads::thread_priority_boost);

using traits::future_access;
return future_access<typename invoker_type::type>::create(std::move(p));
return invoke_when_ready_delayed(std::forward<F>(f),
std::forward<Ts>(vs)...);
}
}}}}

Expand Down
24 changes: 23 additions & 1 deletion hpx/runtime/actions/continuation.hpp
Expand Up @@ -224,6 +224,7 @@ namespace hpx { namespace actions
return gid_;
}

virtual bool has_to_wait_for_futures() = 0;
virtual void wait_for_futures() = 0;

protected:
Expand Down Expand Up @@ -319,6 +320,11 @@ namespace hpx { namespace actions
return std::move(t);
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<cont_type>::call_if(cont_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<cont_type>::call(cont_);
Expand Down Expand Up @@ -378,7 +384,13 @@ namespace hpx { namespace actions
return std::move(t);
}

void wait_for_futures()
virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<cont_type>::call_if(cont_) ||
traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<cont_type>::call(cont_);
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -462,6 +474,11 @@ namespace hpx { namespace actions
}
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down Expand Up @@ -588,6 +605,11 @@ namespace hpx { namespace actions
this->trigger();
}

virtual bool has_to_wait_for_futures()
{
return traits::serialize_as_future<function_type>::call_if(f_);
}

virtual void wait_for_futures()
{
traits::serialize_as_future<function_type>::call(f_);
Expand Down
7 changes: 6 additions & 1 deletion hpx/runtime/agas/request.hpp
Expand Up @@ -260,8 +260,13 @@ namespace hpx { namespace traits
{
template <>
struct serialize_as_future<hpx::agas::request>
: boost::mpl::true_
: boost::mpl::false_
{
static bool call_if(hpx::agas::request& r)
{
return r.get_action_code() == hpx::agas::primary_ns_route;
}

static void call(hpx::agas::request& r)
{
// routed parcels need to be checked for embedded future objects
Expand Down
10 changes: 7 additions & 3 deletions hpx/runtime/applier/apply.hpp
Expand Up @@ -136,12 +136,16 @@ namespace hpx
{
template <typename Action>
struct serialize_as_future<applier::detail::put_parcel<Action> >
: boost::mpl::true_
: boost::mpl::false_
{
static bool call_if(applier::detail::put_parcel<Action>& pp)
{
return pp.cont_ && pp.cont_->has_to_wait_for_futures();
}

static void call(applier::detail::put_parcel<Action>& pp)
{
if (pp.cont_)
pp.cont_->wait_for_futures();
if (pp.cont_) pp.cont_->wait_for_futures();
}
};
}
Expand Down
32 changes: 20 additions & 12 deletions hpx/runtime/components/client_base.hpp
Expand Up @@ -110,18 +110,6 @@ namespace hpx { namespace traits
return std::forward<T_>(value);
}
};

///////////////////////////////////////////////////////////////////////////
template <typename Derived>
struct serialize_as_future<Derived,
typename boost::enable_if<is_client<Derived> >::type>
: boost::mpl::true_
{
static void call(Derived& c)
{
c.wait();
}
};
}}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -489,5 +477,25 @@ namespace hpx { namespace components
}
}}

namespace hpx { namespace traits
{
///////////////////////////////////////////////////////////////////////////
template <typename Derived>
struct serialize_as_future<Derived,
typename boost::enable_if<is_client<Derived> >::type>
: boost::mpl::false_
{
static bool call_if(Derived& c)
{
return c.valid() && !c.is_ready();
}

static void call(Derived& c)
{
c.wait();
}
};
}}

#endif

5 changes: 5 additions & 0 deletions hpx/runtime/parcelset/parcel.hpp
Expand Up @@ -775,6 +775,11 @@ namespace hpx { namespace traits
struct serialize_as_future<hpx::parcelset::parcel>
: boost::mpl::true_
{
static bool call_if(hpx::parcelset::parcel& r)
{
return true;
}

static void call(hpx::parcelset::parcel& p)
{
p.wait_for_futures();
Expand Down
20 changes: 19 additions & 1 deletion hpx/traits/serialize_as_future.hpp
Expand Up @@ -6,6 +6,7 @@
#if !defined(HPX_TRAITS_SERIALIZE_AS_FUTURE_AUG_08_2014_0853PM)
#define HPX_TRAITS_SERIALIZE_AS_FUTURE_AUG_08_2014_0853PM

#include <hpx/config/forceinline.hpp>
#include <hpx/traits.hpp>
#include <hpx/traits/is_future.hpp>
#include <hpx/traits/is_future_range.hpp>
Expand All @@ -31,11 +32,26 @@ namespace hpx { namespace lcos
namespace hpx { namespace traits
{
///////////////////////////////////////////////////////////////////////////
// This trait is used by invoke_when_ready to decide whether a parcel can
// be sent directly (no futures are being wrapped by the continuation or
// argument data structures), or if the parcel has to be delayed until all
// futures have become ready.
//
// If the trait statically evaluates to true_, the parcel will be delayed
// in any case and call() will be invoked on this trait to wait for all
// (embedded) futures to become ready.
// If it statically evaluates to false_, the decision whether the parcel
// will be delayed is done at runtime. The function call_if() will be
// invoked in this case to decide whether the parcel has to be delayed or
// not. If call_if() returns true the parcel will be delayed and call()
// will be invoked to wait for the (embedded) futures to become ready.
//
template <typename Future, typename Enable>
struct serialize_as_future
: boost::mpl::false_
{
static void call(Future& f) {}
static BOOST_FORCEINLINE bool call_if(Future&) { return false; }
static BOOST_FORCEINLINE void call(Future&) {}
};

template <typename T>
Expand All @@ -59,6 +75,8 @@ namespace hpx { namespace traits
, typename boost::enable_if<is_future_range<Range> >::type>
: boost::mpl::true_
{
static BOOST_FORCEINLINE bool call_if(Range& r) { return true; }

static void call(Range& r)
{
hpx::lcos::wait_all(r);
Expand Down
7 changes: 7 additions & 0 deletions hpx/util/bind.hpp
Expand Up @@ -492,6 +492,13 @@ namespace hpx { namespace traits
serialize_as_future<BoundArgs>::value
>
{
static BOOST_FORCEINLINE
bool call_if(util::detail::bound<F, BoundArgs>& b)
{
return serialize_as_future<F>::call_if(b._f) ||
serialize_as_future<BoundArgs>::call_if(b._bound_args);
}

static void call(util::detail::bound<F, BoundArgs> & b)
{
traits::serialize_as_future<F>::call(b._f);
Expand Down
8 changes: 7 additions & 1 deletion hpx/util/bind_action.hpp
Expand Up @@ -321,7 +321,13 @@ namespace hpx { namespace traits
struct serialize_as_future<util::detail::bound_action<Action, BoundArgs> >
: serialize_as_future<BoundArgs>
{
static void call(util::detail::bound_action<Action, BoundArgs> & b)
static bool
call_if(util::detail::bound_action<Action, BoundArgs>& b)
{
return serialize_as_future<BoundArgs>::call_if(b._bound_args);
}

static void call(util::detail::bound_action<Action, BoundArgs>& b)
{
traits::serialize_as_future<BoundArgs>::call(b._bound_args);
}
Expand Down

0 comments on commit b0346d4

Please sign in to comment.