Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rewrite the s4u_launching example
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Aug 2016 20:53:41 +0000 (22:53 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 12 Aug 2016 20:53:41 +0000 (22:53 +0200)
15 files changed:
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/launching/.gitignore
examples/s4u/launching/deployment.xml
examples/s4u/launching/s4u_launching.cpp
examples/s4u/launching/s4u_launching.h [deleted file]
examples/s4u/launching/s4u_launching.tesh
examples/s4u/launching/s4u_launching_deployment.cpp [deleted file]
examples/s4u/launching/s4u_launching_function.cpp [deleted file]
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/comm.hpp
include/simgrid/s4u/forward.hpp
include/simgrid/s4u/mailbox.hpp
src/s4u/s4u_actor.cpp
src/s4u/s4u_comm.cpp

index 1edddbe..f484128 100644 (file)
@@ -7,20 +7,6 @@ foreach (example io launching mutex actions-comm)
   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u_${example}.cpp)
 endforeach()
 
   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u_${example}.cpp)
 endforeach()
 
-add_executable       (s4u_launching_function  launching/s4u_launching_function.cpp)
-target_link_libraries(s4u_launching_function  simgrid)
-set_target_properties(s4u_launching_function  PROPERTIES RUNTIME_OUTPUT_DIRECTORY
- ${CMAKE_CURRENT_BINARY_DIR}/launching)
-
-add_executable       (s4u_launching_deployment  launching/s4u_launching_deployment.cpp)
-target_link_libraries(s4u_launching_deployment  simgrid)
-set_target_properties(s4u_launching_deployment  PROPERTIES RUNTIME_OUTPUT_DIRECTORY
- ${CMAKE_CURRENT_BINARY_DIR}/launching)
-
-set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/launching/s4u_launching_function.cpp
-                                   ${CMAKE_CURRENT_SOURCE_DIR}/launching/s4u_launching_deployment.cpp
-                                   ${CMAKE_CURRENT_SOURCE_DIR}/launching/s4u_launching.h)
-
 set(examples_src  ${examples_src}                                     PARENT_SCOPE)
 set(tesh_files    ${tesh_files}                                       PARENT_SCOPE)
 set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/launching/deployment.xml
 set(examples_src  ${examples_src}                                     PARENT_SCOPE)
 set(tesh_files    ${tesh_files}                                       PARENT_SCOPE)
 set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/launching/deployment.xml
index e08626c..f80cb81 100644 (file)
@@ -13,20 +13,27 @@ documentation, but it should remain readable directly.
  @ingroup s4u_api
  @brief Find the S4U example fitting your needs in the archive.
 
  @ingroup s4u_api
  @brief Find the S4U example fitting your needs in the archive.
 
-  - @ref s4u_ex_launching
+  - @ref s4u_ex_basics
   - @ref s4u_ex_synchro
                    
   - @ref s4u_ex_synchro
                    
-@section s4u_ex_launching Launching actors to populate your simulation
+@section s4u_ex_basics Basics of SimGrid simulation
+
+  - <b>Launching actors</b>
+    Shows how to start your actors to populate your simulation\n
+    @ref examples/s4u/launching/s4u_launching.cpp and @ref examples/s4u/launching/deployment.xml
 
 @section s4u_ex_synchro Inter-Actor Synchronization 
 
 
 @section s4u_ex_synchro Inter-Actor Synchronization 
 
- - <b>Mutex</b>.
-   @ref examples/s4u/mutex/s4u_mutex.cpp\n
-   Shows how to use simgrid::s4u::Mutex synchronization objects
+ - <b>Mutex.</b>
+   Shows how to use simgrid::s4u::Mutex synchronization objects\n
+   @ref examples/s4u/mutex/s4u_mutex.cpp
                         
 */
 
 /**
                         
 */
 
 /**
+@example examples/s4u/launching/s4u_launching.cpp
+@example examples/s4u/launching/deployment.xml
+
 @example examples/s4u/mutex/s4u_mutex.cpp
 
 */
