From 3026fb3c3bce7bd26fb62e84e4d3d078231218d6 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 23 Feb 2021 14:43:18 +0100 Subject: [PATCH] Define getter/setter for Exception::value. --- include/simgrid/Exception.hpp | 8 +++++--- src/kernel/activity/CommImpl.cpp | 3 +-- src/msg/msg_comm.cpp | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 613c527abf..5439656f97 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -92,6 +92,10 @@ public: /** Return the information about where the exception was thrown */ xbt::ThrowPoint const& throw_point() const { return throwpoint_; } + /** Allow to carry a value (used by testany/waitany) */ + int get_value() const { return value_; } + void set_value(int value) { value_ = value; } + std::string resolve_backtrace() const { return throwpoint_.backtrace_.resolve(); } virtual void rethrow_nested(const simgrid::xbt::ThrowPoint& throwpoint, const std::string& message) const @@ -99,11 +103,9 @@ public: std::throw_with_nested(Exception(throwpoint, message)); } - /** Allow to carry a value (used by waitall/waitany) */ - int value = 0; - private: xbt::ThrowPoint throwpoint_; + int value_ = 0; }; #define DECLARE_SIMGRID_EXCEPTION(AnyException, ...) \ diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index cf007f6502..15ceed9435 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -686,12 +686,11 @@ void CommImpl::finish() } CommImpl** element = std::find(comms, comms + count, this); int rank = (element != comms + count) ? element - comms : -1; - // In order to modify the exception we have to rethrow it: try { std::rethrow_exception(simcall->issuer_->exception_); } catch (simgrid::Exception& e) { - e.value = rank; + e.set_value(rank); } } diff --git a/src/msg/msg_comm.cpp b/src/msg/msg_comm.cpp index 3a4bca249b..fd36e6e6eb 100644 --- a/src/msg/msg_comm.cpp +++ b/src/msg/msg_comm.cpp @@ -99,13 +99,13 @@ int MSG_comm_testany(const_xbt_dynar_t comms) try { finished_index = simcall_comm_testany(s_comms.data(), s_comms.size()); } catch (const simgrid::TimeoutException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TIMEOUT; } catch (const simgrid::CancelException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TASK_CANCELED; } catch (const simgrid::NetworkFailureException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TRANSFER_FAILURE; } @@ -176,13 +176,13 @@ int MSG_comm_waitany(const_xbt_dynar_t comms) try { finished_index = simcall_comm_waitany(s_comms.data(), s_comms.size(), -1); } catch (const simgrid::TimeoutException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TIMEOUT; } catch (const simgrid::CancelException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TASK_CANCELED; } catch (const simgrid::NetworkFailureException& e) { - finished_index = e.value; + finished_index = e.get_value(); status = MSG_TRANSFER_FAILURE; } -- 2.20.1