#include <boost/intrusive_ptr.hpp>
+#include <xbt/Extendable.hpp>
#include <xbt/base.h>
#include <xbt/functional.hpp>
#include <xbt/string.hpp>
*/
/** @brief Simulation Agent */
-XBT_PUBLIC_CLASS Actor {
+XBT_PUBLIC_CLASS Actor : public simgrid::xbt::Extendable<Actor>
+{
+
friend Mailbox;
friend simgrid::simix::ActorImpl;
- smx_actor_t pimpl_ = nullptr;
+ friend simgrid::kernel::activity::MailboxImpl;
+ simix::ActorImpl* pimpl_ = nullptr;
/** Wrap a (possibly non-copyable) single-use task into a `std::function` */
template<class F, class... Args>
typedef decltype(f(std::move(args)...)) R;
auto task = std::make_shared<simgrid::xbt::Task<R()>>(
simgrid::xbt::makeTask(std::move(f), std::move(args)...));
- return [=] {
- (*task)();
- };
+ return [task] { (*task)(); };
}
explicit Actor(smx_actor_t pimpl) : pimpl_(pimpl) {}
public:
// ***** No copy *****
-
Actor(Actor const&) = delete;
Actor& operator=(Actor const&) = delete;
// ***** Reference count (delegated to pimpl_) *****
-
friend void intrusive_ptr_add_ref(Actor* actor)
{
xbt_assert(actor != nullptr);
*
* If the actor is restarted, the actor has a fresh copy of the function.
*/
- static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, 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));
- }
+ static ActorPtr createActor(const char* name, s4u::Host* host, std::function<void()> code);
/** Create an actor using code
*
// Create actor from function name:
- static ActorPtr createActor(const char* name, s4u::Host *host, double killTime,
- const char* function, std::vector<std::string> args);
-
- 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));
- }
+ static ActorPtr createActor(const char* name, s4u::Host* host, const char* function, std::vector<std::string> args);
// ***** Methods *****
- /** Retrieves the actor that have the given PID (or NULL if not existing) */
- //static Actor *byPid(int pid); not implemented
-
- /** Retrieves the name of that actor */
- simgrid::xbt::string getName();
+ /** Retrieves the name of that actor as a C string */
+ const char* cname();
+ /** Retrieves the name of that actor as a C++ string */
+ simgrid::xbt::string name();
/** Retrieves the host on which that actor is running */
- s4u::Host *getHost();
+ s4u::Host* host();
/** Retrieves the PID of that actor */
- int getPid();
+ int pid();
/** Retrieves the PPID of that actor */
- int getPpid();
+ int ppid();
/** If set to true, the actor will automatically restart when its host reboots */
void setAutoRestart(bool autorestart);
/** Sets the time at which that actor should be killed */
void setKillTime(double time);
/** Retrieves the time at which that actor will be killed (or -1 if not set) */
- double getKillTime();
+ double killTime();
/** 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.
+ * Still. Please report any bug that you may encounter with a minimal working example.
*/
void kill();
static void kill(int pid);
- static ActorPtr forPid(int pid);
-
- /**
- * Wait for the actor to finish.
- */
+
+ /** Retrieves the actor that have the given PID (or nullptr if not existing) */
+ static ActorPtr byPid(int pid);
+
+ /** @brief Wait for the actor to finish.
+ *
+ * This blocks the calling actor until the actor on which we call join() is terminated
+ */
void join();
// Static methods on all actors:
/** Ask kindly to all actors to die. Only the issuer will survive. */
static void killAll();
-protected:
/** Returns the internal implementation of this actor */
- smx_actor_t getImpl();
+ simix::ActorImpl* getImpl();
};
/** @ingroup s4u_api
*
* See \ref Comm for the full communication API (including non blocking communications).
*/
- 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();
+ XBT_PUBLIC(void) send(MailboxPtr chan, void* payload, double simulatedSize);
+
+ /** @brief Returns the PID of the current actor. */
+ XBT_PUBLIC(int) pid();
+
+ /** @brief Returns the PPID of the current actor. */
+ int ppid();
+ /** @brief Returns the name of the current actor. */
+ std::string name();
};
/** @} */