#include <functional>
#include <list>
#include <map>
+#include <memory>
struct s_smx_process_exit_fun_t {
- std::function<void(int, void*)> fun;
+ std::function<void(bool, void*)> fun;
void *arg;
};
namespace kernel {
namespace actor {
-class ActorImpl : public surf::PropertyHolder {
+class XBT_PUBLIC ActorImpl : public surf::PropertyHolder {
s4u::Host* host_ = nullptr; /* the host on which the actor is running */
void* userdata_ = nullptr; /* kept for compatibility, it should be replaced with moddata */
aid_t pid_ = 0;
public:
xbt::string name_;
ActorImpl(xbt::string name, s4u::Host* host);
+ ActorImpl(const ActorImpl&) = delete;
+ ActorImpl& operator=(const ActorImpl&) = delete;
~ActorImpl();
double get_kill_time();
bool has_to_auto_restart() { return auto_restart_; }
void set_auto_restart(bool autorestart) { auto_restart_ = autorestart; }
- context::Context* context_ = nullptr; /* the context (uctx/raw/thread) that executes the user function */
+ std::unique_ptr<context::Context> context_; /* the context (uctx/raw/thread) that executes the user function */
std::exception_ptr exception_;
bool finished_ = false;
std::vector<s_smx_process_exit_fun_t> on_exit; /* list of functions executed when the process dies */
std::function<void()> code;
- smx_timer_t kill_timer = nullptr;
+ simix::Timer* kill_timer = nullptr;
private:
/* Refcounting */
s4u::ActorPtr iface() { return s4u::ActorPtr(&piface_); }
s4u::Actor* ciface() { return &piface_; }
- static ActorImplPtr create(std::string name, simix::ActorCode code, void* data, s4u::Host* host,
+ ActorImplPtr init(std::string name, s4u::Host* host);
+ ActorImpl* start(const simix::ActorCode& code);
+
+ static ActorImplPtr create(std::string name, const simix::ActorCode& code, void* data, s4u::Host* host,
std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
+ static ActorImplPtr attach(std::string name, void* data, s4u::Host* host,
+ std::unordered_map<std::string, std::string>* properties);
+ static void detach();
+ void cleanup();
void exit();
void kill(ActorImpl* actor);
void kill_all();
bool daemon_ = false;
ProcessArg() = default;
- explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
- std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
+ explicit ProcessArg(std::string name, const std::function<void()>& code, void* data, s4u::Host* host,
+ double kill_time, std::shared_ptr<std::unordered_map<std::string, std::string>> properties,
+ bool auto_restart)
: name(name)
- , code(std::move(code))
+ , code(code)
, data(data)
, host(host)
, kill_time(kill_time)
explicit ProcessArg(s4u::Host* host, ActorImpl* actor)
: name(actor->get_name())
- , code(std::move(actor->code))
+ , code(actor->code)
, data(actor->get_user_data())
, host(host)
, kill_time(actor->get_kill_time())
&ActorImpl::smx_synchro_hook>>
SynchroList;
-XBT_PUBLIC void create_maestro(std::function<void()> code);
+XBT_PUBLIC void create_maestro(const std::function<void()>& code);
} // namespace actor
} // namespace kernel
} // namespace simgrid
-XBT_PRIVATE void SIMIX_process_cleanup(smx_actor_t arg);
-
extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor);
XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro);