--- rpl/src/instructions_v1.c 2013/02/27 17:11:44 1.49 +++ rpl/src/instructions_v1.c 2013/03/23 16:14:39 1.51 @@ -42,7 +42,7 @@ instruction_var(struct_processus *s_etat struct_objet *s_objet_resultat; struct_objet *s_objet_temporaire; - unsigned long nombre_colonnes; + integer8 nombre_colonnes; (*s_etat_processus).erreur_execution = d_ex; @@ -969,8 +969,8 @@ instruction_version(struct_processus *s_ void instruction_vars(struct_processus *s_etat_processus) { - int i; - int nb_variables; + integer8 i; + integer8 nb_variables; logical1 variable_partagee; @@ -1023,18 +1023,31 @@ instruction_vars(struct_processus *s_eta (*s_objet_resultat).objet = NULL; l_element_precedent = NULL; + if (pthread_mutex_lock(&mutex_liste_variables_partagees) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + nb_variables = nombre_variables(s_etat_processus); - if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables))) - == NULL) + if ((tableau = malloc(((size_t) nb_variables) * + sizeof(struct_tableau_variables))) == NULL) { liberation_mutexes_arbre_variables_partagees(s_etat_processus, (*(*s_etat_processus).s_arbre_variables_partagees)); + pthread_mutex_unlock(&mutex_liste_variables_partagees); (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - liste_variables(s_etat_processus, tableau); + nb_variables = liste_variables(s_etat_processus, tableau); + + if (pthread_mutex_unlock(&mutex_liste_variables_partagees) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } for(i = 0; i < nb_variables; i++) { @@ -1093,7 +1106,6 @@ instruction_vars(struct_processus *s_eta tableau[i].origine) == NULL) { // La variable partagée n'existe plus. - continue; } @@ -1122,6 +1134,12 @@ instruction_vars(struct_processus *s_eta } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1145,6 +1163,12 @@ instruction_vars(struct_processus *s_eta } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1171,6 +1195,12 @@ instruction_vars(struct_processus *s_eta } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1189,6 +1219,12 @@ instruction_vars(struct_processus *s_eta } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1215,6 +1251,12 @@ instruction_vars(struct_processus *s_eta } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1236,6 +1278,13 @@ instruction_vars(struct_processus *s_eta return; } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1243,6 +1292,13 @@ instruction_vars(struct_processus *s_eta if (pthread_mutex_unlock(&((*(*s_etat_processus) .pointeur_variable_partagee_courante).mutex)) != 0) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_processus; return; } @@ -1256,6 +1312,13 @@ instruction_vars(struct_processus *s_eta .donnee = copie_objet(s_etat_processus, tableau[i].objet, 'P')) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1269,6 +1332,12 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant) .suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1277,6 +1346,12 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant).suivant) .donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1290,6 +1365,13 @@ instruction_vars(struct_processus *s_eta .suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1315,7 +1397,14 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant) .suivant).donnee).objet = malloc(9 * sizeof(unsigned char))) == NULL) - { + { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1334,6 +1423,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1343,6 +1438,12 @@ instruction_vars(struct_processus *s_eta .suivant).donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1354,6 +1455,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1370,6 +1478,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee).objet = malloc(9 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1389,6 +1504,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1398,6 +1519,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1409,6 +1536,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1425,6 +1559,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).donnee).objet = malloc(8 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1444,6 +1585,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).suivant = NULL; l_element_precedent = l_element_courant; + + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } } free(tableau); @@ -1477,7 +1625,7 @@ instruction_visit(struct_processus *s_et struct_objet *s_objet; - unsigned long profondeur_initiale; + integer8 profondeur_initiale; (*s_etat_processus).erreur_execution = d_ex;