--- rpl/src/gestion_objets.c 2011/09/26 15:57:10 1.73 +++ rpl/src/gestion_objets.c 2012/04/13 14:12:49 1.81 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.4 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.8 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -544,6 +544,7 @@ allocation(struct_processus *s_etat_proc return(NULL); } + (*((struct_mutex *) (*s_objet).objet)).tid = pthread_self(); break; } @@ -1103,6 +1104,28 @@ liberation(struct_processus *s_etat_proc return; } + if (pthread_mutex_trylock(&((*((struct_mutex *) + (*s_objet).objet)).mutex)) == 0) + { + // On a pu verrouiller le mutex. Il faut donc spécifier le tid. + (*((struct_mutex *) (*s_objet).objet)).tid = pthread_self(); + } + + if (pthread_equal(pthread_self(), + (*((struct_mutex *) (*s_objet).objet)).tid) != 0) + { + pthread_mutex_unlock(&((*((struct_mutex *) + (*s_objet).objet)).mutex)); + } + else + { + (*s_etat_processus).erreur_systeme = + d_es_mutex_acquis_autre_thread; + return; + } + + pthread_mutex_destroy(&((*((struct_mutex *) + (*s_objet).objet)).mutex)); free((struct_mutex *) (*s_objet).objet); break; } @@ -2216,20 +2239,9 @@ copie_objet(struct_processus *s_etat_pro case MTX : { - if (type != 'O') - { - incrementation_atomique(s_objet); - return(s_objet); - } - - if ((s_nouvel_objet = allocation(s_etat_processus, MTX)) == NULL) - { - return(NULL); - } - - (*((struct_mutex *) ((*s_nouvel_objet).objet))).mutex = - (*((struct_mutex *) ((*s_objet).objet))).mutex; - break; + // La duplication d'un mutex renvoie le même objet. + incrementation_atomique(s_objet); + return(s_objet); } case NOM : @@ -2484,6 +2496,8 @@ copie_objet(struct_processus *s_etat_pro return(NULL); } + (*((struct_semaphore *) (*s_nouvel_objet).objet)).semaphore = + (*((struct_semaphore *) (*s_objet).objet)).semaphore; strcpy((*((struct_semaphore *) (*s_nouvel_objet).objet)).nom, (*((struct_semaphore *) (*s_objet).objet)).nom); break;