XBT_PUBLIC(void) SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex);
XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration);
XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond);
-XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond);
+XBT_PUBLIC(SIMIX_error_t) SIMIX_cond_destroy(smx_cond_t cond);
/************************** Action handling ************************************/
-XBT_PUBLIC(smx_action_t) SIMIX_communicate(smx_host_t sender,smx_host_t receiver, double size);
-XBT_PUBLIC(smx_action_t) SIMIX_execute(smx_host_t host,double amount);
+XBT_PUBLIC(smx_action_t) SIMIX_communicate(smx_host_t sender,smx_host_t receiver, char *name, double size, double rate);
+XBT_PUBLIC(smx_action_t) SIMIX_execute(smx_host_t host,char *name, double amount);
XBT_PUBLIC(SIMIX_error_t) SIMIX_action_cancel(smx_action_t action);
XBT_PUBLIC(void) SIMIX_action_set_priority(smx_action_t action, double priority);
XBT_PUBLIC(SIMIX_error_t) SIMIX_action_destroy(smx_action_t action);
-XBT_PUBLIC(void) SIMIX_create_link(smx_action_t action, smx_cond_t cond);
+XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond);
+XBT_PUBLIC(void) SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond);
//SIMIX_action_wait_for_computation(smx_process_t process, smx_action_t action);
typedef struct s_smx_cond {
xbt_swag_t sleeping; /* list of sleeping process */
- s_smx_mutex_t * mutex;
+ smx_mutex_t mutex;
xbt_fifo_t actions; /* list of actions */
} s_smx_cond_t;
xbt_fifo_t cond_list; /* conditional variables that must be signaled when the action finish. */
smx_host_t source;
-
+/*
double priority;
double rate;
-
+*/
/*int using;*/
/******* Parallel Tasks Only !!!! *******/
smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);
void __SIMIX_host_destroy(smx_host_t host);
-int __SIMIX_process_block(double max_duration, const char *info);
+int __SIMIX_process_block(double max_duration);
SIMIX_error_t __SIMIX_process_unblock(smx_process_t process);
int __SIMIX_process_isBlocked(smx_process_t process);
/************************************* Actions *********************************/
-smx_action_t SIMIX_communicate(smx_host_t sender,smx_host_t receiver, double size)
+smx_action_t SIMIX_communicate(smx_host_t sender,smx_host_t receiver,char * name, double size, double rate)
{
- return xbt_new0(s_smx_action_t,1);
+
+ /* alloc structures */
+ smx_action_t act = xbt_new0(s_smx_action_t,1);
+ act->simdata = xbt_new0(s_simdata_action_t,1);
+ simdata_action_t simdata = act->simdata;
+ simdata->cond_list = xbt_fifo_new();
+
+ /* initialize them */
+ act-> name = xbt_strdup(name);
+
+
+
+ simdata->surf_action = surf_workstation_resource->extension_public->
+ communicate(sender->simdata->host,
+ receiver->simdata->host, size, rate);
+ surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act);
+
+ return act;
}
-smx_action_t SIMIX_execute(smx_host_t host,double amount)
+smx_action_t SIMIX_execute(smx_host_t host, char * name, double amount)
{
- return xbt_new0(s_smx_action_t,1);
+ CHECK_HOST();
+ /* alloc structures */
+ smx_action_t act = xbt_new0(s_smx_action_t,1);
+ act->simdata = xbt_new0(s_simdata_action_t,1);
+ simdata_action_t simdata = act->simdata;
+ simdata->cond_list = xbt_fifo_new();
+
+ /* initialize them */
+ simdata->source = host;
+ act-> name = xbt_strdup(name);
+
+ /* set communication */
+ simdata->surf_action = surf_workstation_resource->extension_public->
+ execute(host->simdata->host, amount);
+
+ surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act);
+
+ return act;
}
SIMIX_error_t SIMIX_action_cancel(smx_action_t action)
{
+ xbt_assert0((action != NULL), "Invalid parameter");
- return SIMIX_OK;
+ if(action->simdata->surf_action) {
+ surf_workstation_resource->common_public->action_cancel(action->simdata->surf_action);
+ return SIMIX_OK;
+ }
+ return SIMIX_FATAL;
}
void SIMIX_action_set_priority(smx_action_t action, double priority)
{
+ xbt_assert0( (action != NULL) && (action->simdata != NULL), "Invalid parameter" );
+
+ surf_workstation_resource->common_public->
+ set_priority(action->simdata->surf_action, priority);
return;
}
SIMIX_error_t SIMIX_action_destroy(smx_action_t action)
{
+
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ xbt_assert0((xbt_fifo_size(action->simdata->cond_list)==0),
+ "Conditional list not empty. There is a problem. Cannot destroy it now!");
+
+ if(action->name) free(action->name);
+
+ xbt_fifo_free(action->simdata->cond_list);
+
+ if(action->simdata->surf_action)
+ action->simdata->surf_action->resource_type->common_public->action_free(action->simdata->surf_action);
+
return SIMIX_OK;
}
-void SIMIX_create_link(smx_action_t action, smx_cond_t cond)
+void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond)
{
+ xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");
+ xbt_fifo_push(cond->actions,action);
}
SIMIX_error_t __SIMIX_wait_for_action(smx_process_t process, smx_action_t action)
asprintf(&who,"SIMIX: %s on %s: %s",
process->name,
- p_simdata->host->name,
+ p_simdata->host->name,
(process->simdata->blocked)?"[blocked] "
:((process->simdata->suspended)?"[suspended] ":""));
process->name,
process->simdata->host->name);
simix_global->current_process = process;
- /* fflush(NULL); */
xbt_context_schedule(process->simdata->context);
+ /* fflush(NULL); */
simix_global->current_process = NULL;
}
xbt_swag_free(simix_global->process_to_run);
xbt_swag_free(simix_global->process_list);
xbt_dict_free(&(simix_global->registered_functions));
-
simix_config_finalize();
free(simix_global);
surf_exit();
simdata->host = workstation;
- simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, process_hookup));
+ simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
/* Update global variables */
xbt_fifo_unshift(simix_global->host, host);
/* Clean Simulator data */
- simdata = (host)->simdata;
+ simdata = host->simdata;
xbt_assert0((xbt_swag_size(simdata->process_list)==0),
"Some process are still running on this host");
process->simdata = simdata;
process->data = data;
- xbt_swag_insert_at_head(process, host->simdata->process_list);
+ xbt_swag_insert(process, host->simdata->process_list);
/* *************** FIX du current_process !!! *************** */
self = simix_global->current_process;
xbt_context_start(process->simdata->context);
simix_global->current_process = self;
- xbt_swag_insert_at_head(process,simix_global->process_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_at_head(process,simix_global->process_to_run);
+ xbt_swag_insert(process,simix_global->process_to_run);
return process;
}
xbt_swag_remove(process,simdata->host->simdata->process_list);
simdata->host = host;
- xbt_swag_insert_at_head(process,host->simdata->process_list);
+ xbt_swag_insert(process,host->simdata->process_list);
return SIMIX_OK;
}
{
simdata_process_t simdata = NULL;
smx_action_t dummy;
+ char name[] = "dummy";
xbt_assert0(((process) && (process->simdata)), "Invalid parameters");
}
else {
/* process executing, I can create an action and suspend it */
- dummy = SIMIX_execute(SIMIX_process_get_host(process)->simdata->host, 0);
+ dummy = SIMIX_execute(SIMIX_process_get_host(process)->simdata->host, name, 0);
process->simdata->block_action = dummy;
process->simdata->suspended = 1;
return (process->simdata->suspended);
}
-int __SIMIX_process_block(double max_duration, const char *info)
+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)->simdata->host, 0);
+ dummy = SIMIX_execute(SIMIX_process_get_host(process)->simdata->host, name, 0);
process->simdata->block_action = dummy;
process->simdata->blocked=1;
/* somebody using the mutex, block */
xbt_swag_insert(self, mutex->sleeping);
self->simdata->mutex = mutex;
- __SIMIX_process_block(-1,"");
+ __SIMIX_process_block(-1);
self->simdata->mutex = NULL;
mutex->using = 1;
}
/******************************** Conditional *********************************/
smx_cond_t SIMIX_cond_init()
{
- return xbt_new0(s_smx_cond_t,1);
+ smx_cond_t cond = xbt_new0(s_smx_cond_t,1);
+ s_smx_process_t p;
+
+ cond->sleeping = xbt_swag_new(xbt_swag_offset(p,synchro_hookup));
+ cond->actions = xbt_fifo_new();
+ cond->mutex = NULL;
+ return cond;
}
void SIMIX_cond_signal(smx_cond_t cond)
{
+ xbt_assert0((cond != NULL), "Invalid parameters");
+ smx_process_t proc = NULL;
+
+ if (xbt_swag_size(cond->sleeping) >= 1) {
+ proc = xbt_swag_extract(cond->sleeping);
+ __SIMIX_process_unblock(proc);
+ }
+
return;
}
void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex)
{
+ /* call the function with timeout, with max_duration > 0
+ * the process is blocked forever */
+ SIMIX_cond_wait_timeout(cond, mutex, -1);
return;
}
void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration)
{
+ smx_process_t self = SIMIX_process_self();
+
+ xbt_assert0((mutex != NULL), "Invalid parameters");
+
+ /* process status */
+ self->simdata->cond = cond;
+
+ xbt_swag_insert(self, cond->sleeping);
+ cond->mutex = mutex;
+
+ SIMIX_mutex_unlock(mutex);
+ /* if the max_duration < 0, blocks forever */
+ if (max_duration >=0) {
+ __SIMIX_process_block(max_duration);
+ self->simdata->cond = NULL;
+ }
+ else {
+ __SIMIX_process_block(-1);
+ self->simdata->cond = NULL;
+ }
+ /* get the mutex again */
+ SIMIX_mutex_lock(cond->mutex);
return;
}
+
void SIMIX_cond_broadcast(smx_cond_t cond)
{
+ xbt_assert0((cond != NULL), "Invalid parameters");
+ smx_process_t proc = NULL;
+ smx_process_t proc_next = NULL;
+
+ xbt_swag_foreach_safe(proc,proc_next,cond->sleeping) {
+ __SIMIX_process_unblock(proc);
+ xbt_swag_remove(proc,cond->sleeping);
+ }
+
return;
}
-void SIMIX_cond_destroy(smx_cond_t cond)
+SIMIX_error_t SIMIX_cond_destroy(smx_cond_t cond)
{
- return;
+
+ if ( cond == NULL )
+ return SIMIX_WARNING;
+ else {
+ xbt_assert0( (xbt_swag_size(cond->sleeping) > 0) &&
+ (xbt_fifo_size(cond->actions) > 0), "Cannot destroy conditional");
+
+ xbt_swag_free(cond->sleeping);
+ xbt_fifo_free(cond->actions);
+ xbt_free(cond);
+ return SIMIX_OK;
+ }
}
+
+void SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond)
+{
+ xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters");
+
+ xbt_fifo_push(action->simdata->cond_list,cond);
+}
+
+