\ No newline at end of file
 @example examples/s4u/mutex/s4u_mutex.cpp
 
 */
\ No newline at end of file
index f110ab6..7cef20d 100644 (file)
@@ -1,3 +1 @@
 s4u_launching
 s4u_launching
-s4u_launching_deployment
-s4u_launching_function
index 4004253..2c69f21 100644 (file)
@@ -1,8 +1,15 @@
 <?xml version='1.0'?>
 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
 <platform version="4">
 <?xml version='1.0'?>
 <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
 <platform version="4">
-  <process host="Tremblay" function="worker">
-  </process>
-  <process host="Jupiter" function="master">
+
+  <!-- This a weird deployment file: we only start one actor from here and the others from the main().
+    --
+    -- This is only for the example, but don't do that at home.
+    -- Instead, you want to start all your actors from the deployment file.
+    -->
+   
+  <process host="Fafard" function="receiver">
+    <!-- Pass the right mailbox name to the actor -->
+    <argument value="mb42" />
   </process>
 </platform>
   </process>
 </platform>
index 85f512a..bad8098 100644 (file)
 /* 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. */
 
 /* 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. */
 
-#include <xbt/sysdep.h>
+
+/* This example shows how to declare and start your actors.
+ *
+ * The first step is to declare the code of your actors (what they do exactly
+ * does not matter to this example) and then you ask SimGrid to start your
+ * actors. There is three ways of doing so:
+ *  - Directly, by instantiating your actor as paramter to Actor::create();
+ *  - By first registering your actors before instantiating it;
+ *  - Through the deployment file.
+ *
+ * This example shows all these solutions, even if you obviously should use
+ * only one of these solutions to start your actors. The most advised solution
+ * is to use a deployment file, as it creates a clear separation between your
+ * application and the settings to test it. This is a better scientific
+ * methodology. Actually, starting an actor with Actor::create() is mostly
+ * useful to start an actor from another actor.
+ *
+ */
+
 #include <simgrid/s4u.hpp>
 
 #include <simgrid/s4u.hpp>
 
-#include "s4u_launching.h"
+// This declares a logging channel so that XBT_INFO can be used later
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_launching_test, "The logging channel used in this example");
+
+
+/* Declares a first class of actors which sends a message to the mailbox 'mb42'.
+ * The sent message is what was passed as parameter on creation (or 'GaBuZoMeu' by default)
+ *
+ * Later, this actor class is instantiated twice in the simulation.
+ */
+class Sender {
+public:
+  const char *msg = "GaBuZoMeu";
+  Sender() {
+    /* Constructor used when no parameter is passed to the actor */
+  };
+  Sender(std::vector<std::string> args) {
+    /* This constructor is used when we pass parameters to the actor */
+    if (args.size() > 0)
+      msg = args[0].c_str();
+  }
+  void operator()() {
+    XBT_INFO("Hello s4u, I have something to send");
+    simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mb42");
+
+    simgrid::s4u::this_actor::send(mailbox, xbt_strdup(msg), strlen(msg));
+    XBT_INFO("I'm done. See you.");
+  }
+};
+
+
+/* Declares a second class of actor which receive two messages on the mailbox which
+ * name is passed as parameter ('thingy' by default, ie the wrong one).
+ *
+ * Later, this actor class is instantiated once in the simulation.
+ */
+class Receiver {
+public:
+  simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("thingy");
+
+  Receiver() {};
+  Receiver(std::vector<std::string> args) {
+    /* This constructor is used when we pass parameters to the actor */
+    /* as with argc/argv, args[0] is the actor's name, so the first parameter is args[1] */
+    if (args.size() > 1)
+      mailbox = simgrid::s4u::Mailbox::byName(args[1].c_str());
+  }
+  void operator()() {
+    XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getName());
+
+    char *msg1 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+    char *msg2 = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+    XBT_INFO("I received '%s' and '%s'",msg1,msg2);
+    XBT_INFO("I'm done. See you.");
+  }
+};
 
 
+
+/* Here comes the main function of your program */
 int main(int argc, char **argv) {
 int main(int argc, char **argv) {
+  /* When your program starts, you have to first start a new simulation engine, as follows */
   simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
   simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
-  e->loadPlatform("../../platforms/two_hosts.xml");
-  simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), Worker());
-  simgrid::s4u::Actor::createActor("master", simgrid::s4u::Host::by_name("Jupiter"), Master());
+
+  /* Then you should load a platform file, describing your simulated platform */
+  e->loadPlatform("../../platforms/small_platform.xml");
+
+  /* And now you have to ask SimGrid to actually start your actors.
+   *
+   * You can first directly start your actor, as follows. Note the last parameter: 'Sender()',
+   * as if you would call the Sender function.
+   */
+  simgrid::s4u::Actor::createActor("sender1", simgrid::s4u::Host::by_name("Tremblay"), Sender());
+
+  /* The second way is to first register your function, and then retrieve it */
+  e->registerFunction<Sender>("sender"); // The sender is passed as a template parameter here
+  std::vector<std::string> args;  // Here we declare the parameter that the actor will get
+  args.push_back("GloubiBoulga"); // Add a parameter to the set (we could have done it in the first approach too)
+
+  simgrid::s4u::Actor::createActor("sender2", simgrid::s4u::Host::by_name("Jupiter"), "sender", args);
+
+  /* The third way to start your actors is to use a deployment file. */
+  e->registerFunction<Receiver>("receiver"); // You first have to register the actor as with the second approach
+  e->loadDeployment("deployment.xml");       // And then, you load the deployment file
+
+  /* Once every actors are started in the engine, the simulation can start */
   e->run();
   e->run();
