--- rpl/src/interruptions.c 2010/09/02 07:51:48 1.39 +++ rpl/src/interruptions.c 2011/09/10 20:45:06 1.66 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.19 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.3 + 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); @@ -796,25 +803,8 @@ liberation_threads(struct_processus *s_e } } - for(i = 0; i < (*s_etat_processus).nombre_variables; i++) - { - pthread_mutex_trylock(&((*(*s_etat_processus) - .s_liste_variables[i].objet).mutex)); - pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables[i].objet).mutex)); - - // Les variables de niveau 0 sont des définitions qui - // ne sont pas copiées entre threads. - if ((*s_etat_processus).s_liste_variables[i].niveau > 0) - { - liberation(s_etat_processus, - (*s_etat_processus).s_liste_variables[i].objet); - } - - free((*s_etat_processus).s_liste_variables[i].nom); - } - - free((*s_etat_processus).s_liste_variables); + liberation_arbre_variables(s_etat_processus, + (*s_etat_processus).s_arbre_variables, d_faux); for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++) { @@ -1328,6 +1318,7 @@ liberation_threads(struct_processus *s_e sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); # endif + liberation_contexte_cas(s_etat_processus); free(s_etat_processus); s_etat_processus = candidat; @@ -1350,7 +1341,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 +1365,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 +1374,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 +1389,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); @@ -1461,8 +1457,8 @@ recherche_thread(pid_t pid, pthread_t ti return(s_etat_processus); } -static logical1 -recherche_thread_principal(pid_t pid, pthread_t *thread) +static struct_processus * +recherche_thread_principal(pid_t pid) { volatile struct_liste_chainee_volatile *l_element_courant; @@ -1486,12 +1482,11 @@ recherche_thread_principal(pid_t pid, pt * Le processus n'existe plus. On ne distribue aucun signal. */ - return(d_faux); + return(NULL); } - (*thread) = (*((struct_thread *) (*l_element_courant).donnee)).tid; - - return(d_vrai); + return((*((struct_thread *) (*l_element_courant).donnee)) + .s_etat_processus); } @@ -1592,12 +1587,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 +1608,6 @@ verrouillage_gestionnaire_signaux() BUG(1, uprintf("Lock error !\n")); return; } - - sched_yield(); } } @@ -1724,55 +1717,116 @@ deverrouillage_gestionnaire_signaux() return; } -void -interruption1(SIGHANDLER_ARGS) +#define test_signal(signal) \ + if (signal_test == SIGTEST) \ + { signal_test = initialisation_queue_interruptions(signal); return; } + +/* + * Les interruptions sont mise en mémoire puis traitées depuis + * la fonction scrutation_injection() parce que les fonctions pthread*() + * ne sont pas 'async signal safe'. + * + * Les interruptions sont ainsi empilées dans un buffer circulaire puis + * traitées au fur et à mesure. + */ + +static struct { - pid_t pid; +# define SIGNAL_MAX 32 +# define SIGNAL_BUFFER 1024 +# define ECRITURE 0 +# define LECTURE 1 - pthread_t thread; + sig_atomic_t nombre_interruptions_en_queue; + int pointeur[SIGNAL_MAX][2]; - struct_processus *s_etat_processus; + pid_t pid[SIGNAL_MAX][SIGNAL_BUFFER]; +} queue_interruptions; - volatile sig_atomic_t exclusion = 0; +pthread_mutex_t mutex_signal = PTHREAD_MUTEX_INITIALIZER; - verrouillage_gestionnaire_signaux(); +static inline int +initialisation_queue_interruptions(int signal) +{ + int i; -# ifdef _BROKEN_SIGINFO - if (signal == SIGINT) + if (signal > SIGNAL_MAX) { - // Si l'interruption provient du clavier, il n'y a pas eu d'appel - // à queue_in(). - - pid = getpid(); + return(signal + 1); } - else + + queue_interruptions.nombre_interruptions_en_queue = 0; + + for(i = 0; i < SIGNAL_MAX; i++) { - pid = origine_signal(signal); + queue_interruptions.pointeur[i][ECRITURE] = 0; + queue_interruptions.pointeur[i][LECTURE] = 0; } + + return(signal); +} + +void +interruption1(SIGHANDLER_ARGS) +{ + pid_t pid; + + test_signal(signal); + +# ifdef _BROKEN_SIGINFO + if ((signal == SIGINT) || (signal == SIGTERM)) + { + // Si l'interruption provient du clavier, il n'y a pas eu d'appel + // à queue_in(). + + pid = getpid(); + } + else + { + pid = origine_signal(signal); + } # else - if (siginfo != NULL) - { - pid = (*siginfo).si_pid; - } - else - { - pid = getpid(); - } + + /* + * Une vieille spécification POSIX permet au pointeur siginfo + * d'être nul dans le cas d'un ^C envoyé depuis le clavier. + * Solaris suit en particulier cette spécification. + */ + + if (siginfo != NULL) + { + pid = (*siginfo).si_pid; + } + else + { + pid = getpid(); + } # endif + queue_interruptions.pid[signal][queue_interruptions.pointeur + [signal][ECRITURE]] = pid; + queue_interruptions.pointeur[signal][ECRITURE] = + (queue_interruptions.pointeur[signal][ECRITURE] + 1) + % SIGNAL_BUFFER; + queue_interruptions.nombre_interruptions_en_queue++; + return; +} + +static void +corps_interruption1(struct_processus *s_etat_processus, int signal, pid_t pid) +{ + volatile sig_atomic_t exclusion = 0; + + struct_processus *s_thread_principal; + + verrouillage_gestionnaire_signaux(); + switch(signal) { case SIGALRM : { if (pid == getpid()) { - if ((s_etat_processus = recherche_thread(getpid(), - pthread_self())) == NULL) - { - deverrouillage_gestionnaire_signaux(); - return; - } - if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) { printf("[%d] SIGALRM (thread %llu)\n", (int) getpid(), @@ -1792,9 +1846,13 @@ interruption1(SIGHANDLER_ARGS) } else { - if (recherche_thread_principal(getpid(), &thread) == d_vrai) + if ((s_thread_principal = recherche_thread_principal(getpid())) + != NULL) { - pthread_kill(thread, signal); + while((*s_etat_processus).signal_a_traiter == d_vrai); + (*s_etat_processus).signal = signal; + (*s_etat_processus).origine_signal = getpid(); + (*s_etat_processus).signal_a_traiter = d_vrai; } } @@ -1802,33 +1860,23 @@ interruption1(SIGHANDLER_ARGS) } case SIGINT : + case SIGTERM : { - /* - * Une vieille spécification POSIX permet au pointeur siginfo - * d'être nul dans le cas d'un ^C envoyé depuis le clavier. - * Solaris suit en particulier cette spécification. - */ - -# ifndef _BROKEN_SIGINFO - if (siginfo == NULL) - { - kill(getpid(), signal); - } - else -# endif if (pid == getpid()) { - if ((s_etat_processus = recherche_thread(getpid(), - pthread_self())) == NULL) - { - deverrouillage_gestionnaire_signaux(); - return; - } - 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 +1898,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; @@ -1869,9 +1920,13 @@ interruption1(SIGHANDLER_ARGS) } else { - if (recherche_thread_principal(getpid(), &thread) == d_vrai) + if ((s_thread_principal = recherche_thread_principal(getpid())) + != NULL) { - pthread_kill(thread, signal); + while((*s_etat_processus).signal_a_traiter == d_vrai); + (*s_etat_processus).signal = signal; + (*s_etat_processus).origine_signal = getpid(); + (*s_etat_processus).signal_a_traiter = d_vrai; } } @@ -1893,13 +1948,9 @@ interruption1(SIGHANDLER_ARGS) void interruption2(SIGHANDLER_ARGS) { - pid_t pid; - - pthread_t thread; - - struct_processus *s_etat_processus; + pid_t pid; - verrouillage_gestionnaire_signaux(); + test_signal(signal); # ifdef _BROKEN_SIGINFO pid = origine_signal(signal); @@ -1914,35 +1965,42 @@ interruption2(SIGHANDLER_ARGS) } # endif -# ifndef _BROKEN_SIGINFO + queue_interruptions.pid[signal][queue_interruptions.pointeur + [signal][ECRITURE]] = pid; + queue_interruptions.pointeur[signal][ECRITURE] = + (queue_interruptions.pointeur[signal][ECRITURE] + 1) + % SIGNAL_BUFFER; + + /* + * Le signal SIGFSTP provient de la mort du processus de contrôle. + * Sous certains systèmes (Linux...), la mort du terminal de contrôle + * se traduit par l'envoi d'un SIGHUP au processus. Sur d'autres + * (SunOS), le processus reçoit un SIGFSTP avec une structure siginfo + * non initialisée (pointeur NULL) issue de TERMIO. + */ + if (siginfo == NULL) { - /* - * Le signal SIGFSTP provient de la mort du processus de contrôle. - * Sous certains systèmes (Linux...), la mort du terminal de contrôle - * se traduit par l'envoi d'un SIGHUP au processus. Sur d'autres - * (SunOS), le processus reçoit un SIGFSTP avec une structure siginfo - * non initialisée (pointeur NULL) issue de TERMIO. - */ - - if (recherche_thread_principal(getpid(), &thread) == d_vrai) - { - pthread_kill(thread, SIGHUP); - deverrouillage_gestionnaire_signaux(); - return; - } + queue_interruptions.pid[SIGHUP][queue_interruptions.pointeur + [SIGHUP][ECRITURE]] = pid; + queue_interruptions.pointeur[SIGHUP][ECRITURE] = + (queue_interruptions.pointeur[SIGHUP][ECRITURE] + 1) + % SIGNAL_BUFFER; + queue_interruptions.nombre_interruptions_en_queue += 2; } - else -# endif + + return; +} + +static void +corps_interruption2(struct_processus *s_etat_processus, int signal, pid_t pid) +{ + struct_processus *s_thread_principal; + + verrouillage_gestionnaire_signaux(); + if (pid == getpid()) { - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) - == NULL) - { - deverrouillage_gestionnaire_signaux(); - return; - } - /* * 0 => fonctionnement normal * -1 => requête @@ -1969,11 +2027,13 @@ interruption2(SIGHANDLER_ARGS) { // Envoi d'un signal au thread maître du groupe. - if (recherche_thread_principal(getpid(), &thread) == d_vrai) + if ((s_thread_principal = recherche_thread_principal(getpid())) + != NULL) { - pthread_kill(thread, SIGTSTP); - deverrouillage_gestionnaire_signaux(); - return; + while((*s_etat_processus).signal_a_traiter == d_vrai); + (*s_etat_processus).signal = signal; + (*s_etat_processus).origine_signal = getpid(); + (*s_etat_processus).signal_a_traiter = d_vrai; } } @@ -1984,19 +2044,30 @@ interruption2(SIGHANDLER_ARGS) void interruption3(SIGHANDLER_ARGS) { - pid_t pid; + // Si on passe par ici, c'est qu'il est impossible de récupérer + // l'erreur d'accès à la mémoire. On sort donc du programme quitte à + // ce qu'il reste des processus orphelins. - struct_processus *s_etat_processus; + unsigned char message[] = "+++System : Uncaught access violation\n" + "+++System : Aborting !\n; - static int compteur = 0; + if (pid_processus_pere == getpid()) + { + kill(pid_processus_pere, SIGALRM); + } - verrouillage_gestionnaire_signaux(); + write(STDERR_FILENO, message, strlen(message)); + _exit(EXIT_FAILURE); +} -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif +void INTERRUPTION3_A_FIXER() +{ + pthread_t thread; + + struct_processus *s_etat_processus; + + test_signal(signal); + verrouillage_gestionnaire_signaux(); if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { @@ -2022,24 +2093,79 @@ interruption3(SIGHANDLER_ARGS) // Segfault dans une routine interne if (strncmp(getenv("LANG"), "fr", 2) == 0) { - printf("+++Système : Violation d'accès (dépassement de pile)\n"); + printf("+++Système : Violation d'accès\n"); } else { - printf("+++System : Access violation (stack overflow)\n"); + printf("+++System : Access violation\n"); } fflush(stdout); - compteur++; + (*s_etat_processus).compteur_violation_d_acces++; - if (compteur > 1) + if ((*s_etat_processus).compteur_violation_d_acces > 1) { + // On vient de récupérer plus d'une erreur de segmentation + // dans le même processus ou le même thread. L'erreur n'est pas + // récupérable et on sort autoritairement du programme. Il peut + // rester des processus orphelins en attente ! + + if (strncmp(getenv("LANG"), "fr", 2) == 0) + { + printf("+++Système : Violation d'accès, tentative de " + "terminaison de la tâche\n"); + printf(" (defauts multiples)\n"); + } + else + { + printf("+++System : Access violation, trying to kill task " + "(multiple defaults)\n"); + } + + fflush(stdout); + deverrouillage_gestionnaire_signaux(); exit(EXIT_FAILURE); } else { + // Première erreur de segmentation. On essaie de terminer + // proprement le thread ou le processus. Le signal ne peut être + // envoyé que depuis le même processus. + + if (recherche_thread_principal(getpid(), &thread) == d_vrai) + { + if (pthread_equal(thread, pthread_self()) != 0) + { + deverrouillage_gestionnaire_signaux(); + + if ((*s_etat_processus).pid_processus_pere != getpid()) + { + // On est dans le thread principal d'un processus. + + longjmp(contexte_processus, -1); + } + else + { + // On est dans le thread principal du processus + // père. + + longjmp(contexte_initial, -1); + } + } + else + { + // On est dans un thread fils d'un thread principal. + + deverrouillage_gestionnaire_signaux(); + longjmp(contexte_thread, -1); + } + } + + // Là, on ramasse les miettes puisque le thread n'existe plus + // dans la base (corruption de la mémoire). + deverrouillage_gestionnaire_signaux(); longjmp(contexte_initial, -1); } @@ -2052,18 +2178,11 @@ interruption3(SIGHANDLER_ARGS) void interruption4(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2094,6 +2213,7 @@ interruption5(SIGHANDLER_ARGS) struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); # ifdef _BROKEN_SIGINFO @@ -2160,18 +2280,11 @@ interruption5(SIGHANDLER_ARGS) void interruption6(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2192,18 +2305,11 @@ interruption6(SIGHANDLER_ARGS) void interruption7(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2233,6 +2339,7 @@ interruption8(SIGHANDLER_ARGS) struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); # ifdef _BROKEN_SIGINFO @@ -2279,18 +2386,11 @@ interruption8(SIGHANDLER_ARGS) void interruption9(SIGHANDLER_ARGS) { - pid_t pid; - struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2324,20 +2424,13 @@ interruption10(SIGHANDLER_ARGS) { file *fichier; - pid_t pid; - struct_processus *s_etat_processus; unsigned char nom[8 + 64 + 1]; + test_signal(signal); verrouillage_gestionnaire_signaux(); -# ifdef _BROKEN_SIGINFO - pid = origine_signal(signal); -# else - pid = (*siginfo).si_pid; -# endif - if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) { deverrouillage_gestionnaire_signaux(); @@ -2377,6 +2470,7 @@ interruption11(SIGHANDLER_ARGS) struct_processus *s_etat_processus; + test_signal(signal); verrouillage_gestionnaire_signaux(); # ifdef _BROKEN_SIGINFO @@ -2463,4 +2557,78 @@ traitement_exceptions_gsl(const char *re return; } +static inline void +structation_interruptions_elementaires(struct_processus *s_etat_processus, + int signal, pid_t pid) +{ + switch(signal) + { + case SIGINT: + case SIGTERM: + case SIGALRM: + { + corps_interruption1(s_etat_processus, signal, pid); + break; + } + + case SIGTSTP: + { + corps_interruption2(s_etat_processus, signal, pid); + } + } + + return; +} + +void +scrutation_interruptions(struct_processus *s_etat_processus) +{ + int i; + + // Interruption par processus. + + if (pthread_mutex_lock(&mutex_signal) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + + if (queue_interruptions.nombre_interruptions_en_queue > 0) + { + for(i = 0; i < SIGNAL_MAX; i++) + { + if ((queue_interruptions.pointeur[i][ECRITURE] - + queue_interruptions.pointeur[i][LECTURE]) != 0) + { + // Il y a une interruption dans la queue. + + queue_interruptions.nombre_interruptions_en_queue--; + scrutation_interruptions_elementaires(s_etat_processus, i, + queue_interruptions.pid[signal] + [queue_interruptions.pointeur[signal][LECTURE]]); + queue_interruptions.pointeur[signal][LECTURE] = + (queue_interruptions.pointeur[signal][LECTURE] + 1) + % SIGNAL_BUFFER; + } + } + } + + if (pthread_mutex_unlock(&mutex_signal) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + + // Interruption par thread + + if ((*s_etat_processus).signal_a_traiter == d_vrai) + { + (*s_etat_processus).signal_a_traiter = d_faux; + scrutation_interruptions_elementaires(s_etat_processus, + (*s_etat_processus).signal, (*s_etat_processus).origine_signal); + } + + return; +} + // vim: ts=4