Skip to content

Commit

Permalink
Keeping parcel alive long enough to ensure zero copy serialization is…
Browse files Browse the repository at this point in the history
… functioning properly (this relates to #1001: Zero copy serialization raises assert )
  • Loading branch information
hkaiser committed Nov 9, 2013
1 parent 1df779b commit 02a4903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/runtime/parcelset/parcelhandler.cpp
Expand Up @@ -432,6 +432,19 @@ namespace hpx { namespace parcelset
}

///////////////////////////////////////////////////////////////////////////
namespace detail
{
// The original parcel-sent handler is wrapped to keep the parcel alive
// until after the data has been reliably sent (which is needed for zero
// copy serialization).
void parcel_sent_handler(boost::system::error_code const& ec,
std::size_t size, parcelhandler::write_handler_type const& f,
parcel const&)
{
f(ec, size); // invoke the original handler
}
}

void parcelhandler::put_parcel(parcel& p, write_handler_type const& f)
{
rethrow_exception();
Expand Down Expand Up @@ -472,18 +485,24 @@ namespace hpx { namespace parcelset
// If we were able to resolve the address(es) locally we send the
// parcel directly to the destination.
if (resolved_locally) {
// rewrap the given parcel-sent handler
using util::placeholders::_1;
using util::placeholders::_2;
write_handler_type wrapped_f =
util::bind(&detail::parcel_sent_handler, _1, _2, f, p);

// dispatch to the message handler which is associated with the
// encapsulated action
connection_type t = find_appropriate_connection_type(addrs[0].locality_);
policies::message_handler* mh =
p.get_message_handler(this, addrs[0].locality_, t);

if (mh) {
mh->put_parcel(p, f);
mh->put_parcel(p, wrapped_f);
return;
}

find_parcelport(t)->put_parcel(p, f);
find_parcelport(t)->put_parcel(p, wrapped_f);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/regressions/util/zero_copy_parcels_1001.cpp
Expand Up @@ -48,7 +48,7 @@ int hpx_main()
test_action act;

std::size_t size = 1;
for (std::size_t i = 0; i != 14; ++i)
for (std::size_t i = 0; i != 20; ++i)
{
std::vector<int> data;
data.resize(size << i);
Expand Down

0 comments on commit 02a4903

Please sign in to comment.