X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/07c319ec54d6fc778ee3cc5e75a747242006723e..3a04e753eda34fd4f9879f943076ccd149d879e8:/src/simix/smx_process.c diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 7272966d0f..136a1f68c0 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -9,11 +9,26 @@ #include "xbt/log.h" #include "xbt/dict.h" #include "msg/mailbox.h" +#include "mc/mc.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)"); -static unsigned long simix_process_count = 0; +unsigned long simix_process_maxpid = 0; + +/** + * \brief Returns the current agent. + * + * This functions returns the currently running SIMIX process. + * + * \return The SIMIX process + */ +XBT_INLINE smx_process_t SIMIX_process_self(void) +{ + smx_context_t self_context = SIMIX_context_self(); + + return self_context ? SIMIX_context_get_data(self_context) : NULL; +} /** * \brief Move a process to the list of processes to destroy. @@ -21,7 +36,7 @@ static unsigned long simix_process_count = 0; void SIMIX_process_cleanup(smx_process_t process) { DEBUG1("Cleanup process %s", process->name); - xbt_swag_remove(process, simix_global->process_to_run); + /*xbt_swag_remove(process, simix_global->process_to_run);*/ xbt_swag_remove(process, simix_global->process_list); xbt_swag_remove(process, process->smx_host->process_list); xbt_swag_insert(process, simix_global->process_to_destroy); @@ -58,18 +73,17 @@ void SIMIX_process_empty_trash(void) void SIMIX_create_maestro_process() { smx_process_t maestro = NULL; - + /* Create maestro process and intilialize it */ maestro = xbt_new0(s_smx_process_t, 1); - maestro->pid = simix_process_count++; + maestro->pid = simix_process_maxpid++; maestro->name = (char *) ""; maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1); XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx); maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro); + maestro->request.issuer = maestro; simix_global->maestro_process = maestro; - simix_global->current_process = maestro; - return; } @@ -116,10 +130,10 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) { */ smx_process_t SIMIX_process_create(const char *name, xbt_main_func_t code, - void *data, - const char *hostname, - int argc, char **argv, - xbt_dict_t properties) { + void *data, + const char *hostname, + int argc, char **argv, + xbt_dict_t properties) { smx_process_t process = NULL; smx_host_t host = SIMIX_host_get_by_name(hostname); @@ -136,10 +150,9 @@ smx_process_t SIMIX_process_create(const char *name, xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters"); /* Process data */ - process->pid = simix_process_count++; + process->pid = simix_process_maxpid++; process->name = xbt_strdup(name); process->smx_host = host; - process->iwannadie = 0; process->data = data; VERB1("Create context %s", process->name); @@ -160,7 +173,7 @@ smx_process_t SIMIX_process_create(const char *name, /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(process, simix_global->process_list); DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name); - xbt_swag_insert(process, simix_global->process_to_run); + xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); } return process; @@ -178,11 +191,11 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) { DEBUG2("Killing process %s on %s", process->name, process->smx_host->name); - process->iwannadie = 1; + process->context->iwannadie = 1; process->blocked = 0; process->suspended = 0; /* FIXME: set doexception to 0 also? */ - + if (process->waiting_action) { switch (process->waiting_action->type) { @@ -201,7 +214,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) { break; case SIMIX_ACTION_SYNCHRO: - SIMIX_synchro_stop_waiting(process, process->request); + SIMIX_synchro_stop_waiting(process, &process->request); SIMIX_synchro_destroy(process->waiting_action); break; @@ -216,7 +229,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) { SIMIX_context_stop(process->context); } else { - xbt_swag_insert(process, simix_global->process_to_run); + xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); } } @@ -232,6 +245,7 @@ void SIMIX_process_killall(void) while ((p = xbt_swag_extract(simix_global->process_list))) SIMIX_process_kill(p, SIMIX_process_self()); + SIMIX_context_runall(simix_global->process_to_run); SIMIX_process_empty_trash(); } @@ -305,30 +319,34 @@ void SIMIX_process_resume(smx_process_t process, smx_process_t issuer) if (process->waiting_action) { - switch(process->waiting_action->type) { + 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; - + default: THROW_IMPOSSIBLE; } - } else { - xbt_swag_insert(process, simix_global->process_to_run); + } + else { + xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process); } } } +int SIMIX_process_get_maxpid(void) { + return simix_process_maxpid; +} int SIMIX_process_count(void) { return xbt_swag_size(simix_global->process_list); @@ -386,7 +404,7 @@ int SIMIX_process_is_suspended(smx_process_t process) int SIMIX_process_is_enabled(smx_process_t process) { - if(process->request && SIMIX_request_isEnabled(process->request)) + if (process->request.call != REQ_NO_REQ && SIMIX_request_is_enabled(&process->request)) return TRUE; return FALSE; @@ -399,12 +417,10 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process) void SIMIX_pre_process_sleep(smx_req_t req) { -#ifdef HAVE_MC - if(_surf_do_model_check){ + if (MC_IS_ENABLED) { req->process_sleep.result = SIMIX_DONE; SIMIX_request_answer(req); } -#endif smx_action_t action = SIMIX_process_sleep(req->issuer, req->process_sleep.duration); xbt_fifo_push(action->request_list, req); req->issuer->waiting_action = action; @@ -462,7 +478,7 @@ void SIMIX_process_sleep_destroy(smx_action_t action) if (action->sleep.surf_sleep) action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep); #ifdef HAVE_TRACING - TRACE_smx_action_destroy(act); + TRACE_smx_action_destroy(action); #endif xbt_fifo_free(action->request_list); xbt_free(action); @@ -478,20 +494,6 @@ void SIMIX_process_sleep_resume(smx_action_t action) surf_workstation_model->resume(action->sleep.surf_sleep); } -/** - * \brief Returns the current agent. - * - * This functions returns the currently running SIMIX process. - * - * \return The SIMIX process - */ -XBT_INLINE smx_process_t SIMIX_process_self(void) -{ - if(simix_global) - return SIMIX_context_self(); - return NULL; -} - /** * Calling this function makes the process to yield. * Only the processes can call this function, giving back the control to maestro @@ -499,16 +501,16 @@ XBT_INLINE smx_process_t SIMIX_process_self(void) void SIMIX_process_yield(void) { smx_process_t self = SIMIX_process_self(); - + DEBUG1("Yield process '%s'", self->name); - + /* Go into sleep and return control to maestro */ SIMIX_context_suspend(self->context); /* Ok, maestro returned control to us */ DEBUG1("Maestro returned control to me: '%s'", self->name); - - if (self->iwannadie) + + if (self->context->iwannadie) SIMIX_context_stop(self->context); if (self->doexception) { @@ -521,7 +523,7 @@ void SIMIX_process_yield(void) /* callback: context fetching */ xbt_running_ctx_t *SIMIX_process_get_running_context(void) { - return simix_global->current_process->running_ctx; + return SIMIX_process_self()->running_ctx; } /* callback: termination */ @@ -530,3 +532,10 @@ void SIMIX_process_exception_terminate(xbt_ex_t * e) xbt_ex_display(e); abort(); } + +smx_context_t SIMIX_process_get_context(smx_process_t p) { + return p->context; +} +void SIMIX_process_set_context(smx_process_t p,smx_context_t c) { + p->context = c; +}