X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/af4023f2adc7976a736077c23829d217e7b89637..24de4abff1dbfc7c779f6768186be603342df002:/include/simgrid/s4u/Actor.hpp diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 92fc4852ce..efdc1bd822 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2018. 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. */ @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,7 @@ namespace s4u { * pure function or as an object. It is very simple with functions: * * @code{.cpp} - * #include "s4u/actor.hpp" + * #include * * // Declare the code of your worker * void worker() { @@ -68,7 +69,7 @@ namespace s4u { * The syntax is slightly more complicated, but not much. * * @code{.cpp} - * #include "s4u/actor.hpp" + * #include * * // Declare the class representing your actors * class Worker { @@ -128,12 +129,12 @@ namespace s4u { */ /** @brief Simulation Agent */ -XBT_PUBLIC_CLASS Actor : public simgrid::xbt::Extendable -{ +class XBT_PUBLIC Actor : public simgrid::xbt::Extendable { + friend Exec; friend Mailbox; - friend simgrid::simix::ActorImpl; + friend simgrid::kernel::actor::ActorImpl; friend simgrid::kernel::activity::MailboxImpl; - simix::ActorImpl* pimpl_ = nullptr; + kernel::actor::ActorImpl* pimpl_ = nullptr; /** Wrap a (possibly non-copyable) single-use task into a `std::function` */ template @@ -154,13 +155,18 @@ public: Actor& operator=(Actor const&) = delete; // ***** Reference count ***** - friend void intrusive_ptr_add_ref(Actor * actor); - friend void intrusive_ptr_release(Actor * actor); + friend XBT_PUBLIC void intrusive_ptr_add_ref(Actor * actor); + friend XBT_PUBLIC void intrusive_ptr_release(Actor * actor); // ***** Actor creation ***** /** Retrieve a reference to myself */ static ActorPtr self(); + /** Signal to others that a new actor has been created **/ + static simgrid::xbt::signal onCreation; + /** Signal indicating that the given actor is about to disappear */ + static simgrid::xbt::signal onDestruction; + /** Create an actor using a function * * If the actor is restarted, the actor has a fresh copy of the function. @@ -197,19 +203,28 @@ public: /** This actor will be automatically terminated when the last non-daemon actor finishes **/ void daemonize(); + /** Returns whether or not this actor has been daemonized or not **/ + bool isDaemon(); + + XBT_ATTRIB_DEPRECATED_v323("Please use Actor::get_name()") const simgrid::xbt::string& getName() const + { + return get_name(); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Actor::get_cname()") const char* getCname() const { return get_cname(); } + /** Retrieves the name of that actor as a C++ string */ - const simgrid::xbt::string& getName() const; + const simgrid::xbt::string& get_name() const; /** Retrieves the name of that actor as a C string */ - const char* getCname() const; + const char* get_cname() const; /** Retrieves the host on which that actor is running */ s4u::Host* getHost(); /** Retrieves the PID of that actor * - * actor_id_t is an alias for unsigned long */ + * aid_t is an alias for long */ aid_t getPid(); /** Retrieves the PPID of that actor * - * actor_id_t is an alias for unsigned long */ + * aid_t is an alias for long */ aid_t getPpid(); /** Suspend an actor by suspending the task on which it was waiting for the completion. */ @@ -217,9 +232,9 @@ public: /** Resume a suspended actor by resuming the task on which it was waiting for the completion. */ void resume(); - + void yield(); - + /** Returns true if the actor is suspended. */ int isSuspended(); @@ -258,6 +273,7 @@ public: * This blocks the calling actor until the actor on which we call join() is terminated */ void join(); + void join(double timeout); // Static methods on all actors: @@ -266,9 +282,10 @@ public: static void killAll(int resetPid); /** Returns the internal implementation of this actor */ - simix::ActorImpl* getImpl(); + kernel::actor::ActorImpl* getImpl(); /** Retrieve the property value (or nullptr if not set) */ + std::map* getProperties(); const char* getProperty(const char* key); void setProperty(const char* key, const char* value); Actor* restart(); @@ -278,11 +295,11 @@ public: * @brief Static methods working on the current actor (see @ref s4u::Actor) */ namespace this_actor { -XBT_PUBLIC(bool) isMaestro(); +XBT_PUBLIC bool isMaestro(); /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */ -XBT_PUBLIC(void) sleep_for(double duration); -XBT_PUBLIC(void) sleep_until(double timeout); +XBT_PUBLIC void sleep_for(double duration); +XBT_PUBLIC void sleep_until(double timeout); template inline void sleep_for(std::chrono::duration duration) { @@ -296,75 +313,56 @@ template inline void sleep_until(const SimulationTimePoint