Skip to content

Commit

Permalink
Fixing more places where future was extracted from promise after id
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jun 8, 2016
1 parent 9a4cbe7 commit 0aa5be3
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 25 deletions.
5 changes: 4 additions & 1 deletion hpx/lcos/async_continue.hpp
Expand Up @@ -46,12 +46,15 @@ namespace hpx
continuation_result_type;

lcos::promise<result_type, RemoteResult> p;
auto f = p.get_future();

apply<Action>(
hpx::actions::typed_continuation<
result_type, continuation_result_type
>(p.get_id(), std::forward<Cont>(cont))
, target, std::forward<Ts>(vs)...);
return p.get_future();

return f;
}
}

Expand Down
5 changes: 4 additions & 1 deletion hpx/lcos/async_continue_callback.hpp
Expand Up @@ -41,11 +41,14 @@ namespace hpx
continuation_result_type;

lcos::promise<result_type, RemoteResult> p;
auto f = p.get_future();

apply_cb<Action>(
hpx::actions::typed_continuation<result_type, continuation_result_type>(
p.get_id(), std::forward<Cont>(cont))
, target, std::forward<Callback>(cb), std::forward<Ts>(vs)...);
return p.get_future();

return f;
}
}

Expand Down
4 changes: 3 additions & 1 deletion hpx/lcos/stubs/object_semaphore.hpp
Expand Up @@ -53,8 +53,10 @@ struct object_semaphore : components::stub_base<
{
typedef typename server_type::get_action action_type;
lcos::promise<ValueType> lco;
auto f = lco.get_future();

hpx::apply<action_type>(gid, lco.get_id());
return lco.get_future();
return f;
}

static ValueType get_sync(naming::id_type const& gid)
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/agas/addressing_service.cpp
Expand Up @@ -2080,13 +2080,15 @@ future<hpx::id_type> addressing_service::on_symbol_namespace_event(
}

lcos::promise<naming::id_type, naming::gid_type> p;
auto result_f = p.get_future();

request req(symbol_ns_on_event, name, evt, call_for_past_events, p.get_id());
hpx::future<bool> f = stubs::symbol_namespace::service_async<bool>(
name, req, action_priority_);

using util::placeholders::_1;
return f.then(util::bind(
util::one_shot(&detail::on_register_event), _1, p.get_future()
util::one_shot(&detail::on_register_event), _1, std::move(result_f)
));
}

