Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::fill instead of memset.
[simgrid.git] / src / s4u / s4u_Actor.cpp
index ce00aaf..8c0fc2e 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"
 
@@ -109,10 +108,13 @@ void Actor::join() const
 
 void Actor::join(double timeout) const
 {
+  xbt_assert(not(MC_is_active() || MC_record_replay_is_active()),
+             "Actor::join() is not usable in MC yet. Please report this bug.");
+
   kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
   const kernel::actor::ActorImpl* target = pimpl_;
   kernel::actor::simcall_blocking([issuer, target, timeout] {
-    if (target->finished_) {
+    if (target->wannadie()) {
       // The joined actor is already finished, just wake up the issuer right away
       issuer->simcall_answer();
     } else {
@@ -124,8 +126,11 @@ void Actor::join(double timeout) const
 
 Actor* Actor::set_auto_restart(bool autorestart)
 {
+  if (autorestart == pimpl_->has_to_auto_restart()) // not changed
+    return this;
+
   kernel::actor::simcall_answered([this, autorestart]() {
-    xbt_assert(autorestart && not pimpl_->has_to_auto_restart()); // FIXME: handle all cases
+    xbt_assert(autorestart, "Asking an actor to stop being autorestart is not implemented yet. Ask us if you need it.");
     pimpl_->set_auto_restart(autorestart);
 
     auto* arg = new kernel::actor::ProcessArg(pimpl_->get_host(), pimpl_);
@@ -134,6 +139,10 @@ Actor* Actor::set_auto_restart(bool autorestart)
   });
   return this;
 }
+int Actor::get_restart_count() const
+{
+  return pimpl_->get_restart_count();
+}
 
 void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun) const
 {
@@ -244,7 +253,7 @@ void Actor::kill()
 
 ActorPtr Actor::by_pid(aid_t pid)
 {
-  kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(pid);
+  kernel::actor::ActorImpl* actor = kernel::EngineImpl::get_instance()->get_actor_by_pid(pid);
   if (actor != nullptr)
     return actor->get_iface();
   else
@@ -362,6 +371,7 @@ void thread_execute(s4u::Host* host, double flops_amount, int thread_count)
 {
   Exec::init()->set_flops_amount(flops_amount)->set_host(host)->set_thread_count(thread_count)->wait();
 }
+
 ExecPtr exec_init(double flops_amount)
 {
   return Exec::init()->set_flops_amount(flops_amount)->set_host(get_host());
@@ -578,8 +588,8 @@ xbt_dict_t sg_actor_get_properties(const_sg_actor_t actor)
   const std::unordered_map<std::string, std::string>* props = actor->get_properties();
   if (props == nullptr)
     return nullptr;
-  for (auto const& kv : *props) {
-    xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()));
+  for (auto const& [key, value] : *props) {
+    xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str()));
   }
   return as_dict;
 }
@@ -713,7 +723,7 @@ sg_actor_t sg_actor_attach(const char* name, void* data, sg_host_t host, xbt_dic
   xbt_dict_free(&properties);
 
   /* Let's create the actor: SIMIX may decide to start it right now, even before returning the flow control to us */
-  smx_actor_t actor = nullptr;
+  simgrid::kernel::actor::ActorImpl* actor = nullptr;
   try {
     actor = simgrid::kernel::actor::ActorImpl::attach(name, data, host).get();
     actor->set_properties(props);