From f8930986cd96dc07bf6d3f9d800a3935541340d9 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sat, 16 Feb 2019 20:08:50 +0100 Subject: [PATCH 1/1] add support for CancelException --- include/simgrid/Exception.hpp | 6 ++++++ src/msg/msg_gos.cpp | 34 +++++++++++----------------------- src/simix/smx_host.cpp | 3 ++- src/simix/smx_io.cpp | 2 +- src/simix/smx_network.cpp | 16 +++++++--------- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index db16dd9525..b414b15f8b 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -146,6 +146,12 @@ public: /** Exception raised when something got canceled before completion */ class CancelException : public xbt_ex { +public: + CancelException(simgrid::xbt::ThrowPoint throwpoint, std::string message) + : xbt_ex(std::move(throwpoint), std::move(message)) + { + category = cancel_error; + } }; } // namespace simgrid diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index ed298144cb..8f3b0986f5 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -92,11 +92,8 @@ msg_error_t MSG_parallel_task_execute_with_timeout(msg_task_t task, double timeo status = MSG_HOST_FAILURE; } catch (simgrid::TimeoutError& e) { status = MSG_TIMEOUT; - } catch (xbt_ex& e) { - if (e.category == cancel_error) - status = MSG_TASK_CANCELED; - else - throw; + } catch (simgrid::CancelException& e) { + status = MSG_TASK_CANCELED; } /* action ended, set comm and compute = nullptr, the actions is already destroyed in the main function */ @@ -259,17 +256,13 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d ret = MSG_HOST_FAILURE; } catch (simgrid::TimeoutError& e) { ret = MSG_TIMEOUT; + } catch (simgrid::CancelException& e) { + ret = MSG_HOST_FAILURE; } catch (xbt_ex& e) { - switch (e.category) { - case cancel_error: - ret = MSG_HOST_FAILURE; - break; - case network_error: + if (e.category == network_error) ret = MSG_TRANSFER_FAILURE; - break; - default: + else throw; - } } if (ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) { @@ -752,18 +745,13 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl simcall_comm_wait(comm, timeout); } catch (simgrid::TimeoutError& e) { ret = MSG_TIMEOUT; - } - catch (xbt_ex& e) { - switch (e.category) { - case cancel_error: - ret = MSG_HOST_FAILURE; - break; - case network_error: + } catch (simgrid::CancelException& e) { + ret = MSG_HOST_FAILURE; + } catch (xbt_ex& e) { + if (e.category == network_error) ret = MSG_TRANSFER_FAILURE; - break; - default: + else throw; - } /* If the send failed, it is not used anymore */ t_simdata->setNotUsed(); diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index b7ce26dd56..8f17148061 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -113,7 +113,8 @@ void SIMIX_execution_finish(smx_activity_t synchro) case SIMIX_CANCELED: XBT_DEBUG("SIMIX_execution_finished: execution canceled"); - SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled"); + simcall->issuer->exception = + std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "Execution Canceled")); break; case SIMIX_TIMEOUT: diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index bb18ed00fb..b82e48d1ff 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -47,7 +47,7 @@ void SIMIX_io_finish(smx_activity_t synchro) SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed"); break; case SIMIX_CANCELED: - SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled"); + simcall->issuer->exception = std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "I/O Canceled")); break; default: xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast(synchro->state_)); diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index b855c9fc0a..7916873e42 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -446,9 +446,11 @@ void SIMIX_comm_finish(smx_activity_t synchro) case SIMIX_CANCELED: if (simcall->issuer == comm->dst_actor_) - SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the sender"); + simcall->issuer->exception = std::make_exception_ptr( + simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the sender")); else - SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Communication canceled by the receiver"); + simcall->issuer->exception = std::make_exception_ptr( + simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the receiver")); break; default: @@ -483,13 +485,9 @@ void SIMIX_comm_finish(smx_activity_t synchro) } catch (simgrid::NetworkFailureException& e) { e.value = rank; simcall->issuer->exception = std::make_exception_ptr(e); - } catch (xbt_ex& e) { - if (e.category == cancel_error) { - e.value = rank; - simcall->issuer->exception = std::make_exception_ptr(e); - } else { - xbt_die("Unexpected xbt_ex(%s). Please enhance this code", xbt_ex_catname(e.category)); - } + } catch (simgrid::CancelException& e) { + e.value = rank; + simcall->issuer->exception = std::make_exception_ptr(e); } } -- 2.20.1