1 /* Copyright (c) 2007-2013. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "smx_private.h"
8 #include "xbt/sysdep.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
14 "Logging specific to SIMIX (process)");
16 unsigned long simix_process_maxpid = 0;
19 * \brief Returns the current agent.
21 * This functions returns the currently running SIMIX process.
23 * \return The SIMIX process
25 XBT_INLINE smx_process_t SIMIX_process_self(void)
27 smx_context_t self_context = SIMIX_context_self();
29 return self_context ? SIMIX_context_get_data(self_context) : NULL;
33 * \brief Returns whether a process has pending asynchronous communications.
34 * \return true if there are asynchronous communications in this process
36 int SIMIX_process_has_pending_comms(smx_process_t process) {
38 return xbt_fifo_size(process->comms) > 0;
41 void SIMIX_pre_process_cleanup(smx_simcall_t simcall, smx_process_t process) {
42 SIMIX_process_cleanup(process);
45 * \brief Moves a process to the list of processes to destroy.
47 void SIMIX_process_cleanup(smx_process_t process)
49 XBT_DEBUG("Cleanup process %s (%p), waiting action %p",
50 process->name, process, process->waiting_action);
52 /* cancel non-blocking communications */
54 while ((action = xbt_fifo_pop(process->comms))) {
56 /* make sure no one will finish the comm after this process is destroyed,
57 * because src_proc or dst_proc would be an invalid pointer */
58 SIMIX_comm_cancel(action);
60 if (action->comm.src_proc == process) {
61 XBT_DEBUG("Found an unfinished send comm %p (detached = %d), state %d, src = %p, dst = %p",
62 action, action->comm.detached, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
63 action->comm.src_proc = NULL;
65 if (action->comm.detached) {
66 if (action->comm.refcount == 0) {
67 XBT_DEBUG("Increase the refcount before destroying it since it's detached");
68 /* I'm not supposed to destroy a detached comm from the sender side,
69 * unless there is no receiver matching the rdv */
70 action->comm.refcount++;
71 SIMIX_comm_destroy(action);
74 XBT_DEBUG("Don't destroy it since its refcount is %d", action->comm.refcount);
77 SIMIX_comm_destroy(action);
80 else if (action->comm.dst_proc == process){
81 XBT_DEBUG("Found an unfinished recv comm %p, state %d, src = %p, dst = %p",
82 action, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
83 action->comm.dst_proc = NULL;
85 if (action->comm.detached && action->comm.refcount == 1
86 && action->comm.src_proc != NULL) {
87 /* the comm will be freed right now, remove it from the sender */
88 xbt_fifo_remove(action->comm.src_proc->comms, action);
90 SIMIX_comm_destroy(action);
93 xbt_die("Communication action %p is in my list but I'm not the sender "
94 "or the receiver", action);
98 xbt_swag_remove(process, simix_global->process_list);
99 xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list);
100 xbt_swag_insert(process, simix_global->process_to_destroy);
101 process->context->iwannadie = 0;
107 * Should be called some time to time to free the memory allocated for processes
108 * that have finished (or killed).
110 void SIMIX_process_empty_trash(void)
112 smx_process_t process = NULL;
114 while ((process = xbt_swag_extract(simix_global->process_to_destroy))) {
115 SIMIX_context_free(process->context);
117 /* Free the exception allocated at creation time */
118 free(process->running_ctx);
119 xbt_dict_free(&process->properties);
121 xbt_fifo_free(process->comms);
123 xbt_dynar_free(&process->on_exit);
125 xbt_free(process->name);
131 * \brief Creates and runs the maestro process
133 void SIMIX_create_maestro_process()
135 smx_process_t maestro = NULL;
137 /* Create maestro process and intilialize it */
138 maestro = xbt_new0(s_smx_process_t, 1);
139 maestro->pid = simix_process_maxpid++;
140 maestro->name = (char *) "";
141 maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
142 XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
143 maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
144 maestro->simcall.issuer = maestro;
146 if (SIMIX_process_self()) {
147 maestro->ppid = SIMIX_process_get_PID(SIMIX_process_self());
152 simix_global->maestro_process = maestro;
156 * \brief Stops a process.
158 * Stops the process, execute all the registered on_exit functions,
159 * register it to the list of the process to restart if needed
160 * and stops its context.
162 void SIMIX_process_stop(smx_process_t arg) {
163 /* execute the on_exit functions */
164 SIMIX_process_on_exit_runall(arg);
165 /* Add the process to the list of process to restart, only if
168 if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) {
169 SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data,
170 sg_host_name(arg->smx_host),
172 arg->argc,arg->argv,arg->properties,
175 XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_name(arg->smx_host));
176 /* stop the context */
177 SIMIX_context_stop(arg->context);
181 * \brief Same as SIMIX_process_create() but with only one argument (used by timers).
182 * This function frees the argument.
183 * \return the process created
185 smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
187 smx_process_t process;
188 simix_global->create_process_function(
204 void SIMIX_pre_process_create(smx_simcall_t simcall,
205 smx_process_t *process,
207 xbt_main_func_t code,
209 const char *hostname,
211 int argc, char **argv,
212 xbt_dict_t properties,
214 return SIMIX_process_create(process, name, code, data, hostname,
215 kill_time, argc, argv, properties, auto_restart);
218 * \brief Internal function to create a process.
220 * This function actually creates the process.
221 * It may be called when a SIMCALL_PROCESS_CREATE simcall occurs,
222 * or directly for SIMIX internal purposes. The sure thing is that it's called from maestro context.
224 * \return the process created
226 void SIMIX_process_create(smx_process_t *process,
228 xbt_main_func_t code,
230 const char *hostname,
232 int argc, char **argv,
233 xbt_dict_t properties,
237 smx_host_t host = SIMIX_host_get_by_name(hostname);
239 XBT_DEBUG("Start process %s on host '%s'", name, hostname);
241 if (!SIMIX_host_get_state(host)) {
243 XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
245 for (i = 0; i < argc; i++)
250 *process = xbt_new0(s_smx_process_t, 1);
252 xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters");
254 (*process)->pid = simix_process_maxpid++;
255 (*process)->name = xbt_strdup(name);
256 (*process)->smx_host = host;
257 (*process)->data = data;
258 (*process)->comms = xbt_fifo_new();
259 (*process)->simcall.issuer = *process;
261 if (SIMIX_process_self()) {
262 (*process)->ppid = SIMIX_process_get_PID(SIMIX_process_self());
264 (*process)->ppid = -1;
267 /* Process data for auto-restart */
268 (*process)->auto_restart = auto_restart;
269 (*process)->code = code;
270 (*process)->argc = argc;
271 (*process)->argv = argv;
272 (*process)->kill_time = kill_time;
275 XBT_VERB("Create context %s", (*process)->name);
276 (*process)->context = SIMIX_context_new(code, argc, argv,
277 simix_global->cleanup_process_function, *process);
279 (*process)->running_ctx = xbt_new(xbt_running_ctx_t, 1);
280 XBT_RUNNING_CTX_INITIALIZE((*process)->running_ctx);
283 MC_ignore_heap((*process)->running_ctx, sizeof(*(*process)->running_ctx));
287 (*process)->properties = properties;
289 /* Add the process to it's host process list */
290 xbt_swag_insert(*process, SIMIX_host_priv(host)->process_list);
292 XBT_DEBUG("Start context '%s'", (*process)->name);
294 /* Now insert it in the global process list and in the process to run list */
295 xbt_swag_insert(*process, simix_global->process_list);
296 XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, sg_host_name(host));
297 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process);
300 if (kill_time > SIMIX_get_clock()) {
301 if (simix_global->kill_process_function) {
302 XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name,
303 sg_host_name((*process)->smx_host), kill_time);
304 SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process);
310 * \brief Executes the processes from simix_global->process_to_run.
312 * The processes of simix_global->process_to_run are run (in parallel if
313 * possible). On exit, simix_global->process_to_run is empty, and
314 * simix_global->process_that_ran contains the list of processes that just ran.
315 * The two lists are swapped so, be careful when using them before and after a
316 * call to this function.
318 void SIMIX_process_runall(void)
320 SIMIX_context_runall();
322 xbt_dynar_t tmp = simix_global->process_that_ran;
323 simix_global->process_that_ran = simix_global->process_to_run;
324 simix_global->process_to_run = tmp;
325 xbt_dynar_reset(simix_global->process_to_run);
328 void SIMIX_pre_process_kill(smx_simcall_t simcall, smx_process_t process) {
329 SIMIX_process_kill(process, simcall->issuer);
332 * \brief Internal function to kill a SIMIX process.
334 * This function may be called when a SIMCALL_PROCESS_KILL simcall occurs,
335 * or directly for SIMIX internal purposes.
337 * \param process poor victim
338 * \param issuer the process which has sent the PROCESS_KILL. Important to not schedule twice the same process.
340 void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
342 XBT_DEBUG("Killing process %s on %s", process->name, sg_host_name(process->smx_host));
344 process->context->iwannadie = 1;
345 process->blocked = 0;
346 process->suspended = 0;
347 /* FIXME: set doexception to 0 also? */
349 /* destroy the blocking action if any */
350 if (process->waiting_action) {
352 switch (process->waiting_action->type) {
354 case SIMIX_ACTION_EXECUTE:
355 case SIMIX_ACTION_PARALLEL_EXECUTE:
356 SIMIX_host_execution_destroy(process->waiting_action);
359 case SIMIX_ACTION_COMMUNICATE:
360 xbt_fifo_remove(process->comms, process->waiting_action);
361 SIMIX_comm_cancel(process->waiting_action);
362 SIMIX_comm_destroy(process->waiting_action);
365 case SIMIX_ACTION_SLEEP:
366 SIMIX_process_sleep_destroy(process->waiting_action);
369 case SIMIX_ACTION_SYNCHRO:
370 SIMIX_synchro_stop_waiting(process, &process->simcall);
371 SIMIX_synchro_destroy(process->waiting_action);
374 case SIMIX_ACTION_IO:
375 SIMIX_io_destroy(process->waiting_action);
378 /* **************************************/
379 /* TUTORIAL: New API */
380 case SIMIX_ACTION_NEW_API:
381 SIMIX_new_api_destroy(process->waiting_action);
383 /* **************************************/
387 if(!xbt_dynar_member(simix_global->process_to_run, &(process)) && process != issuer) {
388 xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
393 void SIMIX_pre_process_killall(smx_simcall_t simcall, int reset_pid) {
394 SIMIX_process_killall(simcall->issuer, reset_pid);
397 * \brief Kills all running processes.
398 * \param issuer this one will not be killed
400 void SIMIX_process_killall(smx_process_t issuer, int reset_pid)
402 smx_process_t p = NULL;
404 while ((p = xbt_swag_extract(simix_global->process_list))) {
406 SIMIX_process_kill(p,issuer);
411 simix_process_maxpid = reset_pid;
413 SIMIX_context_runall();
415 SIMIX_process_empty_trash();
418 void SIMIX_pre_process_change_host(smx_simcall_t simcall, smx_process_t process,
421 process->new_host = dest;
423 void SIMIX_process_change_host(smx_process_t process,
426 xbt_assert((process != NULL), "Invalid parameters");
427 xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list);
428 process->smx_host = dest;
429 xbt_swag_insert(process, SIMIX_host_priv(dest)->process_list);
433 void SIMIX_pre_process_suspend(smx_simcall_t simcall, smx_process_t process)
435 smx_action_t action_suspend =
436 SIMIX_process_suspend(process, simcall->issuer);
438 if (process != simcall->issuer) {
439 SIMIX_simcall_answer(simcall);
441 xbt_fifo_push(action_suspend->simcalls, simcall);
442 process->waiting_action = action_suspend;
443 SIMIX_host_execution_suspend(process->waiting_action);
445 /* If we are suspending ourselves, then just do not finish the simcall now */
448 smx_action_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
450 xbt_assert((process != NULL), "Invalid parameters");
452 if (process->suspended) {
453 XBT_DEBUG("Process '%s' is already suspended", process->name);
457 process->suspended = 1;
459 /* If we are suspending another process, and it is waiting on an action,
460 suspend its action. */
461 if (process != issuer) {
463 if (process->waiting_action) {
465 switch (process->waiting_action->type) {
467 case SIMIX_ACTION_EXECUTE:
468 case SIMIX_ACTION_PARALLEL_EXECUTE:
469 SIMIX_host_execution_suspend(process->waiting_action);
472 case SIMIX_ACTION_COMMUNICATE:
473 SIMIX_comm_suspend(process->waiting_action);
476 case SIMIX_ACTION_SLEEP:
477 SIMIX_process_sleep_suspend(process->waiting_action);
480 case SIMIX_ACTION_SYNCHRO:
481 /* Suspension is delayed to when the process is rescheduled. */
485 xbt_die("Internal error in SIMIX_process_suspend: unexpected action type %d",
486 (int)process->waiting_action->type);
490 /* Suspension is delayed to when the process is rescheduled. */
494 return SIMIX_host_execute("suspend", process->smx_host, 0.0, 1.0);
498 void SIMIX_pre_process_resume(smx_simcall_t simcall, smx_process_t process){
499 SIMIX_process_resume(process, simcall->issuer);
502 void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
504 xbt_assert((process != NULL), "Invalid parameters");
506 XBT_IN("process = %p, issuer = %p", process, issuer);
508 if(process->context->iwannadie) {
509 XBT_VERB("Ignoring request to suspend a process that is currently dying.");
513 if(!process->suspended) return;
514 process->suspended = 0;
516 /* If we are resuming another process, resume the action it was waiting for
517 if any. Otherwise add it to the list of process to run in the next round. */
518 if (process != issuer) {
520 if (process->waiting_action) {
522 switch (process->waiting_action->type) {
524 case SIMIX_ACTION_EXECUTE:
525 case SIMIX_ACTION_PARALLEL_EXECUTE:
526 SIMIX_host_execution_resume(process->waiting_action);
529 case SIMIX_ACTION_COMMUNICATE:
530 SIMIX_comm_resume(process->waiting_action);
533 case SIMIX_ACTION_SLEEP:
534 SIMIX_process_sleep_resume(process->waiting_action);
537 case SIMIX_ACTION_SYNCHRO:
538 /* I cannot resume it now. This is delayed to when the process is rescheduled at
539 * the end of the synchro. */
543 xbt_die("Internal error in SIMIX_process_resume: unexpected action type %d",
544 (int)process->waiting_action->type);
547 } else XBT_WARN("Strange. Process %p is trying to resume himself.", issuer);
552 int SIMIX_process_get_maxpid(void) {
553 return simix_process_maxpid;
556 int SIMIX_pre_process_count(smx_simcall_t simcall){
557 return SIMIX_process_count();
559 int SIMIX_process_count(void)
561 return xbt_swag_size(simix_global->process_list);
564 int SIMIX_pre_process_get_PID(smx_simcall_t simcall, smx_process_t self){
565 return SIMIX_process_get_PID(self);
568 int SIMIX_process_get_PID(smx_process_t self){
575 int SIMIX_pre_process_get_PPID(smx_simcall_t simcall, smx_process_t self){
576 return SIMIX_process_get_PPID(self);
579 int SIMIX_process_get_PPID(smx_process_t self){
586 void* SIMIX_pre_process_self_get_data(smx_simcall_t simcall, smx_process_t self){
587 return SIMIX_process_self_get_data(self);
590 void* SIMIX_process_self_get_data(smx_process_t self)
592 xbt_assert(self == SIMIX_process_self(), "This is not the current process");
597 return SIMIX_process_get_data(self);
600 void SIMIX_pre_process_set_data(smx_simcall_t simcall, smx_process_t process,
602 SIMIX_process_set_data(process, data);
604 void SIMIX_process_self_set_data(smx_process_t self, void *data)
606 xbt_assert(self == SIMIX_process_self(), "This is not the current process");
608 SIMIX_process_set_data(self, data);
611 void* SIMIX_pre_process_get_data(smx_simcall_t simcall, smx_process_t process){
612 return SIMIX_process_get_data(process);
614 void* SIMIX_process_get_data(smx_process_t process)
616 return process->data;
619 void SIMIX_process_set_data(smx_process_t process, void *data)
621 process->data = data;
624 smx_host_t SIMIX_pre_process_get_host(smx_simcall_t simcall, smx_process_t process){
625 return SIMIX_process_get_host(process);
627 smx_host_t SIMIX_process_get_host(smx_process_t process)
629 return process->smx_host;
632 /* needs to be public and without simcall because it is called
633 by exceptions and logging events */
634 const char* SIMIX_process_self_get_name(void) {
636 smx_process_t process = SIMIX_process_self();
637 if (process == NULL || process == simix_global->maestro_process)
640 return SIMIX_process_get_name(process);
643 const char* SIMIX_pre_process_get_name(smx_simcall_t simcall, smx_process_t process) {
644 return SIMIX_process_get_name(process);
646 const char* SIMIX_process_get_name(smx_process_t process)
648 return process->name;
651 smx_process_t SIMIX_process_get_by_name(const char* name)
655 xbt_swag_foreach(proc, simix_global->process_list)
657 if(!strcmp(name, proc->name))
663 int SIMIX_pre_process_is_suspended(smx_simcall_t simcall, smx_process_t process){
664 return SIMIX_process_is_suspended(process);
666 int SIMIX_process_is_suspended(smx_process_t process)
668 return process->suspended;
671 xbt_dict_t SIMIX_pre_process_get_properties(smx_simcall_t simcall, smx_process_t process){
672 return SIMIX_process_get_properties(process);
674 xbt_dict_t SIMIX_process_get_properties(smx_process_t process)
676 return process->properties;
679 void SIMIX_pre_process_sleep(smx_simcall_t simcall, double duration)
681 if (MC_is_active()) {
682 MC_process_clock_add(simcall->issuer, duration);
683 simcall_process_sleep__set__result(simcall, SIMIX_DONE);
684 SIMIX_simcall_answer(simcall);
687 smx_action_t action = SIMIX_process_sleep(simcall->issuer, duration);
688 xbt_fifo_push(action->simcalls, simcall);
689 simcall->issuer->waiting_action = action;
692 smx_action_t SIMIX_process_sleep(smx_process_t process, double duration)
695 smx_host_t host = process->smx_host;
697 /* check if the host is active */
698 if (surf_workstation_model->extension.
699 workstation.get_state(host) != SURF_RESOURCE_ON) {
700 THROWF(host_error, 0, "Host %s failed, you cannot call this function",
704 action = xbt_mallocator_get(simix_global->action_mallocator);
705 action->type = SIMIX_ACTION_SLEEP;
708 action->category = NULL;
711 action->sleep.host = host;
712 action->sleep.surf_sleep =
713 surf_workstation_model->extension.workstation.sleep(host, duration);
715 surf_workstation_model->action_data_set(action->sleep.surf_sleep, action);
716 XBT_DEBUG("Create sleep action %p", action);
721 void SIMIX_post_process_sleep(smx_action_t action)
723 smx_simcall_t simcall;
726 while ((simcall = xbt_fifo_shift(action->simcalls))) {
728 switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){
729 case SURF_ACTION_FAILED:
730 simcall->issuer->context->iwannadie = 1;
731 //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
732 state = SIMIX_SRC_HOST_FAILURE;
735 case SURF_ACTION_DONE:
743 if (surf_workstation_model->extension.
744 workstation.get_state(simcall->issuer->smx_host) != SURF_RESOURCE_ON) {
745 simcall->issuer->context->iwannadie = 1;
747 simcall_process_sleep__set__result(simcall, state);
748 simcall->issuer->waiting_action = NULL;
749 SIMIX_simcall_answer(simcall);
752 SIMIX_process_sleep_destroy(action);
755 void SIMIX_process_sleep_destroy(smx_action_t action)
757 XBT_DEBUG("Destroy action %p", action);
758 if (action->sleep.surf_sleep)
759 action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep);
760 xbt_mallocator_release(simix_global->action_mallocator, action);
763 void SIMIX_process_sleep_suspend(smx_action_t action)
765 surf_workstation_model->suspend(action->sleep.surf_sleep);
768 void SIMIX_process_sleep_resume(smx_action_t action)
770 surf_workstation_model->resume(action->sleep.surf_sleep);
774 * \brief Calling this function makes the process to yield.
776 * Only the current process can call this function, giving back the control to
779 * \param self the current process
781 void SIMIX_process_yield(smx_process_t self)
783 XBT_DEBUG("Yield process '%s'", self->name);
785 /* Go into sleep and return control to maestro */
786 SIMIX_context_suspend(self->context);
788 /* Ok, maestro returned control to us */
789 XBT_DEBUG("Control returned to me: '%s'", self->name);
791 if (self->new_host) {
792 SIMIX_process_change_host(self, self->new_host);
793 self->new_host = NULL;
796 if (self->context->iwannadie){
797 XBT_DEBUG("I wanna die!");
798 SIMIX_process_stop(self);
801 if(self->suspended) {
802 xbt_assert(!self->doexception, "Gloups! This exception may be lost by subsequent calls.");
804 SIMIX_process_suspend(self,self);
807 if (self->doexception) {
808 XBT_DEBUG("Wait, maestro left me an exception");
809 self->doexception = 0;
815 /* callback: context fetching */
816 xbt_running_ctx_t *SIMIX_process_get_running_context(void)
818 return SIMIX_process_self()->running_ctx;
821 /* callback: termination */
822 void SIMIX_process_exception_terminate(xbt_ex_t * e)
828 smx_context_t SIMIX_process_get_context(smx_process_t p) {
832 void SIMIX_process_set_context(smx_process_t p,smx_context_t c) {
837 * \brief Returns the list of processes to run.
839 xbt_dynar_t SIMIX_process_get_runnable(void)
841 return simix_global->process_to_run;
845 * \brief Returns the process from PID.
847 smx_process_t SIMIX_process_from_PID(int PID)
850 xbt_swag_foreach(proc, simix_global->process_list)
858 /** @brief returns a dynar containg all currently existing processes */
859 xbt_dynar_t SIMIX_processes_as_dynar(void) {
861 xbt_dynar_t res = xbt_dynar_new(sizeof(smx_process_t),NULL);
862 xbt_swag_foreach(proc, simix_global->process_list) {
863 xbt_dynar_push(res,&proc);
869 void SIMIX_process_on_exit_runall(smx_process_t process) {
870 s_smx_process_exit_fun_t exit_fun;
872 while (!xbt_dynar_is_empty(process->on_exit)) {
873 exit_fun = xbt_dynar_pop_as(process->on_exit,s_smx_process_exit_fun_t);
874 (exit_fun.fun)(exit_fun.arg);
878 void SIMIX_pre_process_on_exit(smx_simcall_t simcall, smx_process_t process,
879 int_f_pvoid_t fun, void *data) {
880 SIMIX_process_on_exit(process, fun, data);
883 void SIMIX_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data) {
884 xbt_assert(process, "current process not found: are you in maestro context ?");
886 if (!process->on_exit) {
887 process->on_exit = xbt_dynar_new(sizeof(s_smx_process_exit_fun_t), NULL);
890 s_smx_process_exit_fun_t exit_fun = {fun, data};
892 xbt_dynar_push_as(process->on_exit,s_smx_process_exit_fun_t,exit_fun);
895 void SIMIX_pre_process_auto_restart_set(smx_simcall_t simcall, smx_process_t process,
897 SIMIX_process_auto_restart_set(process, auto_restart);
900 * \brief Sets the auto-restart status of the process.
901 * If set to 1, the process will be automatically restarted when its host
904 void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart) {
905 process->auto_restart = auto_restart;
908 smx_process_t SIMIX_pre_process_restart(smx_simcall_t simcall, smx_process_t process) {
909 return SIMIX_process_restart(process, simcall->issuer);
912 * \brief Restart a process.
913 * Restart a process, starting it again from the beginning.
915 smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) {
916 XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_name(process->smx_host));
917 //retrieve the arguments of the old process
918 //FIXME: Factorise this with SIMIX_host_add_auto_restart_process ?
919 s_smx_process_arg_t arg;
920 arg.code = process->code;
921 arg.hostname = sg_host_name(process->smx_host);
922 arg.kill_time = process->kill_time;
923 arg.argc = process->argc;
924 arg.data = process->data;
926 arg.argv = xbt_new(char*,process->argc + 1);
927 for (i = 0; i < arg.argc; i++) {
928 arg.argv[i] = xbt_strdup(process->argv[i]);
930 arg.argv[process->argc] = NULL;
931 arg.properties = NULL;
932 arg.auto_restart = process->auto_restart;
933 //kill the old process
934 SIMIX_process_kill(process,issuer);
935 //start the new process
936 smx_process_t new_process;
937 if (simix_global->create_process_function) {
938 simix_global->create_process_function(&new_process,
950 simcall_process_create(&new_process,