+
+  /* Once the simulation is done, the program is ended */
   return 0;
 }
   return 0;
 }
diff --git a/examples/s4u/launching/s4u_launching.h b/examples/s4u/launching/s4u_launching.h
deleted file mode 100644 (file)
index 1cfdc83..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (c) 2006-2016. 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. */
-
-#include <xbt/sysdep.h>
-
-#include <simgrid/s4u.hpp>
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
-
-class Worker {
-public:
-  Worker() {};
-  Worker(std::vector<std::string> args) {}
-  void operator()() {
-    XBT_INFO("Hello s4u, I'm ready to serve");
-    char *msg = static_cast<char*>(simgrid::s4u::this_actor::recv(
-      *simgrid::s4u::Mailbox::byName("worker")));
-    XBT_INFO("I received '%s'",msg);
-    XBT_INFO("I'm done. See you.");
-  }
-};
-
-class Master {
-public:
-  Master() {};
-  Master(std::vector<std::string> args) {}
-  void operator()() {
-    const char *msg = "GaBuZoMeu";
-    XBT_INFO("Hello s4u, I have something to send");
-    simgrid::s4u::this_actor::send(*simgrid::s4u::Mailbox::byName("worker"), xbt_strdup(msg), strlen(msg));
-    XBT_INFO("I'm done. See you.");
-  }
-};
index 214dbea..6817721 100644 (file)
@@ -1,22 +1,10 @@
 #! ./tesh
 
 $ $SG_TEST_EXENV ${bindir:=.}/s4u_launching
 #! ./tesh
 
 $ $SG_TEST_EXENV ${bindir:=.}/s4u_launching