Expand Down
9 changes: 7 additions & 2 deletions src/runtime/components/stubs/runtime_support_stubs.cpp
Expand Up @@ -197,10 +197,13 @@ namespace hpx { namespace components { namespace stubs
typedef server::runtime_support::shutdown_action action_type;

lcos::promise<void> value;
auto f = value.get_future();

// We need to make it unmanaged to avoid late refcnt requests
id_type gid(value.get_id().get_gid(), id_type::unmanaged);
hpx::apply<action_type>(targetgid, timeout, gid);
return value.get_future();

return f;
}

void runtime_support::shutdown(naming::id_type const& targetgid,
Expand Down Expand Up @@ -239,8 +242,10 @@ namespace hpx { namespace components { namespace stubs
typedef server::runtime_support::terminate_action action_type;

lcos::promise<void> value;
auto f = value.get_future();

hpx::apply<action_type>(targetgid, value.get_id());
return value.get_future();
return f;
}

void runtime_support::terminate(naming::id_type const& targetgid)
Expand Down
2 changes: 1 addition & 1 deletion tests/performance/network/osu/CMakeLists.txt
Expand Up @@ -24,7 +24,7 @@ foreach(benchmark ${benchmarks})
COMPONENT_DEPENDENCIES iostreams
EXCLUDE_FROM_ALL
HPX_PREFIX ${HPX_BUILD_PREFIX}
FOLDER "Benchmarks/Network/${benchmark}")
FOLDER "Benchmarks/Network/OSU")

# add a custom target for this example
add_hpx_pseudo_target(tests.performance.network.osu_perf.${benchmark})
Expand Down
12 changes: 5 additions & 7 deletions tests/performance/network/osu/osu_coll.hpp
Expand Up @@ -101,8 +101,8 @@ distribute_component(std::vector<hpx::id_type> localities,
future_type f;
{
hpx::lcos::packaged_action<action_type, std::vector<hpx::naming::gid_type> > p;
p.apply(hpx::launch::async, this_loc, type, num_components);
f = p.get_future();
p.apply(hpx::launch::async, this_loc, type, num_components);
}

std::vector<hpx::future<result_type> > components_futures;
Expand All @@ -120,21 +120,19 @@ distribute_component(std::vector<hpx::id_type> localities,
if(locs_first.size() > 0)
{
hpx::lcos::packaged_action<distribute_component_action, result_type > p;
auto f = p.get_future();
hpx::id_type id = locs_first[0];
p.apply(hpx::launch::async, id, std::move(locs_first), type);
components_futures.push_back(
p.get_future()
);
components_futures.push_back(std::move(f));
}

if(locs_second.size() > 0)
{
hpx::lcos::packaged_action<distribute_component_action, result_type > p;
auto f = p.get_future();
hpx::id_type id = locs_second[0];
p.apply(hpx::launch::async, id, std::move(locs_second), type);
components_futures.push_back(
p.get_future()
);
components_futures.push_back(std::move(f));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/regressions/lcos/promise_1620.cpp
Expand Up @@ -32,8 +32,8 @@ void test_leak()

{
hpx::lcos::promise<test> p;
hpx::apply_c<call_action>(p.get_id(), hpx::find_here());
f = p.get_future();
hpx::apply_c<call_action>(p.get_id(), hpx::find_here());
}

test t = f.get();
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/parcelset/put_parcels.cpp
Expand Up @@ -92,14 +92,15 @@ void test_future_argument(hpx::id_type const& id)
{
hpx::lcos::local::promise<double> p_arg;
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

parcels.push_back(
generate_parcel<test2_action>(id, p_cont.get_id(),
p_arg.get_future())
);

args.push_back(std::move(p_arg));
results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down Expand Up @@ -136,6 +137,7 @@ void test_mixed_arguments(hpx::id_type const& id)
for (std::size_t i = 0; i != numparcels_default; ++i)
{
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

if (std::rand() % 2)
{
Expand All @@ -155,7 +157,7 @@ void test_mixed_arguments(hpx::id_type const& id)
args.push_back(std::move(p_arg));
}

results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/parcelset/put_parcels_with_coalescing.cpp
Expand Up @@ -74,10 +74,13 @@ void test_plain_argument(hpx::id_type const& id)
for (std::size_t i = 0; i != numparcels_default; ++i)
{
hpx::lcos::promise<hpx::id_type> p;
auto f = p.get_future();

parcels.push_back(
generate_parcel<test1_action>(c.get_id(), p.get_id(), data)
);
results.push_back(p.get_future());

results.push_back(std::move(f));
}

// send parcels
Expand Down Expand Up @@ -115,14 +118,15 @@ void test_future_argument(hpx::id_type const& id)
{
hpx::lcos::local::promise<double> p_arg;
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

parcels.push_back(
generate_parcel<test2_action>(id, p_cont.get_id(),
p_arg.get_future())
);

args.push_back(std::move(p_arg));
results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down Expand Up @@ -161,6 +165,7 @@ void test_mixed_arguments(hpx::id_type const& id)
for (std::size_t i = 0; i != numparcels_default; ++i)
{
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

if (std::rand() % 2)
{
Expand All @@ -180,7 +185,7 @@ void test_mixed_arguments(hpx::id_type const& id)
args.push_back(std::move(p_arg));
}

results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/parcelset/put_parcels_with_compression.cpp
Expand Up @@ -82,10 +82,13 @@ void test_plain_argument(hpx::id_type const& id)
for (std::size_t i = 0; i != numparcels_default; ++i)
{
hpx::lcos::promise<hpx::id_type> p;
auto f = p.get_future();

parcels.push_back(
generate_parcel<test1_action>(c.get_id(), p.get_id(), data)
);
results.push_back(p.get_future());

results.push_back(std::move(f));
}

// send parcels
Expand Down Expand Up @@ -132,14 +135,15 @@ void test_future_argument(hpx::id_type const& id)
{
hpx::lcos::local::promise<double> p_arg;
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

parcels.push_back(
generate_parcel<test2_action>(id, p_cont.get_id(),
p_arg.get_future())
);

args.push_back(std::move(p_arg));
results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down Expand Up @@ -178,6 +182,7 @@ void test_mixed_arguments(hpx::id_type const& id)
for (std::size_t i = 0; i != numparcels_default; ++i)
{
hpx::lcos::promise<hpx::id_type> p_cont;
auto f_cont = p_cont.get_future();

if (std::rand() % 2)
{
Expand All @@ -197,7 +202,7 @@ void test_mixed_arguments(hpx::id_type const& id)
args.push_back(std::move(p_arg));
}

results.push_back(p_cont.get_future());
results.push_back(std::move(f_cont));
}

// send parcels
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/parcelset/set_parcel_write_handler.cpp
Expand Up @@ -51,8 +51,11 @@ int main()
for (hpx::id_type const& id: localities)
{
hpx::lcos::promise<void> p;
auto f = p.get_future();

hpx::apply<test_action>(id, p.get_id());
wait_for.push_back(p.get_future());

wait_for.push_back(std::move(f));
}

hpx::wait_all(wait_for);
Expand All @@ -68,8 +71,11 @@ int main()
for (hpx::id_type const& id: localities)
{
hpx::lcos::promise<void> p;
auto f = p.get_future();

hpx::apply<test_action>(id, p.get_id());
wait_for.push_back(p.get_future());

wait_for.push_back(std::move(f));
}

hpx::wait_all(wait_for);
Expand Down

0 comments on commit 0aa5be3

Please sign in to comment.