Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move StopRequest out of Context.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Jan 2019 10:56:44 +0000 (11:56 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 25 Jan 2019 11:31:06 +0000 (12:31 +0100)
Using context::Context in fully qualified name was redundant.

src/bindings/python/simgrid_python.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextUnix.cpp
src/simix/ActorImpl.cpp
src/xbt/exception.cpp

index 4a67d2e..1469120 100644 (file)
@@ -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<simgrid::kernel::context::Context::StopRequest>(m, "ActorKilled");
+  py::object pyStopRequestEx = py::register_exception<simgrid::kernel::context::StopRequest>(m, "ActorKilled");
 
   /* this_actor namespace */
   void (*sleep_for_fun)(double) = &simgrid::s4u::this_actor::sleep_for; // pick the right overload
index 7b828c1..fb8aacb 100644 (file)
@@ -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<void(void)> try_block)
@@ -112,7 +114,7 @@ bool try_n_catch_stoprequest(std::function<void(void)> try_block)
   try {
     try_block();
     res = true;
-  } catch (Context::StopRequest const&) {
+  } catch (StopRequest const&) {
     XBT_DEBUG("Caught a StopRequest");
     res = false;
   }
index b77601c..06bd27a 100644 (file)
@@ -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<void(void)> try_block);
 
index 88d4710..a39ef84 100644 (file)
@@ -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());
index 9bf3f15..cb138fb 100644 (file)
@@ -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;
   }
index 4fd03bc..94fc91f 100644 (file)
@@ -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);