-> [Tremblay:worker:(0) 0.000000] [s4u_test/INFO] Hello s4u, I'm ready to serve
-> [Jupiter:master:(0) 0.000000] [s4u_test/INFO] Hello s4u, I have something to send
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I received 'GaBuZoMeu'
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
-> [Jupiter:master:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
-
-$ $SG_TEST_EXENV ${bindir:=.}/s4u_launching_function
-> [Tremblay:worker:(0) 0.000000] [s4u_test/INFO] Hello s4u, I'm ready to serve
-> [Jupiter:master:(0) 0.000000] [s4u_test/INFO] Hello s4u, I have something to send
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I received 'GaBuZoMeu'
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
-> [Jupiter:master:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
-
-$ $SG_TEST_EXENV ${bindir:=.}/s4u_launching_deployment deployment.xml
-> [Tremblay:worker:(0) 0.000000] [s4u_test/INFO] Hello s4u, I'm ready to serve
-> [Jupiter:master:(0) 0.000000] [s4u_test/INFO] Hello s4u, I have something to send
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I received 'GaBuZoMeu'
-> [Tremblay:worker:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
-> [Jupiter:master:(0) 0.001301] [s4u_test/INFO] I'm done. See you.
+> [Tremblay:sender1:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send
+> [Jupiter:sender2:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I have something to send
+> [Fafard:receiver:(0) 0.000000] [s4u_launching_test/INFO] Hello s4u, I'm ready to get any message you'd want on mb42
+> [Tremblay:sender1:(0) 0.025709] [s4u_launching_test/INFO] I'm done. See you.
+> [Jupiter:sender2:(0) 0.070434] [s4u_launching_test/INFO] I'm done. See you.
+> [Fafard:receiver:(0) 0.070434] [s4u_launching_test/INFO] I received 'GaBuZoMeu' and 'GloubiBoulga'
+> [Fafard:receiver:(0) 0.070434] [s4u_launching_test/INFO] I'm done. See you.
diff --git a/examples/s4u/launching/s4u_launching_deployment.cpp b/examples/s4u/launching/s4u_launching_deployment.cpp
deleted file mode 100644 (file)
index 115cf4a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Copyright (c) 2006-2016. 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. */
-
-#include <string>
-#include <vector>
-
-#include <xbt/sysdep.h>
-#include <simgrid/s4u.hpp>
-
-#include "s4u_launching.h"
-
-int main(int argc, char **argv) {
-  simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
-  e->loadPlatform("../../platforms/two_hosts.xml");
-  e->registerFunction<Worker>("worker");
-  e->registerFunction<Master>("master");
-  e->loadDeployment(argv[1]);
-  e->run();
-  return 0;
-}
diff --git a/examples/s4u/launching/s4u_launching_function.cpp b/examples/s4u/launching/s4u_launching_function.cpp
deleted file mode 100644 (file)
index 713aa96..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright (c) 2006-2016. 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. */
-
-#include <string>
-#include <vector>
-
-#include <xbt/sysdep.h>
-
-#include <simgrid/s4u.hpp>
-
-#include "s4u_launching.h"
-
-int main(int argc, char **argv) {
-  simgrid::s4u::Engine *e = new simgrid::s4u::Engine(&argc,argv);
-  e->loadPlatform("../../platforms/two_hosts.xml");
-  e->registerFunction<Worker>("worker");
-  e->registerFunction<Master>("master");
-  std::vector<std::string> args;
-  simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), "worker", args);
-  simgrid::s4u::Actor::createActor("master", simgrid::s4u::Host::by_name("Jupiter"), "master", args);
-  e->run();
-  return 0;
-}
index a858bdf..89ea5f4 100644 (file)
@@ -25,6 +25,7 @@
 #include <simgrid/chrono.hpp>
 #include <simgrid/simix.h>
 #include <simgrid/s4u/forward.hpp>
 #include <simgrid/chrono.hpp>
 #include <simgrid/simix.h>
 #include <simgrid/s4u/forward.hpp>
+#include <simgrid/s4u/mailbox.hpp>
 
 namespace simgrid {
 namespace s4u {
 
 namespace simgrid {
 namespace s4u {
@@ -168,19 +169,18 @@ public:
     xbt_assert(actor != nullptr);
     SIMIX_process_unref(actor->pimpl_);
   }
     xbt_assert(actor != nullptr);
     SIMIX_process_unref(actor->pimpl_);
   }
-  using Ptr = boost::intrusive_ptr<Actor>;
 
   // ***** Actor creation *****
   /** Retrieve a reference to myself */
 
   // ***** Actor creation *****
   /** Retrieve a reference to myself */
-  static Ptr self();
+  static ActorPtr self();
 
   /** Create an actor using a function
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
    */
 
   /** Create an actor using a function
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
    */
-  static Ptr createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code);
+  static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code);
 
 
-  static Ptr createActor(const char* name, s4u::Host *host, std::function<void()> code)
+  static ActorPtr createActor(const char* name, s4u::Host *host, std::function<void()> code)
   {
     return createActor(name, host, -1.0, std::move(code));
   }
   {
     return createActor(name, host, -1.0, std::move(code));
   }
@@ -196,17 +196,17 @@ public:
     // This constructor is enabled only if the call code(args...) is valid:
     typename = typename std::result_of<F(Args...)>::type
     >
     // This constructor is enabled only if the call code(args...) is valid:
     typename = typename std::result_of<F(Args...)>::type
     >
-  static Ptr createActor(const char* name, s4u::Host *host, F code, Args... args)
+  static ActorPtr createActor(const char* name, s4u::Host *host, F code, Args... args)
   {
     return createActor(name, host, wrap_task(std::move(code), std::move(args)...));
   }
 
   // Create actor from function name:
 
   {
     return createActor(name, host, wrap_task(std::move(code), std::move(args)...));
   }
 
   // Create actor from function name:
 
-  static Ptr createActor(const char* name, s4u::Host *host, double killTime,
+  static ActorPtr createActor(const char* name, s4u::Host *host, double killTime,
     const char* function, std::vector<std::string> args);
 
     const char* function, std::vector<std::string> args);
 
-  static Ptr createActor(const char* name, s4u::Host *host, const char* function,
+  static ActorPtr createActor(const char* name, s4u::Host *host, const char* function,
       std::vector<std::string> args)
   {
     return createActor(name, host, -1.0, function, std::move(args));
       std::vector<std::string> args)
   {
     return createActor(name, host, -1.0, function, std::move(args));
@@ -242,7 +242,7 @@ public:
   void kill();
 
   static void kill(int pid);
   void kill();
 
   static void kill(int pid);
-  static Ptr forPid(int pid);
+  static ActorPtr forPid(int pid);
   
   /**
    * Wait for the actor to finish.
   
   /**
    * Wait for the actor to finish.
@@ -259,8 +259,6 @@ protected:
   smx_process_t getImpl();
 };
 
   smx_process_t getImpl();
 };
 
-using ActorPtr = Actor::Ptr;
-
 /** @ingroup s4u_api
  *  @brief Static methods working on the current actor (see @ref s4u::Actor) */
 namespace this_actor {
 /** @ingroup s4u_api
  *  @brief Static methods working on the current actor (see @ref s4u::Actor) */
 namespace this_actor {
@@ -295,13 +293,13 @@ namespace this_actor {
    *
    * See \ref Comm for the full communication API (including non blocking communications).
    */
    *
    * See \ref Comm for the full communication API (including non blocking communications).
    */
-  XBT_PUBLIC(void*) recv(Mailbox &chan);
+  XBT_PUBLIC(void*) recv(MailboxPtr chan);
 
   /** Block the actor until it delivers a message of the given simulated size to the given mailbox
    *
    * See \ref Comm for the full communication API (including non blocking communications).
   */
 
   /** Block the actor until it delivers a message of the given simulated size to the given mailbox
    *
    * See \ref Comm for the full communication API (including non blocking communications).
   */
-  XBT_PUBLIC(void) send(Mailbox &chan, void*payload, size_t simulatedSize);
+  XBT_PUBLIC(void) send(MailboxPtr chan, void*payload, size_t simulatedSize);
   
   /**
    * Return the PID of the current actor.
   
   /**
    * Return the PID of the current actor.
index 1083fbe..ff5ec42 100644 (file)
@@ -78,13 +78,13 @@ public:
     return res;
   }
   /** Creates (but don't start) an async send to the mailbox @p dest */
     return res;
   }
   /** Creates (but don't start) an async send to the mailbox @p dest */
-  static Comm &send_init(Mailbox &dest);
+  static Comm &send_init(MailboxPtr dest);
   /** Creates and start an async send to the mailbox @p dest */
   /** Creates and start an async send to the mailbox @p dest */
-  static Comm &send_async(Mailbox &dest, void *data, int simulatedByteAmount);
+  static Comm &send_async(MailboxPtr dest, void *data, int simulatedByteAmount);
     /** Creates (but don't start) an async recv onto the mailbox @p from */
     /** Creates (but don't start) an async recv onto the mailbox @p from */
-  static Comm &recv_init(Mailbox &from);
+  static Comm &recv_init(MailboxPtr from);
   /** Creates and start an async recv to the mailbox @p from */
   /** Creates and start an async recv to the mailbox @p from */
-  static Comm &recv_async(Mailbox &from, void **data);
+  static Comm &recv_async(MailboxPtr from, void **data);
 
   void start() override;
   void wait() override;
 
   void start() override;
   void wait() override;
@@ -125,7 +125,7 @@ private:
 
   smx_process_t sender_ = nullptr;
   smx_process_t receiver_ = nullptr;
 
   smx_process_t sender_ = nullptr;
   smx_process_t receiver_ = nullptr;
-  Mailbox *mailbox_ = nullptr;
+  MailboxPtr mailbox_ = nullptr;
 };
 
 }} // namespace simgrid::s4u
 };
 
 }} // namespace simgrid::s4u
index b8f6b42..5b864a8 100644 (file)
@@ -6,14 +6,21 @@
 #ifndef SIMGRID_S4U_FORWARD_HPP
 #define SIMGRID_S4U_FORWARD_HPP
 
 #ifndef SIMGRID_S4U_FORWARD_HPP
 #define SIMGRID_S4U_FORWARD_HPP
 
+#include <boost/intrusive_ptr.hpp>
+
 namespace simgrid {
 namespace s4u {
 
 namespace simgrid {
 namespace s4u {
 
+class Actor;
+using ActorPtr = boost::intrusive_ptr<Actor>;
+
 class Activity;
 class Comm;
 class Engine;
 class Host;
 class Mailbox;
 class Activity;
 class Comm;
 class Engine;
 class Host;
 class Mailbox;
+using MailboxPtr = boost::intrusive_ptr<Mailbox>;
+
 class Storage;
 
 }
 class Storage;
 
 }
index 99f65b4..6298ad3 100644 (file)
@@ -8,8 +8,6 @@
 
 #include <string>
 
 
 #include <string>
 
-#include <boost/intrusive_ptr.hpp>
-
 #include <xbt/base.h>
 
 #include <simgrid/s4u/forward.hpp>
 #include <xbt/base.h>
 
 #include <simgrid/s4u/forward.hpp>
@@ -40,13 +38,12 @@ public:
   // We don't have to manage the lifetime of mailboxes:
   friend void intrusive_ptr_add_ref(Mailbox*) {}
   friend void intrusive_ptr_release(Mailbox*) {}
   // We don't have to manage the lifetime of mailboxes:
   friend void intrusive_ptr_add_ref(Mailbox*) {}
   friend void intrusive_ptr_release(Mailbox*) {}
-  using Ptr = boost::intrusive_ptr<Mailbox>;
 
   /** Get the name of that mailbox */
   const char *getName();
 
   /** Retrieve the mailbox associated to the given string */
 
   /** Get the name of that mailbox */
   const char *getName();
 
   /** Retrieve the mailbox associated to the given string */
-  static Ptr byName(const char *name);
+  static MailboxPtr byName(const char *name);
 
   /** Returns whether the mailbox contains queued communications */
   bool empty();
 
   /** Returns whether the mailbox contains queued communications */
   bool empty();
@@ -65,8 +62,6 @@ public:
   ActorPtr receiver();
 };
 
   ActorPtr receiver();
 };
 
-using MailboxPtr = Mailbox::Ptr;
-
 }} // namespace simgrid::s4u
 
 XBT_PUBLIC(sg_mbox_t) sg_mbox_by_name(const char*name);
 }} // namespace simgrid::s4u
 
 XBT_PUBLIC(sg_mbox_t) sg_mbox_by_name(const char*name);
