Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s4u::Actor: Merge signals on_migration_start/end into on_host_change
[simgrid.git] / src / s4u / s4u_Actor.cpp
index 154d5fbf7816d2b2715f78491f01ec8289c6b6f4..7a5047213755e42ff9484ef1afde3c1c26741a5c 100644 (file)
 #include "src/include/mc/mc.h"
 #include "src/kernel/activity/ExecImpl.hpp"
 #include "src/mc/mc_replay.hpp"
-#include "src/simix/smx_private.hpp"
 #include "src/surf/HostImpl.hpp"
 
 #include <algorithm>
 #include <sstream>
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor, "S4U actors");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_actor, s4u, "S4U actors");
 
 namespace simgrid {
 namespace s4u {
@@ -29,8 +28,9 @@ xbt::signal<void(Actor const&)> s4u::Actor::on_suspend;
 xbt::signal<void(Actor const&)> s4u::Actor::on_resume;
 xbt::signal<void(Actor const&)> s4u::Actor::on_sleep;
 xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
-xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start;
-xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;
+xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start; // deprecated
+xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;   // deprecated
+xbt::signal<void(Actor const&, Host const& previous_location)> s4u::Actor::on_host_change;
 xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
 xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
 
@@ -128,7 +128,17 @@ void Actor::on_exit(const std::function<void(bool /*failed*/)>& fun) const
 
 void Actor::migrate(Host* new_host)
 {
-  s4u::Actor::on_migration_start(*this);
+  if (s4u::Actor::on_migration_start.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
+    static bool already_warned = false;
+    if (not already_warned) {
+      XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_start. This will be removed "
+               "in v3.29");
+      already_warned = true;
+    }
+    s4u::Actor::on_migration_start(*this);
+  }
+
+  auto* previous_location = get_host();
 
   kernel::actor::simcall([this, new_host]() {
     if (pimpl_->waiting_synchro != nullptr) {
@@ -142,7 +152,17 @@ void Actor::migrate(Host* new_host)
     this->pimpl_->set_host(new_host);
   });
 
-  s4u::Actor::on_migration_end(*this);
+  if (s4u::Actor::on_migration_end.get_slot_count() > 0) { // XBT_ATTRIB_DEPRECATED_v329
+    static bool already_warned = false;
+    if (not already_warned) {
+      XBT_INFO("Please use s4u::Actor::on_host_change instead of s4u::Actor::on_migration_end. This will be removed in "
+               "v3.29");
+      already_warned = true;
+    }
+    s4u::Actor::on_migration_end(*this);
+  }
+
+  s4u::Actor::on_host_change(*this, *previous_location);
 }
 
 s4u::Host* Actor::get_host() const
@@ -219,10 +239,7 @@ double Actor::get_kill_time()
 void Actor::kill()
 {
   kernel::actor::ActorImpl* self = SIMIX_process_self();
-  kernel::actor::simcall([this, self] {
-    xbt_assert(pimpl_ != simix_global->maestro_process, "Killing maestro is a rather bad idea");
-    self->kill(pimpl_);
-  });
+  kernel::actor::simcall([this, self] { self->kill(pimpl_); });
 }
 
 // ***** Static functions *****
@@ -278,8 +295,7 @@ namespace this_actor {
  */
 bool is_maestro()
 {
-  kernel::actor::ActorImpl* self = SIMIX_process_self();
-  return self == nullptr || self == simix_global->maestro_process;
+  return SIMIX_is_maestro();
 }
 
 void sleep_for(double duration)
@@ -690,6 +706,16 @@ const char* sg_actor_self_get_name()
   return simgrid::s4u::this_actor::get_cname();
 }
 
+void* sg_actor_self_data()
+{
+  return simgrid::s4u::Actor::self()->get_data();
+}
+
+void sg_actor_self_data_set(void* userdata)
+{
+  simgrid::s4u::Actor::self()->set_data(userdata);
+}
+
 sg_actor_t sg_actor_self()
 {
   return simgrid::s4u::Actor::self();
@@ -712,7 +738,7 @@ void sg_actor_unref(sg_actor_t actor)
 }
 
 /** @brief Return the user data of a #sg_actor_t */
-void* sg_actor_data(sg_actor_t actor)
+void* sg_actor_data(const_sg_actor_t actor)
 {
   return actor->get_data();
 }