-{
- smx_simdata_process_t p_simdata = process->simdata;
-
- DEBUG2("Killing process %s on %s",process->name, p_simdata->s_host->name);
-
- /* Cleanup if we were waiting for something */
- if (p_simdata->mutex)
- xbt_swag_remove(process,p_simdata->mutex->sleeping);
-
- if (p_simdata->cond)
- xbt_swag_remove(process,p_simdata->cond->sleeping);
-
- xbt_swag_remove(process, simix_global->process_to_run);
- xbt_swag_remove(process, simix_global->process_list);
- xbt_context_kill(process->simdata->context);
-
- if(process==SIMIX_process_self()) {
- /* I just killed myself */
- xbt_context_yield();
- }
+{
+ DEBUG2("Killing process %s on %s", process->name, process->smx_host->name);
+
+ process->iwannadie = 1;
+
+ /* If I'm killing myself then stop otherwise schedule the process to kill
+ * Two different behaviors, if I'm killing my self, remove from mutex and condition and stop. Otherwise, first we must schedule the process, wait its ending and after remove it from mutex and condition */
+ if (process == SIMIX_process_self()) {
+ /* Cleanup if we were waiting for something */
+ if (process->mutex)
+ xbt_swag_remove(process, process->mutex->sleeping);
+
+ if (process->cond)
+ xbt_swag_remove(process, process->cond->sleeping);
+ if (process->waiting_action) {
+ SIMIX_unregister_action_to_condition(process->waiting_action, process->cond);
+ SIMIX_action_destroy(process->waiting_action);
+ }
+
+ if (process->sem) {
+ xbt_swag_remove(process, process->sem->sleeping);
+
+ if (process->waiting_action) {
+ SIMIX_unregister_action_to_semaphore(process->waiting_action, process->sem);
+ SIMIX_action_destroy(process->waiting_action);
+ }
+ }
+
+ SIMIX_context_stop(process->context);
+
+ } else {
+ DEBUG4("%s(%p) here! killing %s(%p)",
+ simix_global->current_process->name,simix_global->current_process,
+ process->name,process);
+
+ /* Cleanup if it were waiting for something */
+ if (process->mutex) {
+ xbt_swag_remove(process, process->mutex->sleeping);
+ process->mutex = NULL;
+ }
+
+ if (process->cond) {
+ xbt_swag_remove(process, process->cond->sleeping);
+
+ if (process->waiting_action) {
+ SIMIX_unregister_action_to_condition(process->waiting_action, process->cond);
+ SIMIX_action_destroy(process->waiting_action);
+ }
+ process->cond = NULL;
+ }
+
+ if (process->sem) {
+ xbt_swag_remove(process, process->sem->sleeping);
+
+ if (process->waiting_action) {
+ SIMIX_unregister_action_to_semaphore(process->waiting_action, process->sem);
+ SIMIX_action_destroy(process->waiting_action);
+ }
+ process->sem = NULL;
+ }
+
+ /* make sure that the process gets awake soon enough, now that we've set its iwannadie to 1 */
+ process->blocked = 0;
+ process->suspended = 0;
+ xbt_swag_insert(process, simix_global->process_to_run);
+ }