--- rpl/src/gestion_objets.c 2011/11/18 21:33:31 1.74 +++ rpl/src/gestion_objets.c 2012/09/15 12:57:09 1.84 @@ -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.10 + 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; @@ -2803,6 +2817,7 @@ copie_etat_processus(struct_processus *s pthread_mutexattr_init(&attributs_mutex); pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); + (*s_nouvel_etat_processus).sections_critiques = 0; // Les sémaphores sont initialisés dans le nouveau thread. Il // s'agit d'une limitation de l'implantation de l'émulation