--- rpl/src/gestion_objets.c 2010/05/25 18:09:44 1.21 +++ rpl/src/gestion_objets.c 2010/07/31 10:34:17 1.32 @@ -1,6 +1,6 @@ /* ================================================================================ - RPL/2 (R) version 4.0.16 + RPL/2 (R) version 4.0.18 Copyright (C) 1989-2010 Dr. BERTRAND Joël This file is part of RPL/2. @@ -266,7 +266,7 @@ liberation_maillon(struct_processus *s_e ================================================================================ Routine d'allocation d'une structure *s_objet ================================================================================ - Entrées : structure sur l'état du processus et objet à afficher + Entrées : structure sur l'état du processus et objet à allouer -------------------------------------------------------------------------------- Sorties : chaine de caractères -------------------------------------------------------------------------------- @@ -279,8 +279,20 @@ allocation(struct_processus *s_etat_proc { struct_objet *s_objet; + if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return(NULL); + } + if ((*s_etat_processus).pile_objets == NULL) { + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return(NULL); + } + // Il n'existe aucune structure struct_objet disponible dans le cache. if ((s_objet = malloc(sizeof(struct_objet))) == NULL) @@ -299,6 +311,12 @@ allocation(struct_processus *s_etat_proc (*s_etat_processus).taille_pile_objets--; (*s_objet).nombre_occurrences = 1; + + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return(NULL); + } } (*s_objet).type = type; @@ -1104,7 +1122,6 @@ liberation(struct_processus *s_etat_proc return; } - free(s_objet); break; } @@ -1121,7 +1138,8 @@ liberation(struct_processus *s_etat_proc .nombre_references--; BUG((*(*((struct_processus_fils *) (*s_objet).objet)).thread) - .nombre_references < 0, printf("(*(*((struct_processus_fils" + .nombre_references < 0, uprintf( + "(*(*((struct_processus_fils" " *) (*s_objet).objet)).thread).nombre_references = %d\n", (int) (*(*((struct_processus_fils *) (*s_objet).objet)) .thread).nombre_references)); @@ -1148,10 +1166,14 @@ liberation(struct_processus *s_etat_proc pthread_mutex_destroy(&((*(*((struct_processus_fils *) (*s_objet).objet)).thread).mutex)); free((*((struct_processus_fils *) (*s_objet).objet)).thread); + } if (decrementation_atomique(s_objet) > 0) { + BUG(drapeau == d_vrai, uprintf("(*(*((struct_processus_fils" + " *) (*s_objet).objet)).thread).nombre_references " + "= 0 with nombre_occurrences > 0\n")); return; } @@ -1416,30 +1438,36 @@ liberation(struct_processus *s_etat_proc return; } - if (s_etat_processus != NULL) + if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0) { - if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE) - { - (*s_objet).objet = (*s_etat_processus).pile_objets; - (*s_etat_processus).pile_objets = s_objet; - (*s_etat_processus).taille_pile_objets++; - } - else - { - if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } - free(s_objet); - } + if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE) + { + (*s_objet).objet = (*s_etat_processus).pile_objets; + (*s_etat_processus).pile_objets = s_objet; + (*s_etat_processus).taille_pile_objets++; } else { + if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0) + { + pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)); + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + free(s_objet); } + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + return; } @@ -2267,6 +2295,7 @@ copie_objet(struct_processus *s_etat_pro (*((struct_processus_fils *) (*s_nouvel_objet).objet)) = (*((struct_processus_fils *) (*s_objet).objet)); + break; } @@ -2800,6 +2829,8 @@ copie_etat_processus(struct_processus *s (*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0; (*s_nouvel_etat_processus).at_exit = NULL; + (*s_nouvel_etat_processus).at_poke = NULL; + (*s_nouvel_etat_processus).traitement_at_poke = 'N'; for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) { @@ -3536,6 +3567,12 @@ copie_etat_processus(struct_processus *s pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex); pthread_mutexattr_destroy(&attributs_mutex); + pthread_mutexattr_init(&attributs_mutex); + pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); + pthread_mutex_init(&((*s_nouvel_etat_processus).mutex_allocation), + &attributs_mutex); + pthread_mutexattr_destroy(&attributs_mutex); + if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -3714,7 +3751,7 @@ debug_memoire_modification(void *pointeu { pthread_mutex_unlock(&mutex_allocation); - uprintf("[%d-%llu] ILLEGAL POINTER\n", + uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n", getpid(), (unsigned long long) pthread_self()); # ifdef __BACKTRACE BACKTRACE(PROFONDEUR_PILE); @@ -3811,7 +3848,7 @@ debug_memoire_retrait(void *pointeur) if (element_courant == NULL) { - uprintf("[%d-%llu] ILLEGAL POINTER\n", + uprintf("[%d-%llu] ILLEGAL POINTER (free)\n", getpid(), (unsigned long long) pthread_self()); # ifdef __BACKTRACE BACKTRACE(PROFONDEUR_PILE); @@ -3928,20 +3965,6 @@ debug_memoire_verification() return; } -void -debug_memoire_verrouillage() -{ - pthread_mutex_lock(&mutex_allocation); - return; -} - -void -debug_memoire_deverrouillage() -{ - pthread_mutex_unlock(&mutex_allocation); - return; -} - pid_t debug_fork() {