Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move the actor lifecycle markers from Context to ActorImpl
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Mar 2022 11:25:05 +0000 (12:25 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Mar 2022 14:30:06 +0000 (15:30 +0100)
and reduce Context.hpp visibility

17 files changed:
src/bindings/java/jmsg_task.cpp
src/bindings/java/jmsg_vm.cpp
src/bindings/python/simgrid_python.cpp
src/kernel/EngineImpl.cpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/IoImpl.cpp
src/kernel/activity/Synchro.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp
src/kernel/actor/Simcall.cpp
src/kernel/context/Context.cpp
src/kernel/context/Context.hpp
src/kernel/context/ContextBoost.hpp
src/mc/mc_record.cpp
src/s4u/s4u_Actor.cpp
src/xbt/exception.cpp

index 02d2d33..d5686e2 100644 (file)
@@ -7,7 +7,6 @@
 
 #include "simgrid/Exception.hpp"
 #include "simgrid/s4u/Host.hpp"
-#include "src/kernel/context/Context.hpp"
 
 #include "jmsg.hpp"
 #include "jmsg_host.h"
index b8153a3..48cd4ab 100644 (file)
@@ -10,7 +10,6 @@
 #include "jxbt_utilities.hpp"
 #include "simgrid/Exception.hpp"
 #include "simgrid/plugins/live_migration.h"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/VirtualMachineImpl.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
index 60ce5f6..f79cfb0 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "simgrid/kernel/ProfileBuilder.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
-#include "src/kernel/context/Context.hpp"
 #include <simgrid/Exception.hpp>
 #include <simgrid/s4u/Actor.hpp>
 #include <simgrid/s4u/Comm.hpp>
index b105c17..79f12ec 100644 (file)
@@ -454,7 +454,7 @@ void EngineImpl::run_all_actors()
   instance_->get_context_factory()->run_all();
 
   for (auto const& actor : actors_to_run_)
-    if (actor->context_->to_be_freed())
+    if (actor->to_be_freed())
       actor->cleanup_from_kernel();
 
   actors_to_run_.swap(actors_that_ran_);
index a383818..1e6483d 100644 (file)
@@ -14,7 +14,6 @@
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/activity/MailboxImpl.hpp"
 #include "src/kernel/actor/SimcallObserver.hpp"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/CpuImpl.hpp"
 #include "src/kernel/resource/LinkImpl.hpp"
 #include "src/kernel/resource/StandardLinkImpl.hpp"
@@ -481,7 +480,7 @@ void CommImpl::set_exception(actor::ActorImpl* issuer)
 
     case State::SRC_HOST_FAILURE:
       if (issuer == src_actor_)
-        issuer->context_->set_wannadie();
+        issuer->set_wannadie();
       else {
         set_state(State::FAILED);
         issuer->exception_ = std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
@@ -490,7 +489,7 @@ void CommImpl::set_exception(actor::ActorImpl* issuer)
 
     case State::DST_HOST_FAILURE:
       if (issuer == dst_actor_)
-        issuer->context_->set_wannadie();
+        issuer->set_wannadie();
       else {
         set_state(State::FAILED);
         issuer->exception_ = std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
@@ -554,10 +553,10 @@ void CommImpl::finish()
     /* Check out for errors */
 
     if (not simcall->issuer_->get_host()->is_on()) {
-      simcall->issuer_->context_->set_wannadie();
+      simcall->issuer_->set_wannadie();
     } else {
       // Do not answer to dying actors
-      if (not simcall->issuer_->context_->wannadie()) {
+      if (not simcall->issuer_->wannadie()) {
         set_exception(simcall->issuer_);
         simcall->issuer_->simcall_answer();
       }
index 360ec95..b33dac4 100644 (file)
@@ -184,7 +184,7 @@ void ExecImpl::set_exception(actor::ActorImpl* issuer)
       if (issuer->get_host()->is_on())
         issuer->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed"));
       else /* else, the actor will be killed with no possibility to survive */
-        issuer->context_->set_wannadie();
+        issuer->set_wannadie();
       break;
 
     case State::CANCELED:
@@ -219,7 +219,7 @@ void ExecImpl::finish()
     if (simcall->issuer_->get_host()->is_on())
       simcall->issuer_->simcall_answer();
     else
-      simcall->issuer_->context_->set_wannadie();
+      simcall->issuer_->set_wannadie();
   }
 }
 
index 07dff0f..cdd593d 100644 (file)
@@ -12,7 +12,6 @@
 #include "src/kernel/activity/IoImpl.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
 #include "src/kernel/actor/SimcallObserver.hpp"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/CpuImpl.hpp"
 #include "src/kernel/resource/DiskImpl.hpp"
 #include "src/mc/mc_replay.hpp"
@@ -118,7 +117,7 @@ void IoImpl::set_exception(actor::ActorImpl* issuer)
 {
   switch (get_state()) {
     case State::FAILED:
-      issuer->context_->set_wannadie();
+      issuer->set_wannadie();
       static_cast<s4u::Io*>(get_iface())->complete(s4u::Activity::State::FAILED);
       issuer->exception_ = std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
       break;
index c9f5802..ea5e660 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "src/kernel/activity/Synchro.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/resource/CpuImpl.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_synchro, kernel,
@@ -66,7 +65,7 @@ void SynchroImpl::post()
 void SynchroImpl::set_exception(actor::ActorImpl* issuer)
 {
   if (get_state() == State::FAILED) {
-    issuer->context_->set_wannadie();
+    issuer->set_wannadie();
     issuer->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed"));
   } else {
     xbt_assert(get_state() == State::SRC_TIMEOUT, "Internal error in SynchroImpl::finish() unexpected synchro state %s",
index f62d97c..8acb38f 100644 (file)
@@ -166,11 +166,11 @@ void ActorImpl::cleanup_from_kernel()
 void ActorImpl::cleanup_from_self()
 {
   xbt_assert(not ActorImpl::is_maestro(), "Cleanup_from_self called from maestro on '%s'", get_cname());
-  context_->set_to_be_freed();
+  set_to_be_freed();
 
   if (on_exit) {
     // Execute the termination callbacks
-    bool failed = context_->wannadie();
+    bool failed = wannadie();
     for (auto exit_fun = on_exit->crbegin(); exit_fun != on_exit->crend(); ++exit_fun)
       (*exit_fun)(failed);
     on_exit.reset();
@@ -193,14 +193,14 @@ void ActorImpl::cleanup_from_self()
     simcall_.timeout_cb_ = nullptr;
   }
 
-  context_->set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+  set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
   actor::simcall_answered([this] { s4u::Actor::on_termination(*get_ciface()); });
-  context_->set_wannadie();
+  set_wannadie();
 }
 
 void ActorImpl::exit()
 {
-  context_->set_wannadie();
+  set_wannadie();
   suspended_ = false;
   exception_ = nullptr;
 
@@ -225,7 +225,7 @@ void ActorImpl::exit()
 void ActorImpl::kill(ActorImpl* actor) const
 {
   xbt_assert(not actor->is_maestro(), "Killing maestro is a rather bad idea.");
-  if (actor->context_->wannadie()) {
+  if (actor->wannadie()) {
     XBT_DEBUG("Ignoring request to kill actor %s@%s that is already dead", actor->get_cname(),
               actor->host_->get_cname());
     return;
@@ -275,7 +275,7 @@ void ActorImpl::yield()
   /* Ok, maestro returned control to us */
   XBT_DEBUG("Control returned to me: '%s'", get_cname());
 
-  if (context_->wannadie()) {
+  if (wannadie()) {
     XBT_DEBUG("Actor %s@%s is dead", get_cname(), host_->get_cname());
     context_->stop();
     THROW_IMPOSSIBLE;
@@ -298,7 +298,7 @@ void ActorImpl::yield()
     }
   }
 #if HAVE_SMPI
-  if (not context_->wannadie())
+  if (not wannadie())
     smpi_switch_data_segment(get_iface());
 #endif
 }
@@ -354,7 +354,7 @@ void ActorImpl::resume()
 {
   XBT_IN("actor = %p", this);
 
-  if (context_->wannadie()) {
+  if (wannadie()) {
     XBT_VERB("Ignoring request to resume an actor that is currently dying.");
     return;
   }
@@ -375,7 +375,7 @@ void ActorImpl::resume()
 activity::ActivityImplPtr ActorImpl::join(const ActorImpl* actor, double timeout)
 {
   activity::ActivityImplPtr sleep = this->sleep(timeout);
-  if (actor->context_->wannadie() || actor->context_->to_be_freed()) {
+  if (actor->wannadie() || actor->to_be_freed()) {
     if (sleep->surf_action_)
       sleep->surf_action_->finish(resource::Action::State::FINISHED);
   } else {
@@ -506,6 +506,11 @@ ActorImplPtr ActorImpl::create(ProcessArg* args)
     actor->daemonize();
   return actor;
 }
+void ActorImpl::set_wannadie(bool value)
+{
+  XBT_DEBUG("Actor %s gonna die.", get_cname());
+  iwannadie_ = value;
+}
 
 void create_maestro(const std::function<void()>& code)
 {
index 0dc8751..c4310e0 100644 (file)
@@ -40,6 +40,8 @@ class XBT_PUBLIC ActorImpl : public xbt::PropertyHolder, public ActorRestartingT
   aid_t ppid_        = -1;
   bool daemon_       = false; /* Daemon actors are automatically killed when the last non-daemon leaves */
   unsigned stacksize_; // set to default value in constructor
+  bool iwannadie_   = false; // True if we need to do some cleanups in actor mode.
+  bool to_be_freed_ = false; // True if cleanups in actor mode done, but cleanups in kernel mode pending
 
   std::vector<activity::MailboxImpl*> mailboxes_;
   friend activity::MailboxImpl;
@@ -63,6 +65,12 @@ public:
   const xbt::string& get_name() const { return name_; }
   const char* get_cname() const { return name_.c_str(); }
 
+  // Life-cycle
+  bool wannadie() const { return iwannadie_; }
+  void set_wannadie(bool value = true);
+  bool to_be_freed() const { return to_be_freed_; }
+  void set_to_be_freed() { to_be_freed_ = true; }
+
   // Accessors to private fields
   s4u::Host* get_host() const { return host_; }
   void set_host(s4u::Host* dest);
index 4fa6c44..b379c9f 100644 (file)
@@ -25,7 +25,7 @@ void ActorImpl::simcall_handle(int times_considered)
   XBT_DEBUG("Handling simcall %p: %s", &simcall_, simcall_.get_cname());
   if (simcall_.observer_ != nullptr)
     simcall_.observer_->prepare(times_considered);
-  if (context_->wannadie())
+  if (wannadie())
     return;
 
   xbt_assert(simcall_.call_ != Simcall::Type::NONE, "Asked to do the noop syscall on %s@%s", get_cname(),
index 40ded32..c6728df 100644 (file)
@@ -142,12 +142,6 @@ void Context::stop()
   this->actor_->cleanup_from_self();
   throw ForcefulKillException(); // clean RAII variables with the dedicated exception
 }
-
-void Context::set_wannadie(bool value)
-{
-  XBT_DEBUG("Actor %s gonna die.", actor_->get_cname());
-  iwannadie_ = value;
-}
 AttachContext::~AttachContext() = default;
 
 } // namespace context
index 473af7a..f7dc07d 100644 (file)
@@ -51,8 +51,6 @@ class XBT_PUBLIC Context {
 
   std::function<void()> code_;
   actor::ActorImpl* actor_ = nullptr;
-  bool iwannadie_          = false; // True if we need to do some cleanups in actor mode.
-  bool to_be_freed_        = false; // True if cleanups in actor mode done, but cleanups in kernel mode pending
   bool is_maestro_;
   void declare_context(std::size_t size);
 
@@ -66,10 +64,6 @@ public:
   Context& operator=(const Context&) = delete;
   virtual ~Context();
 
-  bool wannadie() const { return iwannadie_; }
-  void set_wannadie(bool value = true);
-  bool to_be_freed() const { return to_be_freed_; }
-  void set_to_be_freed() { to_be_freed_ = true; }
   bool is_maestro() const { return is_maestro_; }
   void operator()() const { code_(); }
   bool has_code() const { return static_cast<bool>(code_); }
index 7528443..5a877c4 100644 (file)
@@ -22,7 +22,6 @@
 #include <xbt/parmap.hpp>
 
 #include "src/internal_config.h"
-#include "src/kernel/context/Context.hpp"
 #include "src/kernel/context/ContextSwapped.hpp"
 
 namespace simgrid {
index 6e566b3..ee371dc 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "src/mc/mc_record.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
-#include "src/kernel/context/Context.hpp"
 #include "src/mc/mc_base.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/mc/transition/Transition.hpp"
index def1862..27b2dca 100644 (file)
@@ -14,7 +14,6 @@
 #include "src/include/mc/mc.h"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
-#include "src/kernel/context/Context.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/surf/HostImpl.hpp"
 
@@ -112,7 +111,7 @@ void Actor::join(double timeout) const
   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
   const kernel::actor::ActorImpl* target = pimpl_;
   kernel::actor::simcall_blocking([issuer, target, timeout] {
-    if (target->context_->wannadie()) {
+    if (target->wannadie()) {
       // The joined actor is already finished, just wake up the issuer right away
       issuer->simcall_answer();
     } else {
index 6d6cc5f..bcc183b 100644 (file)
@@ -4,7 +4,6 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/Exception.hpp"
-#include "src/kernel/context/Context.hpp"
 #include <xbt/config.hpp>
 #include <xbt/log.hpp>