index 444fa6c..803a979 100644 (file)
@@ -38,7 +38,7 @@ ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime,
   smx_process_t process = simcall_process_create(
     name, std::move(code), nullptr, host->name().c_str(),
     killTime, nullptr, 0);
   smx_process_t process = simcall_process_create(
     name, std::move(code), nullptr, host->name().c_str(),
     killTime, nullptr, 0);
-  return Ptr(&process->getIface());
+  return ActorPtr(&process->getIface());
 }
 
 ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime,
 }
 
 ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime,
@@ -142,7 +142,7 @@ e_smx_state_t execute(double flops) {
   return simcall_execution_wait(s);
 }
 
   return simcall_execution_wait(s);
 }
 
-void* recv(Mailbox &chan) {
+void* recv(MailboxPtr chan) {
   void *res = nullptr;
   Comm& c = Comm::recv_init(chan);
   c.setDstData(&res,sizeof(res));
   void *res = nullptr;
   Comm& c = Comm::recv_init(chan);
   c.setDstData(&res,sizeof(res));
@@ -150,7 +150,7 @@ void* recv(Mailbox &chan) {
   return res;
 }
 
   return res;
 }
 
-void send(Mailbox &chan, void *payload, size_t simulatedSize) {
+void send(MailboxPtr chan, void *payload, size_t simulatedSize) {
   Comm& c = Comm::send_init(chan);
   c.setRemains(simulatedSize);
   c.setSrcData(payload);
   Comm& c = Comm::send_init(chan);
   c.setRemains(simulatedSize);
   c.setSrcData(payload);
index 7873e1d..4fd7d4e 100644 (file)
@@ -20,17 +20,17 @@ Comm::~Comm() {
 
 
 
 
 
 
-s4u::Comm &Comm::send_init(s4u::Mailbox &chan) {
+s4u::Comm &Comm::send_init(s4u::MailboxPtr chan) {
   s4u::Comm *res = new s4u::Comm();
   res->sender_ = SIMIX_process_self();
   s4u::Comm *res = new s4u::Comm();
   res->sender_ = SIMIX_process_self();
-  res->mailbox_ = &chan;
+  res->mailbox_ = chan;
   return *res;
 }
 
   return *res;
 }
 
-s4u::Comm &Comm::recv_init(s4u::Mailbox &chan) {
+s4u::Comm &Comm::recv_init(s4u::MailboxPtr chan) {
   s4u::Comm *res = new s4u::Comm();
   res->receiver_ = SIMIX_process_self();
   s4u::Comm *res = new s4u::Comm();
   res->receiver_ = SIMIX_process_self();
-  res->mailbox_ = &chan;
+  res->mailbox_ = chan;
   return *res;
 }
 
   return *res;
 }
 
@@ -132,7 +132,7 @@ void Comm::wait(double timeout) {
   state_ = finished;
 }
 
   state_ = finished;
 }
 
-s4u::Comm &Comm::send_async(Mailbox &dest, void *data, int simulatedSize) {
+s4u::Comm &Comm::send_async(MailboxPtr dest, void *data, int simulatedSize) {
   s4u::Comm &res = s4u::Comm::send_init(dest);
   res.setRemains(simulatedSize);
   res.srcBuff_ = data;
   s4u::Comm &res = s4u::Comm::send_init(dest);
   res.setRemains(simulatedSize);
   res.srcBuff_ = data;
@@ -141,7 +141,7 @@ s4u::Comm &Comm::send_async(Mailbox &dest, void *data, int simulatedSize) {
   return res;
 }
 
   return res;
 }
 
-s4u::Comm &Comm::recv_async(Mailbox &dest, void **data) {
+s4u::Comm &Comm::recv_async(MailboxPtr dest, void **data) {
   s4u::Comm &res = s4u::Comm::recv_init(dest);
   res.setDstData(data);
   res.start();
   s4u::Comm &res = s4u::Comm::recv_init(dest);
   res.setDstData(data);
   res.start();