Diff for /rpl/src/gestion_variables.c between versions 1.64 and 1.65

version 1.64, 2012/12/13 16:59:41 version 1.65, 2012/12/17 21:22:43
Line 427  ajout_variable(struct_processus *s_etat_ Line 427  ajout_variable(struct_processus *s_etat_
   
         (*(*s_etat_processus).s_arbre_variables).feuille = NULL;          (*(*s_etat_processus).s_arbre_variables).feuille = NULL;
         (*(*s_etat_processus).s_arbre_variables).feuille_statique = NULL;          (*(*s_etat_processus).s_arbre_variables).feuille_statique = NULL;
         (*(*s_etat_processus).s_arbre_variables).feuille_partagee = NULL;  
         (*(*s_etat_processus).s_arbre_variables).noeuds_utilises = 0;          (*(*s_etat_processus).s_arbre_variables).noeuds_utilises = 0;
         (*(*s_etat_processus).s_arbre_variables).indice_tableau_pere = -1;          (*(*s_etat_processus).s_arbre_variables).indice_tableau_pere = -1;
         (*(*s_etat_processus).s_arbre_variables).noeud_pere = NULL;          (*(*s_etat_processus).s_arbre_variables).noeud_pere = NULL;
         INITIALISATION_MUTEX((*(*s_etat_processus).s_arbre_variables)  
                 .mutex_feuille_partagee);  
   
         if (((*(*s_etat_processus).s_arbre_variables).noeuds =          if (((*(*s_etat_processus).s_arbre_variables).noeuds =
                 allocation_tableau_noeuds(s_etat_processus)) == NULL)                  allocation_tableau_noeuds(s_etat_processus)) == NULL)
Line 483  ajout_variable(struct_processus *s_etat_ Line 480  ajout_variable(struct_processus *s_etat_
                     .pointeurs_caracteres_variables[*ptr]]).feuille_statique                      .pointeurs_caracteres_variables[*ptr]]).feuille_statique
                     = NULL;                      = NULL;
             (*(*l_variable_courante).noeuds[(*s_etat_processus)              (*(*l_variable_courante).noeuds[(*s_etat_processus)
                     .pointeurs_caracteres_variables[*ptr]]).feuille_partagee  
                     = NULL;  
             (*(*l_variable_courante).noeuds[(*s_etat_processus)  
                     .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises = 0;                      .pointeurs_caracteres_variables[*ptr]]).noeuds_utilises = 0;
             INITIALISATION_MUTEX((*(*l_variable_courante).noeuds  
                     [(*s_etat_processus).pointeurs_caracteres_variables[*ptr]])  
                     .mutex_feuille_partagee);  
   
             // Le champ noeud_pere de la structure créée pointe sur              // Le champ noeud_pere de la structure créée pointe sur
             // la structure parente et l'indice tableau_pere correspond à la              // la structure parente et l'indice tableau_pere correspond à la
Line 1306  retrait_variable(struct_processus *s_eta Line 1297  retrait_variable(struct_processus *s_eta
                     .feuille = NULL;                      .feuille = NULL;
   
             while(((*s_arbre_courant).noeuds_utilises == 0) &&              while(((*s_arbre_courant).noeuds_utilises == 0) &&
                     ((*s_arbre_courant).feuille_statique == NULL) &&                      ((*s_arbre_courant).feuille_statique == NULL))
                     ((*s_arbre_courant).feuille_partagee == NULL))  
             {              {
                 s_arbre_a_supprimer = s_arbre_courant;                  s_arbre_a_supprimer = s_arbre_courant;
                 s_arbre_courant = (*s_arbre_courant).noeud_pere;                  s_arbre_courant = (*s_arbre_courant).noeud_pere;
Line 1799  liberation_arbre_variables(struct_proces Line 1789  liberation_arbre_variables(struct_proces
 ================================================================================  ================================================================================
 */  */
   
 int  static int
 nombre_variables(struct_processus *s_etat_processus,  nombre_variables_locales(struct_processus *s_etat_processus,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
     int                                 i;      int                                 i;
Line 1809  nombre_variables(struct_processus *s_eta Line 1799  nombre_variables(struct_processus *s_eta
     struct_liste_variables              *l_variable;      struct_liste_variables              *l_variable;
     struct_liste_variables_statiques    *l_variable_statique;      struct_liste_variables_statiques    *l_variable_statique;
   
       if (l_element_courant == NULL)
       {
           return(0);
       }
   
     n = 0;      n = 0;
   
     if ((*l_element_courant).feuille != NULL)      if ((*l_element_courant).feuille != NULL)
Line 1844  nombre_variables(struct_processus *s_eta Line 1839  nombre_variables(struct_processus *s_eta
     {      {
         if ((*l_element_courant).noeuds[i] != NULL)          if ((*l_element_courant).noeuds[i] != NULL)
         {          {
             n += nombre_variables(s_etat_processus,              n += nombre_variables_locales(s_etat_processus,
                       (*l_element_courant).noeuds[i]);
           }
       }
   
       return(n);
   }
   
   
   static int
   nombre_variables_partagees(struct_processus *s_etat_processus,
           struct_arbre_variables_partagees *l_element_courant)
   {
       int                                 i;
       int                                 n;
   
       struct_liste_variables_partagees    *l_variable;
   
       if (l_element_courant == NULL)
       {
           return(0);
       }
   
       if (pthread_mutex_lock(&((*l_element_courant).mutex_feuille)) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_processus;
           return(0);
       }
   
       n = 0;
   
       if ((*l_element_courant).feuille != NULL)
       {
           l_variable = (*l_element_courant).feuille;
   
           do
           {
               n++;
               l_variable = (*l_variable).suivant;
           } while(l_variable != NULL);
       }
   
       for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
       {
           if ((*l_element_courant).noeuds[i] != NULL)
           {
               n += nombre_variables_partagees(s_etat_processus,
                     (*l_element_courant).noeuds[i]);                      (*l_element_courant).noeuds[i]);
         }          }
     }      }
Line 1854  nombre_variables(struct_processus *s_eta Line 1895  nombre_variables(struct_processus *s_eta
   
   
 int  int
 liste_variables(struct_processus *s_etat_processus,  nombre_variables(struct_processus *s_etat_processus)
   {
       return(nombre_variables_locales(s_etat_processus,
               (*s_etat_processus).s_arbre_variables)
               + nombre_variables_partagees(s_etat_processus,
               (*(*s_etat_processus).s_arbre_variables_partagees)));
   }
   
   
   void
   liberation_mutexes_arbre_variables_partagees(struct_processus *s_etat_processus,
           struct_arbre_variables_partagees *l_element_courant)
   {
       int                                 i;
   
       if (l_element_courant == NULL)
       {
           return;
       }
   
       if (pthread_mutex_trylock(&((*l_element_courant).mutex_feuille)) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_processus;
           return;
       }
   
       if (pthread_mutex_unlock(&((*l_element_courant).mutex_feuille)) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_processus;
           return;
       }
   
       for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
       {
           if ((*l_element_courant).noeuds[i] != NULL)
           {
               liberation_mutexes_arbre_variables_partagees(s_etat_processus,
                       (*l_element_courant).noeuds[i]);
           }
       }
   
       return;
   }
   
   
   static int
   liste_variables_locales(struct_processus *s_etat_processus,
         struct_tableau_variables *tableau, int position,          struct_tableau_variables *tableau, int position,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
Line 1863  liste_variables(struct_processus *s_etat Line 1950  liste_variables(struct_processus *s_etat
     struct_liste_variables              *l_variable;      struct_liste_variables              *l_variable;
     struct_liste_variables_statiques    *l_variable_statique;      struct_liste_variables_statiques    *l_variable_statique;
   
       if (l_element_courant == NULL)
       {
           return(0);
       }
   
     if ((*l_element_courant).feuille != NULL)      if ((*l_element_courant).feuille != NULL)
     {      {
         l_variable = (*l_element_courant).feuille;          l_variable = (*l_element_courant).feuille;
Line 1917  liste_variables(struct_processus *s_etat Line 2009  liste_variables(struct_processus *s_etat
     {      {
         if ((*l_element_courant).noeuds[i] != NULL)          if ((*l_element_courant).noeuds[i] != NULL)
         {          {
             position = liste_variables(s_etat_processus,              position = liste_variables_locales(s_etat_processus,
                       tableau, position, (*l_element_courant).noeuds[i]);
           }
       }
   
       return(position);
   }
   
   
   static int
   liste_variables_partagees(struct_processus *s_etat_processus,
           struct_tableau_variables *tableau, int position,
           struct_arbre_variables_partagees *l_element_courant)
   {
       int                                 i;
   
       struct_liste_variables_partagees    *l_variable;
   
       if (l_element_courant == NULL)
       {
           return(0);
       }
   
       if ((*l_element_courant).feuille != NULL)
       {
           l_variable = (*l_element_courant).feuille;
   
           do
           {
               tableau[position].origine = 'E';
               tableau[position].nom = (*(*l_variable).variable).nom;
               tableau[position].niveau = (*(*l_variable).variable).niveau;
               tableau[position].objet = (*(*l_variable).variable).objet;
               tableau[position].variable_verrouillee = d_faux;
               tableau[position].variable_partagee =
                       (*(*l_variable).variable).variable_partagee;
               tableau[position].variable_partagee.pointeur = NULL;
               tableau[position].variable_masquee = d_faux;
   
               position++;
   
               l_variable = (*l_variable).suivant;
           } while(l_variable != NULL);
       }
   
       for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++)
       {
           if ((*l_element_courant).noeuds[i] != NULL)
           {
               position = liste_variables_partagees(s_etat_processus,
                     tableau, position, (*l_element_courant).noeuds[i]);                      tableau, position, (*l_element_courant).noeuds[i]);
         }          }
     }      }
Line 1926  liste_variables(struct_processus *s_etat Line 2067  liste_variables(struct_processus *s_etat
 }  }
   
   
   static int
   fonction_ordre_variables(const void *argument_1, const void *argument_2)
   {
       int                         comparaison;
   
       struct_tableau_variables    *a1;
       struct_tableau_variables    *a2;
   
       a1 = (struct_tableau_variables *) argument_1;
       a2 = (struct_tableau_variables *) argument_2;
   
       comparaison = strcmp((*a1).nom, (*a2).nom);
   
       if (comparaison != 0)
       {
           return(comparaison);
       }
       else
       {
           return((*a1).niveau - (*a2).niveau);
       }
   }
   
   
   int
   liste_variables(struct_processus *s_etat_processus,
           struct_tableau_variables *tableau)
   {
       int     nombre_elements;
   
       nombre_elements = liste_variables_locales(s_etat_processus,
               tableau, 0, (*s_etat_processus).s_arbre_variables);
       nombre_elements += liste_variables_partagees(s_etat_processus,
               tableau, nombre_elements, (*(*s_etat_processus)
               .s_arbre_variables_partagees));
   
       qsort(tableau, nombre_elements, sizeof(struct_tableau_variables),
               fonction_ordre_variables);
   
       return(nombre_elements);
   }
   
   
 /*  /*
 ================================================================================  ================================================================================
   Procédure de copie de l'arbre des variables    Procédure de copie de l'arbre des variables

Removed from v.1.64  
changed lines
  Added in v.1.65


CVSweb interface <joel.bertrand@systella.fr>