--- rpl/src/instructions_m4.c 2011/09/14 17:55:59 1.31 +++ rpl/src/instructions_m4.c 2012/12/18 13:19:37 1.50 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.3 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.12 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -47,8 +47,6 @@ instruction_mem(struct_processus *s_etat struct_tableau_variables *tableau; - unsigned long i; - (*s_etat_processus).erreur_execution = d_ex; if ((*s_etat_processus).affichage_arguments == 'Y') @@ -144,18 +142,18 @@ instruction_mem(struct_processus *s_etat (*((integer8 *) (*((*((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant)).donnee)).objet)) = 0; - nb_variables = nombre_variables(s_etat_processus, - (*s_etat_processus).s_arbre_variables); + nb_variables = nombre_variables(s_etat_processus); if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables))) == NULL) { + liberation_mutexes_arbre_variables_partagees(s_etat_processus, + (*(*s_etat_processus).s_arbre_variables_partagees)); (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - liste_variables(s_etat_processus, tableau, 0, - (*s_etat_processus).s_arbre_variables); + liste_variables(s_etat_processus, tableau); for(j = 0; j < nb_variables; j++) { @@ -169,38 +167,6 @@ instruction_mem(struct_processus *s_etat free(tableau); - for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++) - { - // Comptabilisation des empreintes mémoire des variables - // statiques qui ne sont pas accessibles, les variables statiques - // accessibles étant déjà comptabilitées par la boucle précédente. - - if ((*s_etat_processus).s_liste_variables_statiques[i].objet != NULL) - { - (*((integer8 *) (*((*((*((struct_liste_chainee *) - (*s_objet_resultat).objet)).suivant)).donnee)).objet)) += - sizeof(unsigned char) * strlen((*s_etat_processus) - .s_liste_variables_statiques[i].nom); - (*((integer8 *) (*((*((*((struct_liste_chainee *) - (*s_objet_resultat).objet)).suivant)).donnee)).objet)) += - occupation_memoire((*s_etat_processus) - .s_liste_variables_statiques[i].objet); - } - } - - for(i = 0; i < (*(*s_etat_processus).s_liste_variables_partagees) - .nombre_variables; i++) - { - (*((integer8 *) (*((*((*((struct_liste_chainee *) - (*s_objet_resultat).objet)).suivant)).donnee)).objet)) += - sizeof(unsigned char) * strlen((*(*s_etat_processus) - .s_liste_variables_partagees).table[i].nom); - (*((integer8 *) (*((*((*((struct_liste_chainee *) - (*s_objet_resultat).objet)).suivant)).donnee)).objet)) += - occupation_memoire((*(*s_etat_processus) - .s_liste_variables_partagees).table[i].objet); - } - /* * Empilement du résultat */ @@ -416,7 +382,11 @@ instruction_mtxlock(struct_processus *s_ } } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -425,10 +395,17 @@ instruction_mtxlock(struct_processus *s_ if (pthread_mutex_lock(&((*((struct_mutex *) (*s_objet_argument).objet)) .mutex)) != 0) { - if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; + if (errno != EINTR) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } } liberation(s_etat_processus, s_objet_argument); @@ -442,10 +419,19 @@ instruction_mtxlock(struct_processus *s_ return; } - if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0) + (*((struct_mutex *) (*s_objet_argument).objet)).tid = pthread_self(); + +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; + if (errno != EINTR) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } } if ((*s_etat_processus).profilage == d_vrai) @@ -590,6 +576,11 @@ instruction_mtxtrylock(struct_processus return; } } + else + { + (*((struct_mutex *) (*s_objet_argument).objet)).tid = + pthread_self(); + } if ((*s_etat_processus).profilage == d_vrai) { @@ -613,7 +604,7 @@ instruction_mtxtrylock(struct_processus return; } - (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1; + (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? -1 : 0; if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) @@ -624,6 +615,7 @@ instruction_mtxtrylock(struct_processus return; } + /* ================================================================================ Fonction 'mtxstatus' @@ -748,18 +740,23 @@ instruction_mtxstatus(struct_processus * } } - if (pthread_mutex_unlock(&((*((struct_mutex *) - (*s_objet_argument).objet)).mutex)) != 0) + if (ios == 0) { - liberation(s_etat_processus, s_objet_argument); + // Le mutex a été verrouillé par le trylock précédent. - if ((*s_etat_processus).profilage == d_vrai) + if (pthread_mutex_unlock(&((*((struct_mutex *) + (*s_objet_argument).objet)).mutex)) != 0) { - profilage(s_etat_processus, NULL); - } + liberation(s_etat_processus, s_objet_argument); - (*s_etat_processus).erreur_systeme = d_es_processus; - return; + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } + + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } } if ((*s_etat_processus).profilage == d_vrai) @@ -873,9 +870,19 @@ instruction_mtxunlock(struct_processus * if (l_element_courant == NULL) { + liberation(s_etat_processus, s_objet_argument); + (*s_etat_processus).erreur_execution = d_ex_mutex; + return; + } + if (pthread_equal(pthread_self(), (*((struct_mutex *) + (*s_objet_argument).objet)).tid) == 0) + { liberation(s_etat_processus, s_objet_argument); + + (*s_etat_processus).erreur_execution = + d_ex_mutex_acquis_autre_thread; return; }