version 1.27, 2010/12/10 15:36:56
|
version 1.46, 2011/09/20 08:56:24
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.20 |
RPL/2 (R) version 4.1.3 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 48 instruction_spawn(struct_processus *s_et
|
Line 48 instruction_spawn(struct_processus *s_et
|
pthread_t thread_id; |
pthread_t thread_id; |
pthread_t thread_surveillance; |
pthread_t thread_surveillance; |
|
|
sigset_t oldset; |
|
sigset_t set; |
|
|
|
struct_descripteur_thread *s_argument_thread; |
struct_descripteur_thread *s_argument_thread; |
|
|
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_courant; |
Line 132 instruction_spawn(struct_processus *s_et
|
Line 129 instruction_spawn(struct_processus *s_et
|
if (recherche_variable(s_etat_processus, (*((struct_nom *) |
if (recherche_variable(s_etat_processus, (*((struct_nom *) |
(*s_objet).objet)).nom) == d_vrai) |
(*s_objet).objet)).nom) == d_vrai) |
{ |
{ |
if ((*s_etat_processus).s_liste_variables |
if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL) |
[(*s_etat_processus).position_variable_courante].objet |
|
== NULL) |
|
{ |
{ |
if (pthread_mutex_lock(&((*(*s_etat_processus) |
if (pthread_mutex_lock(&((*(*s_etat_processus) |
.s_liste_variables_partagees).mutex)) != 0) |
.s_liste_variables_partagees).mutex)) != 0) |
Line 144 instruction_spawn(struct_processus *s_et
|
Line 139 instruction_spawn(struct_processus *s_et
|
} |
} |
|
|
if (recherche_variable_partagee(s_etat_processus, |
if (recherche_variable_partagee(s_etat_processus, |
(*s_etat_processus).s_liste_variables |
(*(*s_etat_processus).pointeur_variable_courante).nom, |
[(*s_etat_processus).position_variable_courante].nom, |
(*(*s_etat_processus).pointeur_variable_courante) |
(*s_etat_processus).s_liste_variables |
.variable_partagee, (*(*s_etat_processus) |
[(*s_etat_processus).position_variable_courante] |
.pointeur_variable_courante).origine) == d_faux) |
.variable_partagee, (*s_etat_processus) |
|
.s_liste_variables[(*s_etat_processus) |
|
.position_variable_courante].origine) == d_faux) |
|
{ |
{ |
if (pthread_mutex_unlock(&((*(*s_etat_processus) |
if (pthread_mutex_unlock(&((*(*s_etat_processus) |
.s_liste_variables_partagees).mutex)) != 0) |
.s_liste_variables_partagees).mutex)) != 0) |
Line 219 instruction_spawn(struct_processus *s_et
|
Line 211 instruction_spawn(struct_processus *s_et
|
} |
} |
else |
else |
{ |
{ |
if (((*(*s_etat_processus).s_liste_variables |
if (((*(*(*s_etat_processus).pointeur_variable_courante).objet) |
[(*s_etat_processus).position_variable_courante].objet) |
.type != RPN) && ((*(*(*s_etat_processus) |
.type != RPN) && ((*(*s_etat_processus) |
.pointeur_variable_courante).objet).type != ADR)) |
.s_liste_variables[(*s_etat_processus) |
|
.position_variable_courante].objet).type != ADR)) |
|
{ |
{ |
liberation(s_etat_processus, s_objet); |
liberation(s_etat_processus, s_objet); |
|
|
Line 243 instruction_spawn(struct_processus *s_et
|
Line 233 instruction_spawn(struct_processus *s_et
|
} |
} |
} |
} |
|
|
if (sigemptyset(&set) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (sigaddset(&set, SIGSTART) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
/* |
|
* Le signal SIGFSTOP doit être traité ! |
|
*/ |
|
|
|
if (sigaddset(&set, SIGFSTOP) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (sigaddset(&set, SIGFABORT) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (sigaddset(&set, SIGURG) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (pthread_sigmask(SIG_BLOCK, &set, &oldset) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if ((s_argument_thread = malloc(sizeof(struct_descripteur_thread))) == NULL) |
if ((s_argument_thread = malloc(sizeof(struct_descripteur_thread))) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 404 instruction_spawn(struct_processus *s_et
|
Line 354 instruction_spawn(struct_processus *s_et
|
} |
} |
|
|
# ifndef OS2 |
# ifndef OS2 |
|
# ifndef Cygwin |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 422 instruction_spawn(struct_processus *s_et
|
Line 373 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
# endif |
# endif |
|
# endif |
|
|
/* |
/* |
* Création de l'objet à retourner |
* Création de l'objet à retourner |
Line 445 instruction_spawn(struct_processus *s_et
|
Line 397 instruction_spawn(struct_processus *s_et
|
|
|
// Lancement du thread fils |
// Lancement du thread fils |
|
|
if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
(*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus; |
(*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus; |
(*s_argument_thread).s_etat_processus = s_etat_processus; |
(*s_argument_thread).s_etat_processus = s_etat_processus; |
|
|
Line 465 instruction_spawn(struct_processus *s_et
|
Line 411 instruction_spawn(struct_processus *s_et
|
(*s_argument_thread).destruction_objet = d_faux; |
(*s_argument_thread).destruction_objet = d_faux; |
} |
} |
|
|
(*s_argument_thread).set = set; |
|
(*s_argument_thread).oldset = oldset; |
|
(*s_argument_thread).thread_actif = d_faux; |
(*s_argument_thread).thread_actif = d_faux; |
|
|
if (pthread_create(&thread_id, &attributs, lancement_thread, |
if (pthread_create(&thread_id, &attributs, lancement_thread, |
Line 481 instruction_spawn(struct_processus *s_et
|
Line 425 instruction_spawn(struct_processus *s_et
|
|
|
while((*s_argument_thread).thread_actif == d_faux) |
while((*s_argument_thread).thread_actif == d_faux) |
{ |
{ |
|
scrutation_interruptions(s_etat_processus); |
nanosleep(&attente, NULL); |
nanosleep(&attente, NULL); |
INCR_GRANULARITE(attente.tv_nsec); |
INCR_GRANULARITE(attente.tv_nsec); |
} |
} |
Line 505 instruction_spawn(struct_processus *s_et
|
Line 450 instruction_spawn(struct_processus *s_et
|
} |
} |
|
|
# ifndef OS2 |
# ifndef OS2 |
|
# ifndef Cygwin |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 524 instruction_spawn(struct_processus *s_et
|
Line 470 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
# endif |
# endif |
|
# endif |
// Attente de l'affectation de la grandeur processus.tid par le thread fils. |
|
|
|
if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
/* |
/* |
* On copie l'objet plutôt que le pointeur car cet objet peut être |
* On copie l'objet plutôt que le pointeur car cet objet peut être |
Line 548 instruction_spawn(struct_processus *s_et
|
Line 487 instruction_spawn(struct_processus *s_et
|
|
|
if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) |
{ |
{ |
|
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 609 instruction_spawn(struct_processus *s_et
|
Line 549 instruction_spawn(struct_processus *s_et
|
} |
} |
} |
} |
|
|
|
scrutation_interruptions(s_etat_processus); |
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
} |
} |
} while(drapeau == d_vrai); |
} while(drapeau == d_vrai); |
Line 618 instruction_spawn(struct_processus *s_et
|
Line 559 instruction_spawn(struct_processus *s_et
|
.l_base_pile_processus), s_objet_systeme) == d_erreur) |
.l_base_pile_processus), s_objet_systeme) == d_erreur) |
{ |
{ |
pthread_mutex_unlock(&((*s_etat_processus).mutex)); |
pthread_mutex_unlock(&((*s_etat_processus).mutex)); |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
return; |
return; |
} |
} |
|
|
Line 631 instruction_spawn(struct_processus *s_et
|
Line 571 instruction_spawn(struct_processus *s_et
|
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
s_objet_resultat) == d_erreur) |
s_objet_resultat) == d_erreur) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
return; |
return; |
} |
} |
|
|
if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0) |
if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 647 instruction_spawn(struct_processus *s_et
|
Line 585 instruction_spawn(struct_processus *s_et
|
// Le thread n'existe plus. |
// Le thread n'existe plus. |
|
|
pthread_join((*s_argument_thread).tid, NULL); |
pthread_join((*s_argument_thread).tid, NULL); |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
pthread_mutex_unlock(&(*s_argument_thread).mutex); |
pthread_mutex_unlock(&(*s_argument_thread).mutex); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
Line 655 instruction_spawn(struct_processus *s_et
|
Line 592 instruction_spawn(struct_processus *s_et
|
|
|
if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0) |
if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 683 instruction_spawn(struct_processus *s_et
|
Line 613 instruction_spawn(struct_processus *s_et
|
|
|
// Le fils peut être présent sans être en attente du signal de départ. |
// Le fils peut être présent sans être en attente du signal de départ. |
|
|
if (pthread_kill((*s_argument_thread).tid, SIGSTART) != 0) |
if (envoi_signal_thread((*s_argument_thread).tid, rpl_sigstart) != 0) |
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (pthread_sigmask(SIG_SETMASK, &oldset, NULL) != 0) |
|
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
|
sigpending(&set); |
|
|
|
return; |
return; |
} |
} |
|
|
Line 1183 instruction_smphrdecr(struct_processus *
|
Line 1105 instruction_smphrdecr(struct_processus *
|
} |
} |
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# else |
|
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
# endif |
|
|
|
while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet)) |
while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet)) |
.semaphore) == -1) |
.semaphore) == -1) |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
|
sem_post(&((*s_etat_processus).semaphore_fork)); |
(*s_etat_processus).erreur_execution = d_ex_semaphore; |
(*s_etat_processus).erreur_execution = d_ex_semaphore; |
|
|
if ((*s_etat_processus).profilage == d_vrai) |
if ((*s_etat_processus).profilage == d_vrai) |
Line 1214 instruction_smphrdecr(struct_processus *
|
Line 1129 instruction_smphrdecr(struct_processus *
|
} |
} |
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
|
# else |
|
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
|
# endif |
|
{ |
{ |
if (errno != EINTR) |
if ((*s_etat_processus).profilage == d_vrai) |
{ |
{ |
if ((*s_etat_processus).profilage == d_vrai) |
profilage(s_etat_processus, NULL); |
{ |
|
profilage(s_etat_processus, NULL); |
|
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
} |
} |
|
|
if ((*s_etat_processus).profilage == d_vrai) |
if ((*s_etat_processus).profilage == d_vrai) |
Line 1337 instruction_smphrtrydecr(struct_processu
|
Line 1245 instruction_smphrtrydecr(struct_processu
|
} |
} |
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
{ |
{ |
|
if ((*s_etat_processus).profilage == d_vrai) |
|
{ |
|
profilage(s_etat_processus, NULL); |
|
} |
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# else |
|
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
# endif |
|
|
|
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
|
|
Line 1389 instruction_smphrtrydecr(struct_processu
|
Line 1294 instruction_smphrtrydecr(struct_processu
|
} |
} |
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
if (sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
|
# else |
|
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
|
# endif |
|
{ |
{ |
if (errno != EINTR) |
if ((*s_etat_processus).profilage == d_vrai) |
{ |
{ |
if ((*s_etat_processus).profilage == d_vrai) |
profilage(s_etat_processus, NULL); |
{ |
|
profilage(s_etat_processus, NULL); |
|
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
} |
|
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
} |
} |
|
|
if ((*s_etat_processus).profilage == d_vrai) |
if ((*s_etat_processus).profilage == d_vrai) |