From c3066090245b1d56a9927723543cbc93dcb0d9ee Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 24 Jan 2019 11:56:44 +0100 Subject: [PATCH] Move StopRequest out of Context. Using context::Context in fully qualified name was redundant. --- src/bindings/python/simgrid_python.cpp | 2 +- src/kernel/context/Context.cpp | 6 ++++-- src/kernel/context/Context.hpp | 30 +++++++++++++------------- src/kernel/context/ContextUnix.cpp | 2 +- src/simix/ActorImpl.cpp | 4 ++-- src/xbt/exception.cpp | 2 +- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 4a67d2eb6e..1469120ee9 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -56,7 +56,7 @@ PYBIND11_MODULE(simgrid, m) m.attr("simgrid_version") = simgrid_version; // Internal exception used to kill actors and sweep the RAII chimney (free objects living on the stack) - py::object pyStopRequestEx = py::register_exception(m, "ActorKilled"); + py::object pyStopRequestEx = py::register_exception(m, "ActorKilled"); /* this_actor namespace */ void (*sleep_for_fun)(double) = &simgrid::s4u::this_actor::sleep_for; // pick the right overload diff --git a/src/kernel/context/Context.cpp b/src/kernel/context/Context.cpp index 7b828c1b1b..fb8aacb0e4 100644 --- a/src/kernel/context/Context.cpp +++ b/src/kernel/context/Context.cpp @@ -101,9 +101,11 @@ void Context::stop() AttachContext::~AttachContext() = default; +StopRequest::~StopRequest() = default; + void throw_stoprequest() { - throw Context::StopRequest(); + throw StopRequest(); } bool try_n_catch_stoprequest(std::function try_block) @@ -112,7 +114,7 @@ bool try_n_catch_stoprequest(std::function try_block) try { try_block(); res = true; - } catch (Context::StopRequest const&) { + } catch (StopRequest const&) { XBT_DEBUG("Caught a StopRequest"); res = false; } diff --git a/src/kernel/context/Context.hpp b/src/kernel/context/Context.hpp index b77601cf0a..06bd27aa8a 100644 --- a/src/kernel/context/Context.hpp +++ b/src/kernel/context/Context.hpp @@ -72,21 +72,6 @@ public: static Context* self(); /** @brief Sets the current context of this thread */ static void set_current(Context* self); - - class StopRequest { - /** @brief Exception launched to kill a process, in order to properly unwind its stack and release RAII stuff - * - * Nope, Sonar, this should not inherit of std::exception nor of simgrid::Exception. - * Otherwise, users may accidentally catch it with a try {} catch (std::exception) - */ - public: - StopRequest() = default; - explicit StopRequest(std::string msg) : msg_(std::string("Actor killed (") + msg + std::string(").")) {} - const char* what() const noexcept { return msg_.c_str(); } - - private: - std::string msg_ = std::string("Actor killed."); - }; }; class XBT_PUBLIC AttachContext : public Context { @@ -107,6 +92,21 @@ public: virtual void attach_stop() = 0; }; +class XBT_PUBLIC StopRequest { + /** @brief Exception launched to kill a process, in order to properly unwind its stack and release RAII stuff + * + * Nope, Sonar, this should not inherit of std::exception nor of simgrid::Exception. + * Otherwise, users may accidentally catch it with a try {} catch (std::exception) + */ +public: + StopRequest() = default; + explicit StopRequest(std::string msg) : msg_(std::string("Actor killed (") + msg + std::string(").")) {} + ~StopRequest(); + const char* what() const noexcept { return msg_.c_str(); } + +private: + std::string msg_ = std::string("Actor killed."); +}; XBT_PUBLIC void throw_stoprequest(); XBT_PUBLIC bool try_n_catch_stoprequest(std::function try_block); diff --git a/src/kernel/context/ContextUnix.cpp b/src/kernel/context/ContextUnix.cpp index 88d4710956..a39ef84980 100644 --- a/src/kernel/context/ContextUnix.cpp +++ b/src/kernel/context/ContextUnix.cpp @@ -41,7 +41,7 @@ static void smx_ctx_wrapper(int i1, int i2) try { (*context)(); context->Context::stop(); - } catch (simgrid::kernel::context::Context::StopRequest const&) { + } catch (simgrid::kernel::context::StopRequest const&) { XBT_DEBUG("Caught a StopRequest"); } catch (simgrid::Exception const& e) { XBT_INFO("Actor killed by an uncatched exception %s", simgrid::xbt::demangle(typeid(e).name()).get()); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 9bf3f1577d..cb138fbc6a 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -474,7 +474,7 @@ void SIMIX_process_kill(smx_actor_t actor, smx_actor_t issuer) // Forcefully kill the actor if its host is turned off. Not an HostFailureException because you should not survive that if (actor->host_->is_off()) - actor->throw_exception(std::make_exception_ptr(simgrid::kernel::context::Context::StopRequest("host failed"))); + actor->throw_exception(std::make_exception_ptr(simgrid::kernel::context::StopRequest("host failed"))); /* destroy the blocking synchro if any */ if (actor->waiting_synchro != nullptr) { @@ -721,7 +721,7 @@ void SIMIX_process_yield(smx_actor_t self) if (self->context_->iwannadie) { XBT_DEBUG("Process %s@%s is dead", self->get_cname(), self->host_->get_cname()); - // throw simgrid::kernel::context::Context::StopRequest(); Does not seem to properly kill the actor + // throw simgrid::kernel::context::StopRequest(); Does not seem to properly kill the actor self->context_->stop(); THROW_IMPOSSIBLE; } diff --git a/src/xbt/exception.cpp b/src/xbt/exception.cpp index 4fd03bc71a..94fc91f197 100644 --- a/src/xbt/exception.cpp +++ b/src/xbt/exception.cpp @@ -146,7 +146,7 @@ static void handler() std::abort(); } - catch (simgrid::kernel::context::Context::StopRequest& e) { + catch (simgrid::kernel::context::StopRequest& e) { XBT_ERROR("Received a StopRequest at the top-level exception handler. Maybe a Java->C++ call that is not protected " "in a try/catch?"); show_backtrace(bt); -- 2.20.1