Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New functions added, changes in the header files, function create_link(cond, action...
authordonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 5 Mar 2007 14:57:06 +0000 (14:57 +0000)
committerdonassbr <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 5 Mar 2007 14:57:06 +0000 (14:57 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3198 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/simix/simix.h
src/simix/private.h
src/simix/smx_action.c
src/simix/smx_global.c
src/simix/smx_host.c
src/simix/smx_process.c
src/simix/smx_synchro.c

index ed51809..20a656d 100644 (file)
@@ -86,16 +86,17 @@ XBT_PUBLIC(void) SIMIX_cond_signal(smx_cond_t cond);
 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);
 
index 710abc5..6ee5adb 100644 (file)
@@ -81,7 +81,7 @@ typedef struct s_smx_mutex {
 
 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;
@@ -93,10 +93,10 @@ typedef struct s_simdata_action {
   
   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 !!!! *******/
@@ -137,7 +137,7 @@ extern xbt_cfg_t _simix_cfg_set;
 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);
 
index 8be954c..dc09c63 100644 (file)
@@ -14,35 +14,93 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix,
 
 /************************************* 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)
index 9d33dde..e8c5bee 100644 (file)
@@ -75,7 +75,7 @@ void __SIMIX_display_process_status(void)
        
       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] ":""));
       
@@ -128,8 +128,8 @@ SIMIX_error_t SIMIX_main(void)
                                        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;
                }
 
@@ -289,7 +289,6 @@ SIMIX_error_t SIMIX_clean(void)
   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();
index 14ccdc5..b1f1b79 100644 (file)
@@ -41,7 +41,7 @@ smx_host_t __SIMIX_host_create(const char *name,
 
   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);
@@ -121,7 +121,7 @@ void __SIMIX_host_destroy(smx_host_t 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");
index 3f17ace..25c5801 100644 (file)
@@ -99,17 +99,17 @@ smx_process_t SIMIX_process_create_with_arguments(const char *name,
   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;
 }
@@ -182,7 +182,7 @@ SIMIX_error_t SIMIX_process_change_host(smx_process_t process, smx_host_t host)
 
   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;
 }
@@ -263,6 +263,7 @@ SIMIX_error_t SIMIX_process_suspend(smx_process_t process)
 {
   simdata_process_t simdata = NULL;
        smx_action_t dummy;
+       char name[] = "dummy";
        
   xbt_assert0(((process) && (process->simdata)), "Invalid parameters");
 
@@ -296,7 +297,7 @@ SIMIX_error_t SIMIX_process_suspend(smx_process_t process)
   }
        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;
@@ -367,13 +368,14 @@ int SIMIX_process_is_suspended(smx_process_t process)
   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;
index a15d28c..fa4d4d9 100644 (file)
@@ -37,7 +37,7 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
                /* 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;
        }
@@ -92,30 +92,99 @@ SIMIX_error_t SIMIX_mutex_destroy(smx_mutex_t mutex)
 /******************************** 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);
+}
+
+