--- rpl/src/instructions_m4.c 2011/08/09 11:31:33 1.30 +++ rpl/src/instructions_m4.c 2012/03/01 10:14:06 1.40 @@ -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.7 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -417,33 +417,24 @@ instruction_mtxlock(struct_processus *s_ } # ifndef SEMAPHORES_NOMMES - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) # else - if (sem_post((*s_etat_processus).semaphore_fork) != 0) + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; } -# endif if (pthread_mutex_lock(&((*((struct_mutex *) (*s_objet_argument).objet)) .mutex)) != 0) { # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) == -1) + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) # endif { - if ((*s_etat_processus).profilage == d_vrai) - { - profilage(s_etat_processus, NULL); - } - if (errno != EINTR) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -462,10 +453,12 @@ instruction_mtxlock(struct_processus *s_ return; } + (*((struct_mutex *) (*s_objet_argument).objet)).tid = pthread_self(); + # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) == -1) + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) # endif { if (errno != EINTR) @@ -618,6 +611,8 @@ instruction_mtxtrylock(struct_processus } } + (*((struct_mutex *) (*s_objet_argument).objet)).tid = pthread_self(); + if ((*s_etat_processus).profilage == d_vrai) { profilage(s_etat_processus, NULL); @@ -651,6 +646,7 @@ instruction_mtxtrylock(struct_processus return; } + /* ================================================================================ Fonction 'mtxstatus' @@ -775,18 +771,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) @@ -900,9 +901,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; }