--- rpl/src/interruptions.c 2010/09/02 07:51:48 1.39 +++ rpl/src/interruptions.c 2011/04/11 13:02:27 1.46.2.1 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.19 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.0.22 + Copyright (C) 1989-2011 Dr. BERTRAND Joël This file is part of RPL/2. @@ -183,9 +183,9 @@ insertion_thread_surveillance(struct_pro } } - pthread_mutex_lock(&((*s_argument_thread).mutex)); + pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)); (*s_argument_thread).nombre_references++; - pthread_mutex_unlock(&((*s_argument_thread).mutex)); + pthread_mutex_unlock(&((*s_argument_thread).mutex_nombre_references)); (*l_nouvel_objet).suivant = liste_threads_surveillance; (*l_nouvel_objet).donnee = (void *) s_argument_thread; @@ -378,7 +378,8 @@ retrait_thread_surveillance(struct_proce (*l_element_precedent).suivant = (*l_element_courant).suivant; } - if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)) + != 0) { # ifndef SEMAPHORES_NOMMES sem_post(&semaphore_liste_threads); @@ -400,7 +401,8 @@ retrait_thread_surveillance(struct_proce if ((*s_argument_thread).nombre_references == 0) { - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { # ifndef SEMAPHORES_NOMMES sem_post(&semaphore_liste_threads); @@ -415,11 +417,13 @@ retrait_thread_surveillance(struct_proce } pthread_mutex_destroy(&((*s_argument_thread).mutex)); + pthread_mutex_destroy(&((*s_argument_thread).mutex_nombre_references)); free(s_argument_thread); } else { - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { # ifndef SEMAPHORES_NOMMES sem_post(&semaphore_liste_threads); @@ -676,7 +680,8 @@ liberation_threads(struct_processus *s_e s_argument_thread = (struct_descripteur_thread *) (*((struct_liste_chainee *) element_courant)).donnee; - if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_lock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -700,8 +705,8 @@ liberation_threads(struct_processus *s_e close((*s_argument_thread) .pipe_nombre_interruptions_attente[0]); - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) - != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -709,6 +714,8 @@ liberation_threads(struct_processus *s_e } pthread_mutex_destroy(&((*s_argument_thread).mutex)); + pthread_mutex_destroy(&((*s_argument_thread) + .mutex_nombre_references)); if ((*s_argument_thread).processus_detache == d_faux) { @@ -723,8 +730,8 @@ liberation_threads(struct_processus *s_e } else { - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) - != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -1350,7 +1357,8 @@ liberation_threads(struct_processus *s_e s_argument_thread = (struct_descripteur_thread *) (*l_element_courant).donnee; - if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_lock(&((*s_argument_thread).mutex_nombre_references)) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -1373,7 +1381,8 @@ liberation_threads(struct_processus *s_e close((*s_argument_thread).pipe_interruptions[0]); close((*s_argument_thread).pipe_nombre_interruptions_attente[0]); - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -1381,6 +1390,8 @@ liberation_threads(struct_processus *s_e } pthread_mutex_destroy(&((*s_argument_thread).mutex)); + pthread_mutex_destroy(&((*s_argument_thread) + .mutex_nombre_references)); if ((*s_argument_thread).processus_detache == d_faux) { @@ -1394,7 +1405,8 @@ liberation_threads(struct_processus *s_e } else { - if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_argument_thread) + .mutex_nombre_references)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; sem_post(&semaphore_liste_threads); @@ -1592,12 +1604,12 @@ verrouillage_gestionnaire_signaux() // ce que ce soit possible. # ifndef SEMAPHORES_NOMMES - while(sem_trywait(&semaphore_liste_threads) == -1) + while(sem_wait(&semaphore_liste_threads) == -1) # else - while(sem_trywait(semaphore_liste_threads) == -1) + while(sem_wait(semaphore_liste_threads) == -1) # endif { - if ((errno != EINTR) && (errno != EAGAIN)) + if (errno != EINTR) { pthread_sigmask(SIG_SETMASK, &oldset, NULL); @@ -1613,8 +1625,6 @@ verrouillage_gestionnaire_signaux() BUG(1, uprintf("Lock error !\n")); return; } - - sched_yield(); } } @@ -1738,7 +1748,7 @@ interruption1(SIGHANDLER_ARGS) verrouillage_gestionnaire_signaux(); # ifdef _BROKEN_SIGINFO - if (signal == SIGINT) + if ((signal == SIGINT) || (signal == SIGTERM)) { // Si l'interruption provient du clavier, il n'y a pas eu d'appel // à queue_in(). @@ -1802,6 +1812,7 @@ interruption1(SIGHANDLER_ARGS) } case SIGINT : + case SIGTERM : { /* * Une vieille spécification POSIX permet au pointeur siginfo @@ -1827,8 +1838,17 @@ interruption1(SIGHANDLER_ARGS) if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) { - printf("[%d] SIGINT (thread %llu)\n", (int) getpid(), - (unsigned long long) pthread_self()); + if (signal == SIGINT) + { + printf("[%d] SIGINT (thread %llu)\n", (int) getpid(), + (unsigned long long) pthread_self()); + } + else + { + printf("[%d] SIGTERM (thread %llu)\n", (int) getpid(), + (unsigned long long) pthread_self()); + } + fflush(stdout); } @@ -1850,16 +1870,19 @@ interruption1(SIGHANDLER_ARGS) return; } - if (strncmp(getenv("LANG"), "fr", 2) == 0) + if (signal == SIGINT) { - printf("+++Interruption\n"); - } - else - { - printf("+++Interrupt\n"); - } + if (strncmp(getenv("LANG"), "fr", 2) == 0) + { + printf("+++Interruption\n"); + } + else + { + printf("+++Interrupt\n"); + } - fflush(stdout); + fflush(stdout); + } (*s_etat_processus).var_volatile_requete_arret = -1; (*s_etat_processus).var_volatile_alarme = -1;