X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7bc01999f5003e51cc1d12f93647999a1a143f23..11ae3bfac7b4c85a23e220b9d0755449a622a37b:/include/simgrid/s4u/Actor.hpp diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 89a77276d6..95daaa287a 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -131,7 +132,7 @@ namespace s4u { /** @brief Simulation Agent (see \ref s4u_actor)*/ XBT_PUBLIC_CLASS Actor { friend Mailbox; - friend simgrid::simix::Process; + friend simgrid::simix::ActorImpl; smx_process_t pimpl_ = nullptr; /** Wrap a (possibly non-copyable) single-use task into a `std::function` */ @@ -146,7 +147,7 @@ XBT_PUBLIC_CLASS Actor { }; } - Actor(smx_process_t pimpl) : pimpl_(pimpl) {} + explicit Actor(smx_process_t pimpl) : pimpl_(pimpl) {} public: @@ -167,17 +168,18 @@ public: xbt_assert(actor != nullptr); SIMIX_process_unref(actor->pimpl_); } - using Ptr = boost::intrusive_ptr; // ***** Actor creation ***** + /** Retrieve a reference to myself */ + static ActorPtr self(); /** 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 code); + static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, std::function code); - static Ptr createActor(const char* name, s4u::Host *host, std::function code) + static ActorPtr createActor(const char* name, s4u::Host *host, std::function code) { return createActor(name, host, -1.0, std::move(code)); } @@ -193,17 +195,17 @@ public: // This constructor is enabled only if the call code(args...) is valid: typename = typename std::result_of::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: - 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 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 args) { return createActor(name, host, -1.0, function, std::move(args)); @@ -215,11 +217,13 @@ public: //static Actor *byPid(int pid); not implemented /** Retrieves the name of that actor */ - const char* getName(); + simgrid::xbt::string getName(); /** Retrieves the host on which that actor is running */ s4u::Host *getHost(); /** Retrieves the PID of that actor */ int getPid(); + /** Retrieves the PPID of that actor */ + int getPpid(); /** If set to true, the actor will automatically restart when its host reboots */ void setAutoRestart(bool autorestart); @@ -231,12 +235,13 @@ public: /** Ask the actor to die. * * It will only notice your request when doing a simcall next time (a communication or similar). - * SimGrid sometimes have issues when you kill actors that are currently communicating and such. We are working on it to fix the issues. + * SimGrid sometimes have issues when you kill actors that are currently communicating and such. + * We are working on it to fix the issues. */ void kill(); static void kill(int pid); - static Ptr forPid(int pid); + static ActorPtr forPid(int pid); /** * Wait for the actor to finish. @@ -253,8 +258,6 @@ protected: 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 { @@ -289,18 +292,23 @@ namespace this_actor { * * 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). */ - 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. */ XBT_PUBLIC(int) getPid(); + + /** + * Return the PPID of the current actor. + */ + int getPpid(); };