Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[S4U] Add onCreation signal to the actor API
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 11 Jan 2018 15:19:07 +0000 (16:19 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 12 Jan 2018 11:56:26 +0000 (12:56 +0100)
ChangeLog
include/simgrid/s4u/Actor.hpp
src/simix/ActorImpl.cpp

index 8768cc3..d6c6d18 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ SimGrid (3.19) NOT RELEASED YET (target: March 20 2018, 16:15:27 UTC)
  S4U
  - Execution->setHost() can be called after start() to migrate it.
  - Comm::test_any() is now implemented.
+ - s4u::Actor now has an onCreation() signal.
 
  XBT
  - Remove XBT_LOG_CONNECT, it should be useless nowadays.
index 8f332c8..670f502 100644 (file)
@@ -19,6 +19,7 @@
 #include <xbt/Extendable.hpp>
 #include <xbt/functional.hpp>
 #include <xbt/string.hpp>
+#include <xbt/signal.hpp>
 
 #include <simgrid/chrono.hpp>
 #include <simgrid/s4u/forward.hpp>
@@ -162,6 +163,9 @@ public:
   /** Retrieve a reference to myself */
   static ActorPtr self();
 
+  /** Signal to others that a new actor has been created **/
+  static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> onCreation;
+
   /** Create an actor using a function
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
index 7866fb0..fcc6dac 100644 (file)
@@ -145,6 +145,10 @@ void SIMIX_process_empty_trash()
 }
 
 namespace simgrid {
+
+namespace s4u {
+simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> s4u::Actor::onCreation; // TODO cheinrich is this the right location here?
+}
 namespace simix {
 
 ActorImpl::~ActorImpl()
@@ -310,6 +314,8 @@ smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, v
   }
 
   smx_actor_t process = new simgrid::simix::ActorImpl();
+  simgrid::s4u::ActorPtr tmp = process->iface(); // Passing this directly to onCreation will lead to crashes
+  simgrid::s4u::Actor::onCreation(tmp);
 
   xbt_assert(code && host != nullptr, "Invalid parameters");
   /* Process data */