--- rpl/src/interruptions.c 2011/09/20 07:16:40 1.76 +++ rpl/src/interruptions.c 2011/09/20 15:45:53 1.80 @@ -324,8 +324,13 @@ verrouillage_threads_concurrents(struct_ == getpid()) && (pthread_equal((*((struct_thread *) (*l_element_courant).donnee)).tid, pthread_self()) == 0)) { - if (pthread_mutex_lock(&((*(*((struct_thread *) (*l_element_courant) - .donnee)).s_etat_processus).mutex_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*(*((struct_thread *) (*l_element_courant) + .donnee)).s_etat_processus).semaphore_fork)) == -1) +# else + while(sem_wait((*(*((struct_thread *) (*l_element_courant) + .donnee)).s_etat_processus).semaphore_fork) == -1) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -351,9 +356,15 @@ deverrouillage_threads_concurrents(struc == getpid()) && (pthread_equal((*((struct_thread *) (*l_element_courant).donnee)).tid, pthread_self()) == 0)) { - if (pthread_mutex_unlock(&((*(*((struct_thread *) - (*l_element_courant).donnee)).s_etat_processus) - .mutex_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*(*((struct_thread *) + (*l_element_courant).donnee)).s_etat_processus) + .semaphore_fork)) != 0) +# else + if (sem_post((*(*((struct_thread *) + (*l_element_courant).donnee)).s_etat_processus) + .semaphore_fork) != 0) +# endif { if (pthread_mutex_unlock(&mutex_liste_threads) != 0) { @@ -1109,8 +1120,13 @@ liberation_threads(struct_processus *s_e liberation_allocateur(s_etat_processus); - pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)); - pthread_mutex_destroy(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus).semaphore_fork)); + sem_destroy(&((*s_etat_processus).semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); + sem_close((*s_etat_processus).semaphore_fork); +# endif liberation_contexte_cas(s_etat_processus); free(s_etat_processus); @@ -1298,7 +1314,11 @@ verrouillage_gestionnaire_signaux(struct { int semaphore; - 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 { BUG(1, uprintf("Lock error !\n")); return; @@ -1308,7 +1328,11 @@ verrouillage_gestionnaire_signaux(struct if (pthread_mutex_lock(&mutex_gestionnaires_signaux_atomique) != 0) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } @@ -1319,7 +1343,11 @@ verrouillage_gestionnaire_signaux(struct if (sem_post(semaphore_gestionnaires_signaux) == -1) # endif { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Lock error !\n")); return; } @@ -1330,14 +1358,22 @@ verrouillage_gestionnaire_signaux(struct if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0) # endif { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Lock error !\n")); return; } if (pthread_mutex_unlock(&mutex_gestionnaires_signaux_atomique) != 0) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } @@ -1352,7 +1388,11 @@ verrouillage_gestionnaire_signaux(struct if (pthread_mutex_lock(&mutex_liste_threads) != 0) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Lock error !\n")); return; } @@ -1370,7 +1410,11 @@ deverrouillage_gestionnaire_signaux(stru if (pthread_mutex_lock(&mutex_gestionnaires_signaux_atomique) == -1) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } @@ -1381,7 +1425,11 @@ deverrouillage_gestionnaire_signaux(stru if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0) # endif { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } @@ -1394,7 +1442,11 @@ deverrouillage_gestionnaire_signaux(stru { if (errno != EINTR) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } @@ -1402,15 +1454,26 @@ deverrouillage_gestionnaire_signaux(stru if (pthread_mutex_unlock(&mutex_gestionnaires_signaux_atomique) != 0) { - pthread_mutex_lock(&((*s_etat_processus).mutex_fork)); +# ifndef SEMAPHORES_NOMMES + sem_wait(&((*s_etat_processus).semaphore_fork)); +# else + sem_wait((*s_etat_processus).semaphore_fork); +# endif BUG(1, uprintf("Unlock error !\n")); return; } - 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 { - BUG(1, uprintf("Unlock error !\n")); - return; + if (errno != EINTR) + { + BUG(1, uprintf("Unlock error !\n")); + return; + } } if (semaphore == 1) @@ -2398,12 +2461,15 @@ envoi_signal_processus(pid_t pid, enum s } # ifndef SEMAPHORES_NOMMES - if (sem_wait(&((*s_queue_signaux).semaphore)) != 0) + while(sem_wait(&((*s_queue_signaux).semaphore)) != 0) # else - if (sem_wait(semaphore_queue_signaux) != 0) + while(sem_wait(semaphore_queue_signaux) != 0) # endif { - return(1); + if (errno != EINTR) + { + return(1); + } } (*s_queue_signaux).queue[(*s_queue_signaux).pointeur_ecriture] @@ -2484,26 +2550,35 @@ envoi_signal_processus(pid_t pid, enum s # ifndef IPCS_SYSV // POSIX # ifndef SEMAPHORES_NOMMES - if (sem_wait(&((*queue).semaphore)) != 0) + while(sem_wait(&((*queue).semaphore)) != 0) { - return(1); + if (errno != EINTR) + { + return(1); + } } # else - if ((semaphore = sem_open2(pid)) == SEM_FAILED) + if ((semaphore = sem_open2(pid, SEM_QUEUE)) == SEM_FAILED) { return(1); } - if (sem_wait(semaphore) != 0) + while(sem_wait(semaphore) != 0) { - sem_close(semaphore); - return(1); + if (errno != EINTR) + { + sem_close(semaphore); + return(1); + } } # endif # else // IPCS_SYSV - if (sem_wait(&((*queue).semaphore)) != 0) + while(sem_wait(&((*queue).semaphore)) != 0) { - return(1); + if (errno != EINTR) + { + return(1); + } } # endif @@ -2698,7 +2773,7 @@ creation_queue_signaux(struct_processus # ifndef SEMAPHORES_NOMMES sem_init(&((*s_queue_signaux).semaphore), 1, 1); # else - if ((semaphore_queue_signaux = sem_init2(1, getpid())) + if ((semaphore_queue_signaux = sem_init2(1, getpid(), SEM_QUEUE)) == SEM_FAILED) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -2910,7 +2985,7 @@ destruction_queue_signaux(struct_process sem_destroy(&((*s_queue_signaux).semaphore)); # else sem_close(semaphore_queue_signaux); - sem_destroy2(semaphore_queue_signaux, getpid()); + sem_destroy2(semaphore_queue_signaux, getpid(), SEM_QUEUE); # endif if (munmap(s_queue_signaux, sizeof(struct_queue_signaux)) != 0)