--- rpl/src/interruptions.c 2010/04/29 15:47:25 1.12 +++ rpl/src/interruptions.c 2010/04/30 15:01:14 1.13 @@ -82,30 +82,9 @@ insertion_thread(struct_processus *s_eta sigfillset(&set); pthread_sigmask(SIG_BLOCK, &set, &oldset); -# ifndef SEMAPHORES_NOMMES - while(sem_wait(&semaphore_liste_threads) == -1) -# else - while(sem_wait(semaphore_liste_threads) == -1) -# endif - { - if (errno != EINTR) - { - pthread_sigmask(SIG_SETMASK, &oldset, NULL); - sigpending(&set); - - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - } - if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile))) == NULL) { -# ifndef SEMAPHORES_NOMMES - sem_post(&semaphore_liste_threads); -# else - sem_post(semaphore_liste_threads); -# endif pthread_sigmask(SIG_SETMASK, &oldset, NULL); sigpending(&set); @@ -113,15 +92,8 @@ insertion_thread(struct_processus *s_eta return; } - (*l_nouvel_objet).suivant = liste_threads; - if (((*l_nouvel_objet).donnee = malloc(sizeof(struct_thread))) == NULL) { -# ifndef SEMAPHORES_NOMMES - sem_post(&semaphore_liste_threads); -# else - sem_post(semaphore_liste_threads); -# endif pthread_sigmask(SIG_SETMASK, &oldset, NULL); sigpending(&set); @@ -136,6 +108,24 @@ insertion_thread(struct_processus *s_eta (*((struct_thread *) (*l_nouvel_objet).donnee)).s_etat_processus = s_etat_processus; +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&semaphore_liste_threads) == -1) +# else + while(sem_wait(semaphore_liste_threads) == -1) +# endif + { + if (errno != EINTR) + { + pthread_sigmask(SIG_SETMASK, &oldset, NULL); + sigpending(&set); + + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + } + + (*l_nouvel_objet).suivant = liste_threads; + liste_threads = l_nouvel_objet; # ifndef SEMAPHORES_NOMMES @@ -168,6 +158,16 @@ insertion_thread_surveillance(struct_pro sigfillset(&set); pthread_sigmask(SIG_BLOCK, &set, &oldset); + if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile))) + == NULL) + { + pthread_sigmask(SIG_SETMASK, &oldset, NULL); + sigpending(&set); + + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + # ifndef SEMAPHORES_NOMMES while(sem_wait(&semaphore_liste_threads) == -1) # else @@ -184,21 +184,6 @@ insertion_thread_surveillance(struct_pro } } - if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile))) - == NULL) - { -# ifndef SEMAPHORES_NOMMES - sem_post(&semaphore_liste_threads); -# else - sem_post(semaphore_liste_threads); -# endif - pthread_sigmask(SIG_SETMASK, &oldset, NULL); - sigpending(&set); - - (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; - return; - } - (*l_nouvel_objet).suivant = liste_threads_surveillance; (*l_nouvel_objet).donnee = (void *) s_argument_thread; @@ -289,9 +274,6 @@ retrait_thread(struct_processus *s_etat_ (*l_element_precedent).suivant = (*l_element_courant).suivant; } - free((void *) (*l_element_courant).donnee); - free((struct_liste_chainee_volatile *) l_element_courant); - if (pthread_setspecific(semaphore_fork_processus_courant, NULL) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -319,6 +301,9 @@ retrait_thread(struct_processus *s_etat_ return; } + free((void *) (*l_element_courant).donnee); + free((struct_liste_chainee_volatile *) l_element_courant); + pthread_sigmask(SIG_SETMASK, &oldset, NULL); sigpending(&set); return; @@ -381,6 +366,7 @@ retrait_thread_surveillance(struct_proce return; } + // l_element_courant->donnee n'est pas bonne lorsque ça part en vrille. if (l_element_precedent == NULL) { liste_threads_surveillance = (*l_element_courant).suivant; @@ -390,8 +376,6 @@ retrait_thread_surveillance(struct_proce (*l_element_precedent).suivant = (*l_element_courant).suivant; } - free((struct_liste_chainee_volatile *) l_element_courant); - if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) { # ifndef SEMAPHORES_NOMMES @@ -461,6 +445,8 @@ retrait_thread_surveillance(struct_proce return; } + free((struct_liste_chainee_volatile *) l_element_courant); + pthread_sigmask(SIG_SETMASK, &oldset, NULL); sigpending(&set); return; @@ -641,6 +627,8 @@ liberation_threads(struct_processus *s_e close((*s_etat_processus).pipe_nombre_objets_attente); close((*s_etat_processus).pipe_nombre_interruptions_attente); + liberation(s_etat_processus, (*s_etat_processus).at_exit); + if ((*s_etat_processus).nom_fichier_impression != NULL) { free((*s_etat_processus).nom_fichier_impression);