Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the API between Engine and EngineImpl when registering functions
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index fdf73a3..c695f42 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -60,13 +60,8 @@ ActorImpl::ActorImpl(xbt::string name, s4u::Host* host) : host_(host), name_(std
 
 ActorImpl::~ActorImpl()
 {
-  if (simix_global != nullptr && this != simix_global->maestro_) {
-    if (context_.get() != nullptr) /* the actor was not start()ed yet. This happens if its host was initially off */
-      context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
-    actor::simcall([this] { s4u::Actor::on_destruction(*ciface()); });
-    if (context_.get() != nullptr)
-      context_->iwannadie = true;
-  }
+  if (simix_global != nullptr && this != simix_global->maestro_)
+    s4u::Actor::on_destruction(*ciface());
 }
 
 /* Become an actor in the simulation
@@ -162,7 +157,7 @@ void ActorImpl::cleanup()
 
   if (on_exit) {
     // Execute the termination callbacks
-    bool failed = context_->iwannadie;
+    bool failed = context_->wannadie();
     for (auto exit_fun = on_exit->crbegin(); exit_fun != on_exit->crend(); ++exit_fun)
       (*exit_fun)(failed);
     on_exit.reset();
@@ -188,14 +183,14 @@ void ActorImpl::cleanup()
   }
   cleanup_from_simix();
 
-  context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+  context_->set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
   actor::simcall([this] { s4u::Actor::on_termination(*ciface()); });
-  context_->iwannadie = true;
+  context_->set_wannadie();
 }
 
 void ActorImpl::exit()
 {
-  context_->iwannadie = true;
+  context_->set_wannadie();
   suspended_          = false;
   exception_          = nullptr;
 
@@ -281,7 +276,7 @@ void ActorImpl::yield()
   /* Ok, maestro returned control to us */
   XBT_DEBUG("Control returned to me: '%s'", get_cname());
 
-  if (context_->iwannadie) {
+  if (context_->wannadie()) {
     XBT_DEBUG("Actor %s@%s is dead", get_cname(), host_->get_cname());
     context_->stop();
     THROW_IMPOSSIBLE;
@@ -376,7 +371,7 @@ void ActorImpl::resume()
 {
   XBT_IN("actor = %p", this);
 
-  if (context_->iwannadie) {
+  if (context_->wannadie()) {
     XBT_VERB("Ignoring request to suspend an actor that is currently dying.");
     return;
   }
@@ -466,7 +461,7 @@ ActorImplPtr ActorImpl::init(const std::string& name, s4u::Host* host)
   return ActorImplPtr(actor);
 }
 
-ActorImpl* ActorImpl::start(const simix::ActorCode& code)
+ActorImpl* ActorImpl::start(const ActorCode& code)
 {
   xbt_assert(code && host_ != nullptr, "Invalid parameters");
 
@@ -478,7 +473,7 @@ ActorImpl* ActorImpl::start(const simix::ActorCode& code)
 
   this->code_ = code;
   XBT_VERB("Create context %s", get_cname());
-  context_.reset(simix_global->context_factory->create_context(simix::ActorCode(code), this));
+  context_.reset(simix_global->context_factory->create_context(ActorCode(code), this));
 
   XBT_DEBUG("Start context '%s'", get_cname());
 
@@ -493,7 +488,7 @@ ActorImpl* ActorImpl::start(const simix::ActorCode& code)
   return this;
 }
 
-ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
+ActorImplPtr ActorImpl::create(const std::string& name, const ActorCode& code, void* data, s4u::Host* host,
                                const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
 {
   XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
@@ -522,9 +517,9 @@ void create_maestro(const std::function<void()>& code)
   ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
 
   if (not code) {
-    maestro->context_.reset(simix_global->context_factory->create_context(simix::ActorCode(), maestro));
+    maestro->context_.reset(simix_global->context_factory->create_context(ActorCode(), maestro));
   } else {
-    maestro->context_.reset(simix_global->context_factory->create_maestro(simix::ActorCode(code), maestro));
+    maestro->context_.reset(simix_global->context_factory->create_maestro(ActorCode(code), maestro));
   }
 
   maestro->simcall.issuer_      = maestro;
@@ -607,7 +602,7 @@ void SIMIX_process_on_exit(smx_actor_t actor,
  * @param host where the new agent is executed.
  * @param properties the properties of the process
  */
-smx_actor_t simcall_process_create(const std::string& name, const simgrid::simix::ActorCode& code, void* data,
+smx_actor_t simcall_process_create(const std::string& name, const simgrid::kernel::actor::ActorCode& code, void* data,
                                    sg_host_t host, std::unordered_map<std::string, std::string>* properties)
 {
   smx_actor_t self = simgrid::kernel::actor::ActorImpl::self();