version 1.24, 2010/08/26 19:07:40
|
version 1.51, 2011/11/26 10:01:31
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.19 |
RPL/2 (R) version 4.1.5 |
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 348 instruction_spawn(struct_processus *s_et
|
Line 298 instruction_spawn(struct_processus *s_et
|
pthread_mutex_init(&((*s_argument_thread).mutex), &attributs_mutex); |
pthread_mutex_init(&((*s_argument_thread).mutex), &attributs_mutex); |
pthread_mutexattr_destroy(&attributs_mutex); |
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
|
pthread_mutexattr_init(&attributs_mutex); |
|
pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE); |
|
pthread_mutex_init(&((*s_argument_thread).mutex_nombre_references), |
|
&attributs_mutex); |
|
pthread_mutexattr_destroy(&attributs_mutex); |
|
|
(*s_argument_thread).processus_detache = d_faux; |
(*s_argument_thread).processus_detache = d_faux; |
(*s_argument_thread).thread_actif = d_faux; |
(*s_argument_thread).thread_actif = d_faux; |
(*s_argument_thread).thread_pere = pthread_self(); |
(*s_argument_thread).thread_pere = pthread_self(); |
Line 397 instruction_spawn(struct_processus *s_et
|
Line 353 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
# ifndef OS2 |
# ifdef SCHED_OTHER |
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; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_EXPLICIT_SCHED |
if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0) |
if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_SCOPE_SYSTEM |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 439 instruction_spawn(struct_processus *s_et
|
Line 399 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 459 instruction_spawn(struct_processus *s_et
|
Line 413 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 475 instruction_spawn(struct_processus *s_et
|
Line 427 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 498 instruction_spawn(struct_processus *s_et
|
Line 451 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
# ifndef OS2 |
# ifdef SCHED_OTHER |
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; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_EXPLICIT_SCHED |
if (pthread_attr_setinheritsched(&attributs, |
if (pthread_attr_setinheritsched(&attributs, |
PTHREAD_EXPLICIT_SCHED) != 0) |
PTHREAD_EXPLICIT_SCHED) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_SCOPE_SYSTEM |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 519 instruction_spawn(struct_processus *s_et
|
Line 476 instruction_spawn(struct_processus *s_et
|
} |
} |
# 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 |
* accédé depuis deux threads distincts et aboutir à un blocage lors d'une |
* accédé depuis deux threads distincts et aboutir à un blocage lors d'une |
Line 542 instruction_spawn(struct_processus *s_et
|
Line 491 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 603 instruction_spawn(struct_processus *s_et
|
Line 553 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 612 instruction_spawn(struct_processus *s_et
|
Line 563 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 625 instruction_spawn(struct_processus *s_et
|
Line 575 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 641 instruction_spawn(struct_processus *s_et
|
Line 589 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 649 instruction_spawn(struct_processus *s_et
|
Line 596 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 677 instruction_spawn(struct_processus *s_et
|
Line 617 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; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
|
if (pthread_sigmask(SIG_SETMASK, &oldset, NULL) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
sigpending(&set); |
|
|
|
return; |
return; |
} |
} |
|
|
Line 1178 instruction_smphrdecr(struct_processus *
|
Line 1110 instruction_smphrdecr(struct_processus *
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# 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; |
|
return; |
|
} |
|
# else |
# else |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
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) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
|
sem_post(&((*s_etat_processus).semaphore_fork)); |
|
# else |
|
sem_post((*s_etat_processus).semaphore_fork); |
|
# endif |
|
|
(*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 1209 instruction_smphrdecr(struct_processus *
|
Line 1143 instruction_smphrdecr(struct_processus *
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
# else |
# else |
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
# endif |
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
Line 1332 instruction_smphrtrydecr(struct_processu
|
Line 1266 instruction_smphrtrydecr(struct_processu
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# 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; |
|
return; |
|
} |
|
# else |
# else |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
|
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; |
} |
} |
# endif |
|
|
|
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
|
|
Line 1384 instruction_smphrtrydecr(struct_processu
|
Line 1319 instruction_smphrtrydecr(struct_processu
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
# else |
# else |
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
# endif |
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |