*/
smx_process_t SIMIX_process_create(const char *name,
smx_process_code_t code, void *data,
- smx_host_t host)
+ const char * hostname, void * clean_process_function)
{
- return SIMIX_process_create_with_arguments(name, code, data, host, -1, NULL);
+ return SIMIX_process_create_with_arguments(name, code, data, hostname, -1, NULL, clean_process_function);
}
-static void SIMIX_process_cleanup(void *arg)
+void SIMIX_process_cleanup(void *arg)
{
xbt_swag_remove(arg, simix_global->process_list);
xbt_swag_remove(arg, simix_global->process_to_run);
xbt_swag_remove(arg, ((smx_process_t) arg)->simdata->host->simdata->process_list);
free(((smx_process_t) arg)->name);
((smx_process_t) arg)->name = NULL;
+
free(((smx_process_t) arg)->simdata);
((smx_process_t) arg)->simdata = NULL;
free(arg);
*/
smx_process_t SIMIX_process_create_with_arguments(const char *name,
smx_process_code_t code, void *data,
- smx_host_t host, int argc, char **argv)
+ const char * hostname, int argc, char **argv, void * clean_process_function)
{
- simdata_process_t simdata = xbt_new0(s_simdata_process_t,1);
+ smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t,1);
smx_process_t process = xbt_new0(s_smx_process_t,1);
smx_process_t self = NULL;
+ smx_host_t host = SIMIX_host_get_by_name(hostname);
xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
/* Simulator Data */
simdata->host = host;
simdata->argc = argc;
simdata->argv = argv;
- simdata->context = xbt_context_new(code, NULL, NULL,
- SIMIX_process_cleanup, process,
- simdata->argc, simdata->argv);
-
+ if (clean_process_function) {
+ simdata->context = xbt_context_new(code, NULL, NULL,
+ clean_process_function, process,
+ simdata->argc, simdata->argv);
+ }
+ else {
+ simdata->context = xbt_context_new(code, NULL, NULL,
+ SIMIX_process_cleanup, process,
+ simdata->argc, simdata->argv);
+ }
//simdata->last_errno=SIMIX_OK;
return process;
}
+
+
+
/** \ingroup m_process_management
* \param process poor victim
*
void SIMIX_process_kill(smx_process_t process)
{
//int i;
- simdata_process_t p_simdata = process->simdata;
+ smx_simdata_process_t p_simdata = process->simdata;
//simdata_host_t h_simdata= p_simdata->host->simdata;
//int _cursor;
//smx_process_t proc = NULL;
DEBUG2("Killing %s on %s",process->name, p_simdata->host->name);
+ if (p_simdata->mutex) {
+ xbt_swag_remove(process,p_simdata->mutex->sleeping);
+ }
+ if (p_simdata->cond) {
+ xbt_swag_remove(process,p_simdata->cond->sleeping);
+ }
/*
if(p_simdata->waiting_task) {
*/
xbt_swag_remove(process,simix_global->process_to_run);
xbt_swag_remove(process,simix_global->process_list);
- xbt_context_free(process->simdata->context);
+ xbt_context_kill(process->simdata->context);
if(process==SIMIX_process_self()) {
/* I just killed myself */
}
}
-/** \ingroup m_process_management
- * \brief Migrates an agent to another location.
- *
- * This functions checks whether \a process and \a host are valid pointers
- and change the value of the #m_host_t on which \a process is running.
- */
-void SIMIX_process_change_host(smx_process_t process, smx_host_t host)
-{
- simdata_process_t simdata = NULL;
-
- /* Sanity check */
-
- xbt_assert0(((process) && (process->simdata)
- && (host)), "Invalid parameters");
- simdata = process->simdata;
-
- xbt_swag_remove(process,simdata->host->simdata->process_list);
- simdata->host = host;
- xbt_swag_insert(process,host->simdata->process_list);
-
- return ;
-}
-
/** \ingroup m_process_management
* \brief Return the user data of a #m_process_t.
*
*/
void SIMIX_process_suspend(smx_process_t process)
{
- simdata_process_t simdata = NULL;
+ smx_simdata_process_t simdata = NULL;
xbt_assert0(((process) && (process->simdata)), "Invalid parameters");
surf_workstation_resource->common_public->suspend(act->simdata->surf_action);
}
}
- else if (simdata->block_action) {
+ else {
simdata->suspended = 1;
}
- else xbt_assert0(0, "Unknown process status");
-
}
else {
/* process executing, I can create an action and suspend it */
process->simdata->suspended = 1;
- __SIMIX_process_block(-1);
- process->simdata->suspended = 0;
-
+ smx_action_t dummy;
+ smx_cond_t cond;
+ char name[] = "dummy";
+
+ cond = SIMIX_cond_init();
+ dummy = SIMIX_action_execute(SIMIX_process_get_host(process), name, 0);
+ surf_workstation_resource->common_public->set_priority(dummy->simdata->surf_action,0.0);
+ SIMIX_register_condition_to_action(dummy,cond);
+ SIMIX_register_action_to_condition(dummy,cond);
+ __SIMIX_cond_wait(cond);
+ //SIMIX_action_destroy(dummy);
+ //SIMIX_cond_destroy(cond);
}
return ;
}
*/
void SIMIX_process_resume(smx_process_t process)
{
- simdata_process_t simdata = NULL;
+ smx_simdata_process_t simdata = NULL;
xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
CHECK_HOST();
}
return;
}
- else if (simdata->block_action){
+ else {
simdata->suspended = 0;
- surf_workstation_resource->common_public->resume(simdata->block_action->simdata->surf_action);
- return;
+ xbt_swag_insert(process,simix_global->process_to_run);
}
- else xbt_assert0(0, "Unknown status");
}
return (process->simdata->suspended);
}
-int __SIMIX_process_block(double max_duration)
-{
-
- smx_process_t process = SIMIX_process_self();
- smx_action_t dummy = NULL;
- char name[] = "dummy";
-
- dummy = SIMIX_execute(SIMIX_process_get_host(process), name, 0);
- dummy->simdata->action_block=1;
-
- /* process which will wake up when this system action finish */
- dummy->simdata->cond_process = process;
-
- process->simdata->block_action = dummy;
-
- process->simdata->blocked=1;
- surf_workstation_resource->common_public->suspend(dummy->simdata->surf_action);
- if(max_duration>=0) {
- surf_workstation_resource->common_public->set_max_duration(dummy->simdata->surf_action,
- max_duration);
- dummy->simdata->timeout_cond = process->simdata->cond;
- }
- __SIMIX_wait_for_action(process,dummy);
- SIMIX_action_destroy(dummy);
- process->simdata->blocked=0;
-
- if(process->simdata->suspended) {
- DEBUG0("I've been suspended in the meantime");
- SIMIX_process_suspend(process);
- DEBUG0("I've been resumed, let's keep going");
- }
-
- return 1;
-}
-
-void __SIMIX_process_unblock(smx_process_t process)
-{
- simdata_process_t simdata = NULL;
- simdata_action_t simdata_action = NULL;
-
- xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
-
- simdata = process->simdata;
-
- if(!(simdata->block_action)) {
- xbt_assert0(0,"Process is not blocked !");
- return;
- }
-
- simdata_action = simdata->block_action->simdata;
- xbt_assert0(simdata->blocked,"Process not blocked");
- surf_workstation_resource->common_public->resume(simdata_action->surf_action);
- return ;
-
-/*
- simdata_process_t simdata = NULL;
- simdata_task_t simdata_task = NULL;
-
- xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
- CHECK_HOST();
-
- XBT_IN2(": %s unblocking %s", SIMIX_process_self()->name,process->name);
-
- simdata = process->simdata;
- if(!(simdata->waiting_task)) {
- xbt_assert0(0,"Process not waiting for anything else. Weird !");
- XBT_OUT;
- return SIMIX_WARNING;
- }
- simdata_task = simdata->waiting_task->simdata;
-
- xbt_assert0(simdata->blocked,"Process not blocked");
-
- surf_workstation_resource->common_public->resume(simdata_task->compute);
-
- XBT_OUT;
-*/
-}
-
-int __SIMIX_process_isBlocked(smx_process_t process)
-{
- xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
-
- return (process->simdata->blocked);
-}