Skip to content

Commit

Permalink
Merge pull request #2674 from STEllAR-GROUP/fixing_future_serialization
Browse files Browse the repository at this point in the history
Turning assertions into exceptions
  • Loading branch information
hkaiser committed Jun 6, 2017
2 parents 4efc50b + 33ba6b1 commit 5e88a63
Showing 1 changed file with 16 additions and 54 deletions.
70 changes: 16 additions & 54 deletions hpx/lcos/future.hpp
Expand Up @@ -90,7 +90,9 @@ namespace hpx { namespace lcos { namespace detail
} else if (state == future_state::invalid) {
f = Future();
} else {
HPX_ASSERT(false);
HPX_THROW_EXCEPTION(invalid_status,
"serialize_future_load",
"attempting to deserialize a future with an unknown state");
}
}

Expand Down Expand Up @@ -121,7 +123,9 @@ namespace hpx { namespace lcos { namespace detail
} else if (state == future_state::invalid) {
f = Future();
} else {
HPX_ASSERT(false);
HPX_THROW_EXCEPTION(invalid_status,
"serialize_future_load",
"attempting to deserialize a future with an unknown state");
}
}

Expand All @@ -133,9 +137,9 @@ namespace hpx { namespace lcos { namespace detail
typedef typename hpx::traits::future_traits<Future>::result_type value_type;

int state = future_state::invalid;
if(ar.is_preprocessing())
if (f.valid() && !f.is_ready())
{
if(!f.is_ready())
if (ar.is_preprocessing())
{
typename hpx::traits::detail::shared_state_ptr_for<Future>::type state
= hpx::traits::future_access<Future>::get_shared_state(f);
Expand All @@ -146,35 +150,13 @@ namespace hpx { namespace lcos { namespace detail
}
else
{
if(f.is_ready())
{
if (f.has_value())
{
value_type const & value =
*hpx::traits::future_access<Future>::
get_shared_state(f)->get_result();
state = future_state::has_value;
ar << state << value; //-V128
} else if (f.has_exception()) {
state = future_state::has_exception;
boost::exception_ptr exception = f.get_exception_ptr();
ar << state << exception;
} else {
state = future_state::invalid;
ar << state;
}
}
HPX_THROW_EXCEPTION(invalid_status,
"serialize_future_save",
"future must be ready in order for it to be serialized");
}
return;
}

#if defined(HPX_DEBUG)
if (f.valid())
{
HPX_ASSERT(f.is_ready());
}
#endif

if (f.has_value())
{
state = future_state::has_value;
Expand All @@ -198,9 +180,9 @@ namespace hpx { namespace lcos { namespace detail
>::type serialize_future_save(Archive& ar, Future const& f) //-V659
{
int state = future_state::invalid;
if(ar.is_preprocessing())
if (f.valid() && !f.is_ready())
{
if(!f.is_ready())
if (ar.is_preprocessing())
{
typename
hpx::traits::detail::shared_state_ptr_for<Future>::type state
Expand All @@ -212,33 +194,13 @@ namespace hpx { namespace lcos { namespace detail
}
else
{
if (f.has_value())
{
state = future_state::has_value;
ar << state;
}
else if (f.has_exception())
{
state = future_state::has_exception;
boost::exception_ptr exception = f.get_exception_ptr();
ar << state << exception;
}
else
{
state = future_state::invalid;
ar << state;
}
HPX_THROW_EXCEPTION(invalid_status,
"serialize_future_save",
"future must be ready in order for it to be serialized");
}
return;
}

#if defined(HPX_DEBUG)
if (f.valid())
{
HPX_ASSERT(f.is_ready());
}
#endif

if (f.has_value())
{
state = future_state::has_value;
Expand Down

0 comments on commit 5e88a63

Please sign in to comment.