-/* Copyright (c) 2006-2022. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2006-2023. 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 <simgrid/chrono.hpp>
#include <xbt/Extendable.hpp>
#include <xbt/signal.hpp>
-#include <xbt/string.hpp>
#include <functional>
#include <unordered_map>
friend Mailbox;
friend kernel::actor::ActorImpl;
friend kernel::activity::MailboxImpl;
- friend void this_actor::sleep_for(double);
- friend void this_actor::suspend();
+ friend XBT_PUBLIC void this_actor::sleep_for(double);
+ friend XBT_PUBLIC void this_actor::suspend();
kernel::actor::ActorImpl* const pimpl_;
#endif
static void on_destruction_cb(const std::function<void(Actor const&)>& cb) { on_destruction.connect(cb); }
/** Create an actor from a @c std::function<void()>.
- * If the actor is restarted, it gets a fresh copy of the function.
+ * If the actor is restarted, it gets a fresh copy of the function.
* @verbatim embed:rst:inline See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
static ActorPtr create(const std::string& name, s4u::Host* host, const std::function<void()>& code);
/** Create an actor, but don't start it yet.
ActorPtr start(const std::function<void()>& code, std::vector<std::string> args);
- /** Create an actor from a callable thing.
+ /** Create an actor from a callable thing.
* @verbatim embed:rst:inline See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
template <class F> static ActorPtr create(const std::string& name, s4u::Host* host, F code)
{
/** Create an actor using a callable thing and its arguments.
*
- * Note that the arguments will be copied, so move-only parameters are forbidden.
+ * Note that the arguments will be copied, so move-only parameters are forbidden.
* @verbatim embed:rst:inline See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
template <class F, class... Args,
return create(name, host, std::bind(std::move(code), std::move(args)...));
}
- /** Create actor from function name and a vector of strings as arguments.
+ /** Create actor from function name and a vector of strings as arguments.
* @verbatim embed:rst:inline See the :ref:`example <s4u_ex_actors_create>`. @endverbatim */
static ActorPtr create(const std::string& name, s4u::Host* host, const std::string& function,
std::vector<std::string> args);
static bool is_maestro();
/** Retrieves the name of that actor as a C++ string */
- const simgrid::xbt::string& get_name() const;
+ const std::string& get_name() const;
/** Retrieves the name of that actor as a C string */
const char* get_cname() const;
/** Retrieves the host on which that actor is running */
/** Retrieves the actor ID of that actor's creator */
aid_t get_ppid() const;
- /** Suspend an actor, that is blocked until resumeed by another actor */
+ /** Suspend an actor, that is blocked until resumed by another actor. */
void suspend();
/** Resume an actor that was previously suspended */
/** Returns true if the actor is suspended. */
bool is_suspended() const;
- /** If set to true, the actor will automatically restart when its host reboots */
+ /** If set to true, the actor will automatically restart when its host reboots.
+ *
+ * Some elements of the actor are remembered over reboots: name, host, properties, the on_exit functions, whether it
+ * is daemonized and whether it should automatically restart when its host reboots. Note that the state after reboot
+ * is the one when set_auto_restart() is called.
+ *
+ * If you daemonize your actor after marking it auto_restart, then the new actor after rebooot will not be a daemon.
+ *
+ * The on_exit functions are the one defined when the actor dies, not the ones given when it was marked auto_restart
+ * (sorry for the inconsistency -- speak to us if it's too hard to bear).
+ */
Actor* set_auto_restart(bool autorestart = true);
+ /** Returns the number of reboots that this actor did. Before the first reboot, this function returns 0. */
+ int get_restart_count() const;
/** Add a function to the list of "on_exit" functions for the current actor. The on_exit functions are the functions
* executed when your actor is killed. You should use them to free the data used by your actor.