-/** @brief Start the host if it is off */
-void SIMIX_host_on(sg_host_t h)
-{
- smx_host_priv_t host = sg_host_simix(h);
-
- xbt_assert((host != NULL), "Invalid parameters");
-
- if (h->isOff()) {
- simgrid::surf::HostImpl* surf_host = h->extension<simgrid::surf::HostImpl>();
- surf_host->turnOn();
-
- unsigned int cpt;
- smx_process_arg_t arg;
- xbt_dynar_foreach(host->boot_processes,cpt,arg) {
- XBT_DEBUG("Booting Process %s(%s) right now",
- arg->name.c_str(), arg->hostname);
- if (simix_global->create_process_function) {
- simix_global->create_process_function(arg->name.c_str(),
- arg->code,
- NULL,
- arg->hostname,
- arg->kill_time,
- arg->properties,
- arg->auto_restart,
- NULL);
- } else {
- simcall_process_create(arg->name.c_str(),
- arg->code,
- NULL,
- arg->hostname,
- arg->kill_time,
- arg->properties,
- arg->auto_restart);
+ Host::~Host()
+ {
+ /* Clean Simulator data */
+ if (xbt_swag_size(process_list) != 0) {
+ char *msg = xbt_strdup("Shutting down host, but it's not empty:");
+ char *tmp;
+ smx_actor_t process = nullptr;
+
+ xbt_swag_foreach(process, process_list) {
+ tmp = bprintf("%s\n\t%s", msg, process->name.c_str());
+ free(msg);
+ msg = tmp;
+ }
+ SIMIX_display_process_status();
+ THROWF(arg_error, 0, "%s", msg);
+ }
+ for (auto arg : auto_restart_processes)
+ delete arg;
+ auto_restart_processes.clear();
+ for (auto arg : boot_processes)
+ delete arg;
+ boot_processes.clear();
+ xbt_swag_free(process_list);
+ }
+
+ /** Re-starts all the actors that are marked as restartable.
+ *
+ * Weird things will happen if you turn on an host that is already on. S4U is fool-proof, not this.
+ */
+ void Host::turnOn()
+ {
+ for (auto arg : boot_processes) {
+ XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->host->cname());
+ smx_actor_t actor = simix_global->create_process_function(arg->name.c_str(), arg->code, nullptr, arg->host,
+ arg->properties, nullptr);
+ if (arg->kill_time >= 0)
+ simcall_process_set_kill_time(actor, arg->kill_time);
+ if (arg->auto_restart)
+ simcall_process_auto_restart_set(actor, arg->auto_restart);