+void SIMIX_process_killall(smx_process_t issuer)
+{
+ smx_process_t p = NULL;
+
+ while ((p = xbt_swag_extract(simix_global->process_list))) {
+ if (p != issuer) {
+ SIMIX_process_kill(p);
+ }
+ }
+
+ SIMIX_context_runall();
+
+ SIMIX_process_empty_trash();
+}
+
+void SIMIX_process_change_host(smx_process_t process,
+ smx_host_t dest)
+{
+ xbt_assert((process != NULL), "Invalid parameters");
+ xbt_swag_remove(process, process->smx_host->process_list);
+ process->smx_host = dest;
+ xbt_swag_insert(process, dest->process_list);
+}
+
+void SIMIX_pre_process_change_host(smx_process_t process, smx_host_t dest)
+{
+ process->new_host = dest;
+}
+
+void SIMIX_pre_process_suspend(smx_simcall_t simcall)
+{
+ smx_process_t process = simcall->process_suspend.process;
+ smx_action_t action_suspend =
+ SIMIX_process_suspend(process, simcall->issuer);
+
+ if (process != simcall->issuer) {
+ SIMIX_simcall_answer(simcall);
+ } else {
+ xbt_fifo_push(action_suspend->simcalls, simcall);
+ process->waiting_action = action_suspend;
+ SIMIX_host_execution_suspend(process->waiting_action);
+ }
+ /* If we are suspending ourselves, then just do not finish the simcall now */
+}
+
+smx_action_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
+{
+ xbt_assert((process != NULL), "Invalid parameters");
+
+ if (process->suspended) {
+ XBT_DEBUG("Process '%s' is already suspended", process->name);
+ return NULL;
+ }
+
+ process->suspended = 1;
+
+ /* If we are suspending another process, and it is waiting on an action,
+ suspend its action. */
+ if (process != issuer) {
+
+ if (process->waiting_action) {
+
+ switch (process->waiting_action->type) {
+
+ case SIMIX_ACTION_EXECUTE:
+ case SIMIX_ACTION_PARALLEL_EXECUTE:
+ SIMIX_host_execution_suspend(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_COMMUNICATE:
+ SIMIX_comm_suspend(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_SLEEP:
+ SIMIX_process_sleep_suspend(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_SYNCHRO:
+ /* Suspension is delayed to when the process is rescheduled. */
+ break;
+
+ default:
+ xbt_die("Internal error in SIMIX_process_suspend: unexpected action type %d",
+ (int)process->waiting_action->type);
+ }
+ return NULL;
+ } else {
+ /* Suspension is delayed to when the process is rescheduled. */
+ return NULL;
+ }
+ } else {
+ return SIMIX_host_execute("suspend", process->smx_host, 0.0, 1.0);
+ }
+}
+
+void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
+{
+ xbt_assert((process != NULL), "Invalid parameters");
+
+ XBT_IN("process = %p, issuer = %p", process, issuer);
+
+ if(process->context->iwannadie) {
+ XBT_VERB("Ignoring request to suspend a process that is currently dying.");
+ return;
+ }
+
+ if(!process->suspended) return;
+ process->suspended = 0;
+
+ /* If we are resuming another process, resume the action it was waiting for
+ if any. Otherwise add it to the list of process to run in the next round. */
+ if (process != issuer) {
+
+ if (process->waiting_action) {
+
+ switch (process->waiting_action->type) {
+
+ case SIMIX_ACTION_EXECUTE:
+ case SIMIX_ACTION_PARALLEL_EXECUTE:
+ SIMIX_host_execution_resume(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_COMMUNICATE:
+ SIMIX_comm_resume(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_SLEEP:
+ SIMIX_process_sleep_resume(process->waiting_action);
+ break;
+
+ case SIMIX_ACTION_SYNCHRO:
+ /* I cannot resume it now. This is delayed to when the process is rescheduled at
+ * the end of the synchro. */
+ break;
+
+ default:
+ xbt_die("Internal error in SIMIX_process_resume: unexpected action type %d",
+ (int)process->waiting_action->type);
+ }
+ }
+ } else XBT_WARN("Strange. Process %p is trying to resume himself.", issuer);
+
+ XBT_OUT();
+}
+
+int SIMIX_process_get_maxpid(void) {
+ return simix_process_maxpid;
+}
+
+int SIMIX_process_count(void)
+{
+ return xbt_swag_size(simix_global->process_list);
+}
+
+void* SIMIX_process_self_get_data(smx_process_t self)
+{
+ xbt_assert(self == SIMIX_process_self(), "This is not the current process");
+
+ if (!self) {
+ return NULL;
+ }
+ return SIMIX_process_get_data(self);
+}
+
+void SIMIX_process_self_set_data(smx_process_t self, void *data)
+{
+ xbt_assert(self == SIMIX_process_self(), "This is not the current process");
+
+ SIMIX_process_set_data(self, data);
+}
+
+void* SIMIX_process_get_data(smx_process_t process)
+{
+ return process->data;
+}
+
+void SIMIX_process_set_data(smx_process_t process, void *data)
+{
+ process->data = data;
+}
+