version 1.1.1.1, 2010/01/26 15:22:44
|
version 1.31, 2010/08/17 14:15:20
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.9 |
RPL/2 (R) version 4.0.18 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
Line 20
|
Line 20
|
*/ |
*/ |
|
|
|
|
#include "rpl.conv.h" |
#include "rpl-conv.h" |
|
|
|
|
/* |
/* |
Line 82 insertion_thread(struct_processus *s_eta
|
Line 82 insertion_thread(struct_processus *s_eta
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
while(sem_wait(&semaphore_liste_threads) == -1) |
|
{ |
|
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))) |
if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile))) |
== NULL) |
== NULL) |
{ |
{ |
sem_post(&semaphore_liste_threads); |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 105 insertion_thread(struct_processus *s_eta
|
Line 92 insertion_thread(struct_processus *s_eta
|
return; |
return; |
} |
} |
|
|
(*l_nouvel_objet).suivant = liste_threads; |
|
|
|
if (((*l_nouvel_objet).donnee = malloc(sizeof(struct_thread))) == NULL) |
if (((*l_nouvel_objet).donnee = malloc(sizeof(struct_thread))) == NULL) |
{ |
{ |
sem_post(&semaphore_liste_threads); |
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 124 insertion_thread(struct_processus *s_eta
|
Line 108 insertion_thread(struct_processus *s_eta
|
(*((struct_thread *) (*l_nouvel_objet).donnee)).s_etat_processus = |
(*((struct_thread *) (*l_nouvel_objet).donnee)).s_etat_processus = |
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; |
liste_threads = l_nouvel_objet; |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
Line 152 insertion_thread_surveillance(struct_pro
|
Line 157 insertion_thread_surveillance(struct_pro
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
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) |
while(sem_wait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_wait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 164 insertion_thread_surveillance(struct_pro
|
Line 183 insertion_thread_surveillance(struct_pro
|
} |
} |
} |
} |
|
|
if ((l_nouvel_objet = malloc(sizeof(struct_liste_chainee_volatile))) |
pthread_mutex_lock(&((*s_argument_thread).mutex)); |
== NULL) |
(*s_argument_thread).nombre_references++; |
{ |
pthread_mutex_unlock(&((*s_argument_thread).mutex)); |
sem_post(&semaphore_liste_threads); |
|
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).suivant = liste_threads_surveillance; |
(*l_nouvel_objet).donnee = (void *) s_argument_thread; |
(*l_nouvel_objet).donnee = (void *) s_argument_thread; |
|
|
liste_threads_surveillance = l_nouvel_objet; |
liste_threads_surveillance = l_nouvel_objet; |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
Line 206 retrait_thread(struct_processus *s_etat_
|
Line 222 retrait_thread(struct_processus *s_etat_
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_liste_threads) == -1) |
while(sem_wait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_wait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 236 retrait_thread(struct_processus *s_etat_
|
Line 256 retrait_thread(struct_processus *s_etat_
|
|
|
if (l_element_courant == NULL) |
if (l_element_courant == NULL) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 253 retrait_thread(struct_processus *s_etat_
|
Line 277 retrait_thread(struct_processus *s_etat_
|
(*l_element_precedent).suivant = (*l_element_courant).suivant; |
(*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) |
if (pthread_setspecific(semaphore_fork_processus_courant, NULL) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
|
|
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
return; |
return; |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
|
Line 275 retrait_thread(struct_processus *s_etat_
|
Line 304 retrait_thread(struct_processus *s_etat_
|
return; |
return; |
} |
} |
|
|
|
free((void *) (*l_element_courant).donnee); |
|
free((struct_liste_chainee_volatile *) l_element_courant); |
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
return; |
return; |
Line 293 retrait_thread_surveillance(struct_proce
|
Line 325 retrait_thread_surveillance(struct_proce
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_liste_threads) == -1) |
while(sem_wait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_wait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 321 retrait_thread_surveillance(struct_proce
|
Line 357 retrait_thread_surveillance(struct_proce
|
|
|
if (l_element_courant == NULL) |
if (l_element_courant == NULL) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
sem_post(&semaphore_liste_threads); |
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 338 retrait_thread_surveillance(struct_proce
|
Line 378 retrait_thread_surveillance(struct_proce
|
(*l_element_precedent).suivant = (*l_element_courant).suivant; |
(*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) |
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
|
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 359 retrait_thread_surveillance(struct_proce
|
Line 402 retrait_thread_surveillance(struct_proce
|
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
|
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 373 retrait_thread_surveillance(struct_proce
|
Line 421 retrait_thread_surveillance(struct_proce
|
{ |
{ |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
|
sem_post(&semaphore_liste_threads); |
|
# else |
|
sem_post(semaphore_liste_threads); |
|
# endif |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
Line 381 retrait_thread_surveillance(struct_proce
|
Line 434 retrait_thread_surveillance(struct_proce
|
} |
} |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
Line 390 retrait_thread_surveillance(struct_proce
|
Line 447 retrait_thread_surveillance(struct_proce
|
return; |
return; |
} |
} |
|
|
|
free((struct_liste_chainee_volatile *) l_element_courant); |
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
sigpending(&set); |
sigpending(&set); |
|
|
return; |
return; |
} |
} |
|
|
Line 400 verrouillage_threads_concurrents(struct_
|
Line 460 verrouillage_threads_concurrents(struct_
|
{ |
{ |
volatile struct_liste_chainee_volatile *l_element_courant; |
volatile struct_liste_chainee_volatile *l_element_courant; |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_liste_threads) == -1) |
while(sem_wait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_wait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 417 verrouillage_threads_concurrents(struct_
|
Line 481 verrouillage_threads_concurrents(struct_
|
== getpid()) && (pthread_equal((*((struct_thread *) |
== getpid()) && (pthread_equal((*((struct_thread *) |
(*l_element_courant).donnee)).tid, pthread_self()) == 0)) |
(*l_element_courant).donnee)).tid, pthread_self()) == 0)) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&((*(*((struct_thread *) (*l_element_courant) |
while(sem_wait(&((*(*((struct_thread *) (*l_element_courant) |
.donnee)).s_etat_processus).semaphore_fork)) == -1) |
.donnee)).s_etat_processus).semaphore_fork)) == -1) |
|
# else |
|
while(sem_wait((*(*((struct_thread *) (*l_element_courant) |
|
.donnee)).s_etat_processus).semaphore_fork) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 447 deverrouillage_threads_concurrents(struc
|
Line 516 deverrouillage_threads_concurrents(struc
|
== getpid()) && (pthread_equal((*((struct_thread *) |
== getpid()) && (pthread_equal((*((struct_thread *) |
(*l_element_courant).donnee)).tid, pthread_self()) == 0)) |
(*l_element_courant).donnee)).tid, pthread_self()) == 0)) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&((*(*((struct_thread *) |
if (sem_post(&((*(*((struct_thread *) |
(*l_element_courant).donnee)).s_etat_processus) |
(*l_element_courant).donnee)).s_etat_processus) |
.semaphore_fork)) != 0) |
.semaphore_fork)) != 0) |
|
# else |
|
if (sem_post((*(*((struct_thread *) |
|
(*l_element_courant).donnee)).s_etat_processus) |
|
.semaphore_fork) != 0) |
|
# endif |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
# endif |
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
Line 465 deverrouillage_threads_concurrents(struc
|
Line 548 deverrouillage_threads_concurrents(struc
|
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
Line 498 liberation_threads(struct_processus *s_e
|
Line 585 liberation_threads(struct_processus *s_e
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_liste_threads) == -1) |
while(sem_wait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_wait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 539 liberation_threads(struct_processus *s_e
|
Line 630 liberation_threads(struct_processus *s_e
|
close((*s_etat_processus).pipe_nombre_objets_attente); |
close((*s_etat_processus).pipe_nombre_objets_attente); |
close((*s_etat_processus).pipe_nombre_interruptions_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) |
if ((*s_etat_processus).nom_fichier_impression != NULL) |
{ |
{ |
free((*s_etat_processus).nom_fichier_impression); |
free((*s_etat_processus).nom_fichier_impression); |
Line 580 liberation_threads(struct_processus *s_e
|
Line 673 liberation_threads(struct_processus *s_e
|
.l_base_pile_processus; |
.l_base_pile_processus; |
while(element_courant != NULL) |
while(element_courant != NULL) |
{ |
{ |
pthread_mutex_trylock(&((*(*((struct_liste_chainee *) |
s_argument_thread = (struct_descripteur_thread *) |
element_courant)).donnee).mutex)); |
(*((struct_liste_chainee *) element_courant)).donnee; |
pthread_mutex_unlock(&((*(*((struct_liste_chainee *) |
|
element_courant)).donnee).mutex)); |
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
liberation(s_etat_processus, |
{ |
(*((struct_liste_chainee *) element_courant)).donnee); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
|
return; |
|
} |
|
|
|
(*s_argument_thread).nombre_references--; |
|
|
|
BUG((*s_argument_thread).nombre_references < 0, |
|
printf("(*s_argument_thread).nombre_references = %d\n", |
|
(int) (*s_argument_thread).nombre_references)); |
|
|
|
if ((*s_argument_thread).nombre_references == 0) |
|
{ |
|
close((*s_argument_thread).pipe_objets[0]); |
|
close((*s_argument_thread).pipe_acquittement[1]); |
|
close((*s_argument_thread).pipe_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_objets_attente[0]); |
|
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) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
|
return; |
|
} |
|
|
|
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
|
|
|
if ((*s_argument_thread).processus_detache == d_faux) |
|
{ |
|
if ((*s_argument_thread).destruction_objet == d_vrai) |
|
{ |
|
liberation(s_etat_processus, (*s_argument_thread) |
|
.argument); |
|
} |
|
} |
|
|
|
free(s_argument_thread); |
|
} |
|
else |
|
{ |
|
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) |
|
!= 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
|
return; |
|
} |
|
} |
|
|
element_suivant = (*((struct_liste_chainee *) element_courant)) |
element_suivant = (*((struct_liste_chainee *) element_courant)) |
.suivant; |
.suivant; |
free((struct_liste_chainee *) element_courant); |
free(element_courant); |
element_courant = element_suivant; |
element_courant = element_suivant; |
} |
} |
|
|
|
(*s_etat_processus).l_base_pile_processus = NULL; |
|
|
pthread_mutex_trylock(&((*(*s_etat_processus).indep).mutex)); |
pthread_mutex_trylock(&((*(*s_etat_processus).indep).mutex)); |
pthread_mutex_unlock(&((*(*s_etat_processus).indep).mutex)); |
pthread_mutex_unlock(&((*(*s_etat_processus).indep).mutex)); |
liberation(s_etat_processus, (*s_etat_processus).indep); |
liberation(s_etat_processus, (*s_etat_processus).indep); |
Line 916 liberation_threads(struct_processus *s_e
|
Line 1064 liberation_threads(struct_processus *s_e
|
{ |
{ |
if (((*((struct_descripteur_fichier *) |
if (((*((struct_descripteur_fichier *) |
(*((struct_liste_chainee *) element_courant)) |
(*((struct_liste_chainee *) element_courant)) |
.donnee)).descripteur == |
|
(*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_candidat)) |
|
.donnee)).descripteur) && |
|
((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_courant)) |
|
.donnee)).pid == |
.donnee)).pid == |
(*((struct_descripteur_fichier *) |
(*((struct_descripteur_fichier *) |
(*((struct_liste_chainee *) element_candidat)) |
(*((struct_liste_chainee *) element_candidat)) |
Line 932 liberation_threads(struct_processus *s_e
|
Line 1074 liberation_threads(struct_processus *s_e
|
(*((struct_liste_chainee *) element_candidat)) |
(*((struct_liste_chainee *) element_candidat)) |
.donnee)).tid) != 0)) |
.donnee)).tid) != 0)) |
{ |
{ |
break; |
if ((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_courant)) |
|
.donnee)).type == |
|
(*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_candidat)) |
|
.donnee)).type) |
|
{ |
|
if ((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_candidat)).donnee)).type == 'C') |
|
{ |
|
if ((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_courant)).donnee)) |
|
.descripteur_c == |
|
(*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_candidat)).donnee)) |
|
.descripteur_c) |
|
{ |
|
break; |
|
} |
|
} |
|
else |
|
{ |
|
if (((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_courant)).donnee)) |
|
.descripteur_sqlite == |
|
(*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_candidat)).donnee)) |
|
.descripteur_sqlite) && |
|
((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_courant)).donnee)) |
|
.descripteur_c == |
|
(*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) |
|
element_candidat)).donnee)) |
|
.descripteur_c)) |
|
{ |
|
break; |
|
} |
|
} |
|
} |
} |
} |
|
|
element_candidat = (*((struct_liste_chainee *) |
element_candidat = (*((struct_liste_chainee *) |
Line 943 liberation_threads(struct_processus *s_e
|
Line 1130 liberation_threads(struct_processus *s_e
|
{ |
{ |
fclose((*((struct_descripteur_fichier *) |
fclose((*((struct_descripteur_fichier *) |
(*((struct_liste_chainee *) element_courant)) |
(*((struct_liste_chainee *) element_courant)) |
.donnee)).descripteur); |
.donnee)).descripteur_c); |
|
|
|
if ((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_courant)) |
|
.donnee)).type != 'C') |
|
{ |
|
sqlite3_close((*((struct_descripteur_fichier *) |
|
(*((struct_liste_chainee *) element_courant)) |
|
.donnee)).descripteur_sqlite); |
|
} |
} |
} |
|
|
free((*((struct_descripteur_fichier *) |
free((*((struct_descripteur_fichier *) |
Line 1018 liberation_threads(struct_processus *s_e
|
Line 1214 liberation_threads(struct_processus *s_e
|
element_courant = element_suivant; |
element_courant = element_suivant; |
} |
} |
|
|
|
/* |
|
================================================================================ |
|
À noter : on ne ferme pas la connexion car la conséquence immédiate est |
|
une destruction de l'objet pour le processus père. |
|
================================================================================ |
|
|
element_courant = (*s_etat_processus).s_connecteurs_sql; |
element_courant = (*s_etat_processus).s_connecteurs_sql; |
while(element_courant != NULL) |
while(element_courant != NULL) |
{ |
{ |
Line 1101 liberation_threads(struct_processus *s_e
|
Line 1303 liberation_threads(struct_processus *s_e
|
|
|
element_courant = element_suivant; |
element_courant = element_suivant; |
} |
} |
|
*/ |
|
|
|
(*s_etat_processus).s_connecteurs_sql = NULL; |
|
|
element_courant = (*s_etat_processus).s_marques; |
element_courant = (*s_etat_processus).s_marques; |
while(element_courant != NULL) |
while(element_courant != NULL) |
Line 1115 liberation_threads(struct_processus *s_e
|
Line 1320 liberation_threads(struct_processus *s_e
|
|
|
liberation_allocateur(s_etat_processus); |
liberation_allocateur(s_etat_processus); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
sem_post(&((*s_etat_processus).semaphore_fork)); |
sem_post(&((*s_etat_processus).semaphore_fork)); |
sem_destroy(&((*s_etat_processus).semaphore_fork)); |
sem_destroy(&((*s_etat_processus).semaphore_fork)); |
|
# else |
|
sem_post((*s_etat_processus).semaphore_fork); |
|
sem_destroy2((*s_etat_processus).semaphore_fork, sem_fork); |
|
# endif |
|
|
free(s_etat_processus); |
free(s_etat_processus); |
|
|
Line 1140 liberation_threads(struct_processus *s_e
|
Line 1350 liberation_threads(struct_processus *s_e
|
s_argument_thread = (struct_descripteur_thread *) |
s_argument_thread = (struct_descripteur_thread *) |
(*l_element_courant).donnee; |
(*l_element_courant).donnee; |
|
|
close((*s_argument_thread).pipe_objets[0]); |
|
close((*s_argument_thread).pipe_acquittement[1]); |
|
close((*s_argument_thread).pipe_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_objets_attente[0]); |
|
close((*s_argument_thread).pipe_interruptions[0]); |
|
close((*s_argument_thread).pipe_nombre_interruptions_attente[0]); |
|
|
|
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_argument_thread).mutex)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
return; |
return; |
} |
} |
|
|
Line 1162 liberation_threads(struct_processus *s_e
|
Line 1365 liberation_threads(struct_processus *s_e
|
|
|
if ((*s_argument_thread).nombre_references == 0) |
if ((*s_argument_thread).nombre_references == 0) |
{ |
{ |
|
close((*s_argument_thread).pipe_objets[0]); |
|
close((*s_argument_thread).pipe_acquittement[1]); |
|
close((*s_argument_thread).pipe_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_injections[1]); |
|
close((*s_argument_thread).pipe_nombre_objets_attente[0]); |
|
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)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
return; |
return; |
} |
} |
|
|
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
pthread_mutex_destroy(&((*s_argument_thread).mutex)); |
|
|
|
if ((*s_argument_thread).processus_detache == d_faux) |
|
{ |
|
if ((*s_argument_thread).destruction_objet == d_vrai) |
|
{ |
|
liberation(s_etat_processus, (*s_argument_thread).argument); |
|
} |
|
} |
|
|
free(s_argument_thread); |
free(s_argument_thread); |
} |
} |
else |
else |
Line 1176 liberation_threads(struct_processus *s_e
|
Line 1397 liberation_threads(struct_processus *s_e
|
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
if (pthread_mutex_unlock(&((*s_argument_thread).mutex)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
sem_post(&semaphore_liste_threads); |
return; |
return; |
} |
} |
} |
} |
Line 1187 liberation_threads(struct_processus *s_e
|
Line 1409 liberation_threads(struct_processus *s_e
|
|
|
liste_threads_surveillance = NULL; |
liste_threads_surveillance = NULL; |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 1282 recherche_thread_principal(pid_t pid, pt
|
Line 1508 recherche_thread_principal(pid_t pid, pt
|
*/ |
*/ |
|
|
// Les routines suivantes sont uniquement appelées depuis les gestionnaires |
// Les routines suivantes sont uniquement appelées depuis les gestionnaires |
// des signaux asynchrones. Elles de doivent pas bloquer dans le cas où |
// des signaux asynchrones. Elles ne doivent pas bloquer dans le cas où |
// les sémaphores sont déjà bloqués par un gestionnaire de signal. |
// les sémaphores sont déjà bloqués par un gestionnaire de signal. |
|
|
static inline void |
static inline void |
Line 1310 verrouillage_gestionnaire_signaux()
|
Line 1536 verrouillage_gestionnaire_signaux()
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1) |
while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1) |
|
# else |
|
while(sem_wait(semaphore_gestionnaires_signaux_atomique) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 1320 verrouillage_gestionnaire_signaux()
|
Line 1550 verrouillage_gestionnaire_signaux()
|
} |
} |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_gestionnaires_signaux) == -1) |
if (sem_post(&semaphore_gestionnaires_signaux) == -1) |
|
# else |
|
if (sem_post(semaphore_gestionnaires_signaux) == -1) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
BUG(1, uprintf("Lock error !\n")); |
BUG(1, uprintf("Lock error !\n")); |
return; |
return; |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0) |
if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0) |
|
# else |
|
if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
BUG(1, uprintf("Lock error !\n")); |
BUG(1, uprintf("Lock error !\n")); |
return; |
return; |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0) |
if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0) |
|
# else |
|
if (sem_post(semaphore_gestionnaires_signaux_atomique) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
BUG(1, uprintf("Unlock error !\n")); |
BUG(1, uprintf("Unlock error !\n")); |
Line 1349 verrouillage_gestionnaire_signaux()
|
Line 1591 verrouillage_gestionnaire_signaux()
|
// par un thread concurrent. On essaye donc de le bloquer jusqu'à |
// par un thread concurrent. On essaye donc de le bloquer jusqu'à |
// ce que ce soit possible. |
// ce que ce soit possible. |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_trywait(&semaphore_liste_threads) == -1) |
while(sem_trywait(&semaphore_liste_threads) == -1) |
|
# else |
|
while(sem_trywait(semaphore_liste_threads) == -1) |
|
# endif |
{ |
{ |
if ((errno != EINTR) && (errno != EAGAIN)) |
if ((errno != EINTR) && (errno != EAGAIN)) |
{ |
{ |
Line 1393 deverrouillage_gestionnaire_signaux()
|
Line 1639 deverrouillage_gestionnaire_signaux()
|
sigfillset(&set); |
sigfillset(&set); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
pthread_sigmask(SIG_BLOCK, &set, &oldset); |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1) |
while(sem_wait(&semaphore_gestionnaires_signaux_atomique) == -1) |
|
# else |
|
while(sem_wait(semaphore_gestionnaires_signaux_atomique) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 1403 deverrouillage_gestionnaire_signaux()
|
Line 1653 deverrouillage_gestionnaire_signaux()
|
} |
} |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0) |
if (sem_getvalue(&semaphore_gestionnaires_signaux, &semaphore) != 0) |
|
# else |
|
if (sem_getvalue(semaphore_gestionnaires_signaux, &semaphore) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
BUG(1, uprintf("Unlock error !\n")); |
BUG(1, uprintf("Unlock error !\n")); |
return; |
return; |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&semaphore_gestionnaires_signaux) == -1) |
while(sem_wait(&semaphore_gestionnaires_signaux) == -1) |
|
# else |
|
while(sem_wait(semaphore_gestionnaires_signaux) == -1) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 1420 deverrouillage_gestionnaire_signaux()
|
Line 1678 deverrouillage_gestionnaire_signaux()
|
} |
} |
} |
} |
|
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0) |
if (sem_post(&semaphore_gestionnaires_signaux_atomique) != 0) |
|
# else |
|
if (sem_post(semaphore_gestionnaires_signaux_atomique) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
BUG(1, uprintf("Unlock error !\n")); |
BUG(1, uprintf("Unlock error !\n")); |
Line 1443 deverrouillage_gestionnaire_signaux()
|
Line 1705 deverrouillage_gestionnaire_signaux()
|
|
|
if (semaphore == 1) |
if (semaphore == 1) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&semaphore_liste_threads) != 0) |
if (sem_post(&semaphore_liste_threads) != 0) |
|
# else |
|
if (sem_post(semaphore_liste_threads) != 0) |
|
# endif |
{ |
{ |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
pthread_sigmask(SIG_SETMASK, &oldset, NULL); |
|
|
Line 1458 deverrouillage_gestionnaire_signaux()
|
Line 1724 deverrouillage_gestionnaire_signaux()
|
return; |
return; |
} |
} |
|
|
|
#ifdef _BROKEN_SIGINFO |
|
|
|
static int *fifos; |
|
static int segment; |
|
static int segment_mutexes; |
|
static int longueur_queue; |
|
static int nombre_queues; |
|
|
|
static pthread_mutex_t *mutexes; |
|
|
|
static unsigned char *chemin = NULL; |
|
|
|
unsigned char * |
|
nom_segment(unsigned char *chemin, pid_t pid) |
|
{ |
|
unsigned char *fichier; |
|
|
|
if ((fichier = malloc((strlen(chemin) + 1 + 256 + 1) * |
|
sizeof(unsigned char))) == NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
sprintf(fichier, "%s/RPL-SIGQUEUES-%d", chemin, (int) pid); |
|
|
|
return(fichier); |
|
} |
|
|
|
unsigned char * |
|
nom_segment_mutexes(unsigned char *chemin, pid_t pid) |
|
{ |
|
unsigned char *fichier; |
|
|
|
if ((fichier = malloc((strlen(chemin) + 1 + 256 + 1) * |
|
sizeof(unsigned char))) == NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
sprintf(fichier, "%s/RPL-SIGMUTEXES-%d", chemin, (int) pid); |
|
|
|
return(fichier); |
|
} |
|
|
|
int |
|
queue_de_signal(int signal) |
|
{ |
|
switch(signal) |
|
{ |
|
case SIGINT: |
|
BUG(1, uprintf("SIGINT is not queued as it does not " |
|
"come from program itself !\n")); |
|
return(0); |
|
case SIGTSTP: |
|
return(1); |
|
case SIGCONT: |
|
return(2); |
|
case SIGURG: |
|
return(3); |
|
case SIGPIPE: |
|
return(4); |
|
case SIGALRM: |
|
return(5); |
|
case SIGFSTOP: |
|
return(6); |
|
case SIGSTART: |
|
return(7); |
|
case SIGINJECT: |
|
return(8); |
|
case SIGABORT: |
|
return(9); |
|
case SIGFABORT: |
|
return(10); |
|
} |
|
|
|
return(-1); |
|
} |
|
|
|
void |
|
creation_fifos_signaux(struct_processus *s_etat_processus) |
|
{ |
|
file *desc; |
|
|
|
int i; |
|
|
|
key_t clef; |
|
|
|
pthread_mutexattr_t attributs_mutex; |
|
|
|
unsigned char *nom; |
|
|
|
/* |
|
* Signaux utilisés |
|
* SIGINT, SIGTSTP, SIGCONT, SIGURG, SIGPIPE, SIGALRM, SIGFSTOP, |
|
* SIGSTART, SIGINJECT, SIGABORT, SIGFABORT |
|
*/ |
|
|
|
// Création d'un segment de données associé au PID du processus courant |
|
|
|
chemin = (*s_etat_processus).chemin_fichiers_temporaires; |
|
|
|
if ((nom = nom_segment((*s_etat_processus).chemin_fichiers_temporaires, |
|
getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
/* |
|
* Structure d'une queue |
|
* 0 : pointeur en lecture sur le premier emplacement libre (int) |
|
* 1 : pointeur en écriture sur le premier emplacement à lire (int) |
|
* 2 : longueur de la queue (int) |
|
* 3 : éléments restants (int) |
|
* 4 à 4 + (2) : queue (int) |
|
* 5 : mutex |
|
*/ |
|
|
|
nombre_queues = 11; |
|
longueur_queue = 256; |
|
|
|
if ((desc = fopen(nom, "w")) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return; |
|
} |
|
|
|
fclose(desc); |
|
|
|
if ((clef = ftok(nom, 1)) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
|
|
if ((segment = shmget(clef, |
|
nombre_queues * (longueur_queue + 4) * sizeof(int), |
|
IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
fifos = shmat(segment, NULL, 0); |
|
|
|
if (((void *) fifos) == ((void *) -1)) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
for(i = 0; i < nombre_queues; i++) |
|
{ |
|
fifos[(i * (longueur_queue + 4))] = 0; |
|
fifos[(i * (longueur_queue + 4)) + 1] = 0; |
|
fifos[(i * (longueur_queue + 4)) + 2] = longueur_queue; |
|
fifos[(i * (longueur_queue + 4)) + 3] = longueur_queue; |
|
} |
|
|
|
if ((nom = nom_segment_mutexes((*s_etat_processus) |
|
.chemin_fichiers_temporaires, getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if ((desc = fopen(nom, "w")) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_erreur_fichier; |
|
return; |
|
} |
|
|
|
fclose(desc); |
|
|
|
if ((clef = ftok(nom, 1)) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
|
|
if ((segment_mutexes = shmget(clef, |
|
nombre_queues * sizeof(pthread_mutex_t), |
|
IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR)) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
mutexes = shmat(segment_mutexes, NULL, 0); |
|
|
|
if (((void *) mutexes) == ((void *) -1)) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
/* |
|
* Création et initialisation d'un mutex par queue. Ce mutex n'est pas |
|
* dans le premier segment parce qu'il peut y avoir des problèmes |
|
* d'alignements sur certaines architectures. |
|
*/ |
|
|
|
pthread_mutexattr_init(&attributs_mutex); |
|
pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE); |
|
|
|
for(i = 0; i < nombre_queues; i++) |
|
{ |
|
pthread_mutex_init(&(mutexes[i]), &attributs_mutex); |
|
} |
|
|
|
pthread_mutexattr_destroy(&attributs_mutex); |
|
return; |
|
} |
|
|
|
void |
|
liberation_fifos_signaux(struct_processus *s_etat_processus) |
|
{ |
|
if (shmdt(fifos) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (shmdt(mutexes) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
return; |
|
} |
|
|
void |
void |
interruption1(int signal, siginfo_t *siginfo, void *context) |
destruction_fifos_signaux(struct_processus *s_etat_processus) |
{ |
{ |
|
int i; |
|
|
|
unsigned char *nom; |
|
|
|
if (shmdt(fifos) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (shmctl(segment, IPC_RMID, 0) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
for(i = 0; i < nombre_queues; i++) |
|
{ |
|
pthread_mutex_destroy(&(mutexes[i])); |
|
} |
|
|
|
if (shmdt(mutexes) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (shmctl(segment_mutexes, IPC_RMID, 0) == -1) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if ((nom = nom_segment_mutexes((*s_etat_processus) |
|
.chemin_fichiers_temporaires, getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
unlink(nom); |
|
free(nom); |
|
|
|
if ((nom = nom_segment((*s_etat_processus).chemin_fichiers_temporaires, |
|
getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
unlink(nom); |
|
free(nom); |
|
|
|
return; |
|
} |
|
|
|
int |
|
queue_in(pid_t pid, int signal) |
|
{ |
|
int *base; |
|
int *buffer; |
|
int *projection_fifos; |
|
int queue; |
|
int identifiant; |
|
|
|
key_t clef; |
|
|
|
pthread_mutex_t *projection_mutexes; |
|
|
|
unsigned char *nom; |
|
|
|
queue = queue_de_signal(signal); |
|
|
|
// Ouverture des projections |
|
|
|
if ((nom = nom_segment(chemin, pid)) == NULL) |
|
{ |
|
return(-1); |
|
} |
|
|
|
if ((clef = ftok(nom, 1)) == -1) |
|
{ |
|
free(nom); |
|
return(-1); |
|
} |
|
|
|
free(nom); |
|
|
|
while((identifiant = shmget(clef, |
|
nombre_queues * (longueur_queue + 4) * sizeof(int), |
|
S_IRUSR | S_IWUSR)) == -1); |
|
|
|
projection_fifos = shmat(identifiant, NULL, 0); |
|
|
|
if ((nom = nom_segment_mutexes(chemin, pid)) == NULL) |
|
{ |
|
return(-1); |
|
} |
|
|
|
if ((clef = ftok(nom, 1)) == -1) |
|
{ |
|
free(nom); |
|
return(-1); |
|
} |
|
|
|
free(nom); |
|
|
|
while((identifiant = shmget(clef, |
|
nombre_queues * sizeof(pthread_mutex_t), |
|
S_IRUSR | S_IWUSR)) == -1); |
|
|
|
projection_mutexes = shmat(identifiant, NULL, 0); |
|
|
|
if (pthread_mutex_lock(&(projection_mutexes[queue])) != 0) |
|
{ |
|
return(-1); |
|
} |
|
|
|
base = &(projection_fifos[(longueur_queue + 4) * queue]); |
|
buffer = &(base[4]); |
|
|
|
// base[1] contient le prochain élément à écrire |
|
buffer[base[1]++] = (int) pid; |
|
base[1] %= base[2]; |
|
|
|
// base[3] contient le nombre d'éléments non lus |
|
if (base[3] <= 0) |
|
{ |
|
pthread_mutex_unlock(&(projection_mutexes[queue])); |
|
shmdt(projection_mutexes); |
|
shmdt(projection_fifos); |
|
return(-1); |
|
} |
|
|
|
base[3]--; |
|
|
|
if (pthread_mutex_unlock(&(projection_mutexes[queue])) != 0) |
|
{ |
|
shmdt(projection_mutexes); |
|
shmdt(projection_fifos); |
|
return(-1); |
|
} |
|
|
|
// Fermeture des projections |
|
shmdt(projection_mutexes); |
|
shmdt(projection_fifos); |
|
return(0); |
|
} |
|
|
|
pid_t |
|
origine_signal(int signal) |
|
{ |
|
int *base; |
|
int *buffer; |
|
int pid; |
|
int queue; |
|
|
|
queue = queue_de_signal(signal); |
|
|
|
BUG(queue == -1, uprintf("[%d] Unknown signal %d in this context\n", |
|
(int) getpid(), signal)); |
|
|
|
if (pthread_mutex_lock(&(mutexes[queue])) != 0) |
|
{ |
|
return(-1); |
|
} |
|
|
|
base = &(fifos[(longueur_queue + 4) * queue]); |
|
buffer = &(base[4]); |
|
pid = buffer[base[0]++]; |
|
base[0] %= base[2]; |
|
base[3]++; |
|
|
|
if (base[3] > base[2]) |
|
{ |
|
pthread_mutex_unlock(&(mutexes[queue])); |
|
return(-1); |
|
} |
|
if (pthread_mutex_unlock(&(mutexes[queue])) != 0) |
|
{ |
|
perror("unlock"); |
|
return(-1); |
|
} |
|
|
|
return((pid_t) pid); |
|
} |
|
|
|
#endif |
|
|
|
void |
|
interruption1(SIGHANDLER_ARGS) |
|
{ |
|
pid_t pid; |
|
|
pthread_t thread; |
pthread_t thread; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
volatile sig_atomic_t exclusion = 0; |
volatile sig_atomic_t exclusion = 0; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
if (signal == SIGINT) |
|
{ |
|
// Si l'interruption provient du clavier, il n'y a pas eu d'appel |
|
// à queue_in(). |
|
|
|
pid = getpid(); |
|
} |
|
else |
|
{ |
|
pid = origine_signal(signal); |
|
} |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
switch(signal) |
switch(signal) |
{ |
{ |
case SIGALRM : |
case SIGALRM : |
{ |
{ |
if ((*siginfo).si_pid == getpid()) |
if (pid == getpid()) |
{ |
{ |
if ((s_etat_processus = recherche_thread(getpid(), |
if ((s_etat_processus = recherche_thread(getpid(), |
pthread_self())) == NULL) |
pthread_self())) == NULL) |
{ |
{ |
deverrouillage_gestionnaire_signaux(); |
deverrouillage_gestionnaire_signaux(); |
return; |
return; |
} |
} |
|
|
if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) |
if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) |
Line 1518 interruption1(int signal, siginfo_t *sig
|
Line 2230 interruption1(int signal, siginfo_t *sig
|
* Solaris suit en particulier cette spécification. |
* Solaris suit en particulier cette spécification. |
*/ |
*/ |
|
|
|
# ifndef _BROKEN_SIGINFO |
if (siginfo == NULL) |
if (siginfo == NULL) |
{ |
{ |
kill(getpid(), signal); |
kill(getpid(), signal); |
} |
} |
else if ((*siginfo).si_pid == getpid()) |
else |
|
# endif |
|
if (pid == getpid()) |
{ |
{ |
if ((s_etat_processus = recherche_thread(getpid(), |
if ((s_etat_processus = recherche_thread(getpid(), |
pthread_self())) == NULL) |
pthread_self())) == NULL) |
Line 1597 interruption1(int signal, siginfo_t *sig
|
Line 2312 interruption1(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption2(int signal, siginfo_t *siginfo, void *context) |
interruption2(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
pthread_t thread; |
pthread_t thread; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
|
# ifndef _BROKEN_SIGINFO |
if (siginfo == NULL) |
if (siginfo == NULL) |
{ |
{ |
/* |
/* |
Line 1621 interruption2(int signal, siginfo_t *sig
|
Line 2346 interruption2(int signal, siginfo_t *sig
|
return; |
return; |
} |
} |
} |
} |
else if ((*siginfo).si_pid == getpid()) |
else |
|
# endif |
|
if (pid == getpid()) |
{ |
{ |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
== NULL) |
== NULL) |
Line 1669 interruption2(int signal, siginfo_t *sig
|
Line 2396 interruption2(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption3(int signal, siginfo_t *siginfo, void *context) |
interruption3(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
static int compteur = 0; |
static int compteur = 0; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1729 interruption3(int signal, siginfo_t *sig
|
Line 2464 interruption3(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption4(int signal, siginfo_t *siginfo, void *context) |
interruption4(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1757 interruption4(int signal, siginfo_t *sig
|
Line 2500 interruption4(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption5(int signal, siginfo_t *siginfo, void *context) |
interruption5(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
pthread_t thread; |
pthread_t thread; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((*siginfo).si_pid == getpid()) |
if (pid == getpid()) |
{ |
{ |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
== NULL) |
== NULL) |
Line 1798 interruption5(int signal, siginfo_t *sig
|
Line 2550 interruption5(int signal, siginfo_t *sig
|
} |
} |
else |
else |
{ |
{ |
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
|
== NULL) |
|
{ |
|
deverrouillage_gestionnaire_signaux(); |
|
return; |
|
} |
|
|
// Envoi d'un signal au thread maître du groupe. |
// Envoi d'un signal au thread maître du groupe. |
|
|
if (recherche_thread_principal(getpid(), &thread) == d_vrai) |
if (recherche_thread_principal(getpid(), &thread) == d_vrai) |
{ |
{ |
pthread_kill(thread, SIGFSTOP); |
pthread_kill(thread, signal); |
deverrouillage_gestionnaire_signaux(); |
deverrouillage_gestionnaire_signaux(); |
return; |
return; |
} |
} |
Line 1813 interruption5(int signal, siginfo_t *sig
|
Line 2572 interruption5(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption6(int signal, siginfo_t *siginfo, void *context) |
interruption6(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1837 interruption6(int signal, siginfo_t *sig
|
Line 2604 interruption6(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption7(int signal, siginfo_t *siginfo, void *context) |
interruption7(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1864 interruption7(int signal, siginfo_t *sig
|
Line 2639 interruption7(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption8(int signal, siginfo_t *siginfo, void *context) |
interruption8(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
pthread_t thread; |
pthread_t thread; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((*siginfo).si_pid == getpid()) |
if (pid == getpid()) |
{ |
{ |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
== NULL) |
== NULL) |
Line 1907 interruption8(int signal, siginfo_t *sig
|
Line 2691 interruption8(int signal, siginfo_t *sig
|
} |
} |
|
|
void |
void |
interruption9(int signal, siginfo_t *siginfo, void *context) |
interruption9(SIGHANDLER_ARGS) |
{ |
{ |
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1926 interruption9(int signal, siginfo_t *sig
|
Line 2718 interruption9(int signal, siginfo_t *sig
|
fflush(stdout); |
fflush(stdout); |
} |
} |
|
|
pthread_kill((*s_etat_processus).tid_processus_pere, SIGFSTOP); |
|
deverrouillage_gestionnaire_signaux(); |
deverrouillage_gestionnaire_signaux(); |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
if (queue_in(getpid(), signal) != 0) |
|
{ |
|
return; |
|
} |
|
|
|
interruption11(signal); |
|
# else |
|
interruption11(signal, siginfo, context); |
|
# endif |
return; |
return; |
} |
} |
|
|
void |
void |
interruption10(int signal, siginfo_t *siginfo, void *context) |
interruption10(SIGHANDLER_ARGS) |
{ |
{ |
file *fichier; |
file *fichier; |
|
|
|
pid_t pid; |
|
|
struct_processus *s_etat_processus; |
struct_processus *s_etat_processus; |
|
|
unsigned char nom[8 + 64 + 1]; |
unsigned char nom[8 + 64 + 1]; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
verrouillage_gestionnaire_signaux(); |
verrouillage_gestionnaire_signaux(); |
|
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) == NULL) |
Line 1973 interruption10(int signal, siginfo_t *si
|
Line 2783 interruption10(int signal, siginfo_t *si
|
} |
} |
|
|
void |
void |
|
interruption11(SIGHANDLER_ARGS) |
|
{ |
|
pid_t pid; |
|
|
|
pthread_t thread; |
|
|
|
struct_processus *s_etat_processus; |
|
|
|
# ifdef _BROKEN_SIGINFO |
|
pid = origine_signal(signal); |
|
# else |
|
pid = (*siginfo).si_pid; |
|
# endif |
|
|
|
verrouillage_gestionnaire_signaux(); |
|
|
|
if (pid == getpid()) |
|
{ |
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
|
== NULL) |
|
{ |
|
deverrouillage_gestionnaire_signaux(); |
|
return; |
|
} |
|
|
|
(*s_etat_processus).arret_depuis_abort = -1; |
|
|
|
if (((*s_etat_processus).type_debug & d_debug_signaux) != 0) |
|
{ |
|
printf("[%d] SIGFABORT (thread %llu)\n", (int) getpid(), |
|
(unsigned long long) pthread_self()); |
|
fflush(stdout); |
|
} |
|
|
|
/* |
|
* var_globale_traitement_retarde_stop : |
|
* 0 -> traitement immédiat |
|
* 1 -> traitement retardé (aucun signal reçu) |
|
* -1 -> traitement retardé (un ou plusieurs signaux stop reçus) |
|
*/ |
|
|
|
if ((*s_etat_processus).var_volatile_traitement_retarde_stop == 0) |
|
{ |
|
(*s_etat_processus).var_volatile_requete_arret = -1; |
|
} |
|
else |
|
{ |
|
(*s_etat_processus).var_volatile_traitement_retarde_stop = -1; |
|
} |
|
} |
|
else |
|
{ |
|
if ((s_etat_processus = recherche_thread(getpid(), pthread_self())) |
|
== NULL) |
|
{ |
|
deverrouillage_gestionnaire_signaux(); |
|
return; |
|
} |
|
|
|
(*s_etat_processus).arret_depuis_abort = -1; |
|
|
|
// Envoi d'un signal au thread maître du groupe. |
|
|
|
if (recherche_thread_principal(getpid(), &thread) == d_vrai) |
|
{ |
|
pthread_kill(thread, signal); |
|
deverrouillage_gestionnaire_signaux(); |
|
return; |
|
} |
|
} |
|
|
|
deverrouillage_gestionnaire_signaux(); |
|
return; |
|
} |
|
|
|
void |
traitement_exceptions_gsl(const char *reason, const char *file, |
traitement_exceptions_gsl(const char *reason, const char *file, |
int line, int gsl_errno) |
int line, int gsl_errno) |
{ |
{ |
Line 1991 traitement_exceptions_gsl(const char *re
|
Line 2877 traitement_exceptions_gsl(const char *re
|
return; |
return; |
} |
} |
|
|
|
#ifdef _BROKEN_SIGINFO |
|
|
|
#undef kill |
|
#undef pthread_kill |
|
|
|
int |
|
rpl_kill(pid_t pid, int signal) |
|
{ |
|
/* |
|
* Lorsqu'on veut interrompre le processus pid, on ouvre le segment |
|
* correspondant au processus en question et ou ajoute le pid dans la |
|
* queue. |
|
*/ |
|
|
|
if ((signal != 0) && (signal != SIGINT)) |
|
{ |
|
if (queue_in(pid, signal) != 0) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
|
|
return(kill(pid, signal)); |
|
} |
|
|
|
int |
|
rpl_pthread_kill(pthread_t tid, int signal) |
|
{ |
|
if ((signal != 0) && (signal != SIGINT)) |
|
{ |
|
if (queue_in(getpid(), signal) != 0) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
|
|
return(pthread_kill(tid, signal)); |
|
} |
|
|
|
#endif |
|
|
// vim: ts=4 |
// vim: ts=4 |