version 1.1.1.1, 2010/01/26 15:22:45
|
version 1.51, 2011/11/26 10:01:31
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.9 |
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 20
|
Line 20
|
*/ |
*/ |
|
|
|
|
#include "rpl.conv.h" |
#include "rpl-conv.h" |
|
|
|
|
/* |
/* |
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 111 instruction_spawn(struct_processus *s_et
|
Line 108 instruction_spawn(struct_processus *s_et
|
* d'une fonction ou d'une expression RPN. |
* d'une fonction ou d'une expression RPN. |
*/ |
*/ |
|
|
if (((*s_objet).type != NOM) && |
if (((*s_objet).type != NOM) && ((*s_objet).type != RPN)) |
((*s_objet).type != RPN)) |
|
{ |
{ |
liberation(s_etat_processus, s_objet); |
liberation(s_etat_processus, s_objet); |
|
|
Line 133 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 145 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 220 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 244 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, 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 343 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 392 instruction_spawn(struct_processus *s_et
|
Line 353 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
|
# 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; |
return; |
return; |
} |
} |
|
# endif |
|
|
/* |
/* |
* Création de l'objet à retourner |
* Création de l'objet à retourner |
Line 432 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 452 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).thread_actif = d_faux; |
(*s_argument_thread).oldset = oldset; |
|
|
|
if (pthread_create(&thread_id, &attributs, lancement_thread, |
if (pthread_create(&thread_id, &attributs, lancement_thread, |
s_argument_thread) != 0) |
s_argument_thread) != 0) |
Line 462 instruction_spawn(struct_processus *s_et
|
Line 422 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
|
attente.tv_sec = 0; |
|
attente.tv_nsec = GRANULARITE_us * 1000; |
|
|
|
while((*s_argument_thread).thread_actif == d_faux) |
|
{ |
|
scrutation_interruptions(s_etat_processus); |
|
nanosleep(&attente, NULL); |
|
INCR_GRANULARITE(attente.tv_nsec); |
|
} |
|
|
if (pthread_attr_destroy(&attributs) != 0) |
if (pthread_attr_destroy(&attributs) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 481 instruction_spawn(struct_processus *s_et
|
Line 451 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
|
# 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; |
return; |
return; |
} |
} |
|
# 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 523 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 584 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 593 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 606 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 622 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 630 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 658 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; |
|
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 795 instruction_sqlconnect(struct_processus
|
Line 746 instruction_sqlconnect(struct_processus
|
|
|
/* |
/* |
================================================================================ |
================================================================================ |
Fonction 'sqlconnect' |
Fonction 'sqldisconnect' |
================================================================================ |
================================================================================ |
Entrées : |
Entrées : |
-------------------------------------------------------------------------------- |
-------------------------------------------------------------------------------- |
Line 883 instruction_sqldisconnect(struct_process
|
Line 834 instruction_sqldisconnect(struct_process
|
"MYSQL") == 0) |
"MYSQL") == 0) |
{ |
{ |
# ifdef MYSQL_SUPPORT |
# ifdef MYSQL_SUPPORT |
|
|
if ((*((struct_connecteur_sql *) (*(*l_element_courant) |
if ((*((struct_connecteur_sql *) (*(*l_element_courant) |
.donnee).objet)).descripteur.mysql == |
.donnee).objet)).descripteur.mysql == |
(*((struct_connecteur_sql *) (*s_objet).objet)) |
(*((struct_connecteur_sql *) (*s_objet).objet)) |
Line 894 instruction_sqldisconnect(struct_process
|
Line 846 instruction_sqldisconnect(struct_process
|
{ |
{ |
drapeau = d_faux; |
drapeau = d_faux; |
} |
} |
|
|
# else |
# else |
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
Line 915 instruction_sqldisconnect(struct_process
|
Line 868 instruction_sqldisconnect(struct_process
|
.type, "POSTGRESQL") == 0) |
.type, "POSTGRESQL") == 0) |
{ |
{ |
# ifdef POSTGRESQL_SUPPORT |
# ifdef POSTGRESQL_SUPPORT |
|
|
if ((*((struct_connecteur_sql *) (*(*l_element_courant) |
if ((*((struct_connecteur_sql *) (*(*l_element_courant) |
.donnee).objet)).descripteur.postgresql == |
.donnee).objet)).descripteur.postgresql == |
(*((struct_connecteur_sql *) (*s_objet).objet)) |
(*((struct_connecteur_sql *) (*s_objet).objet)) |
Line 1155 instruction_smphrdecr(struct_processus *
|
Line 1109 instruction_smphrdecr(struct_processus *
|
} |
} |
} |
} |
|
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
# ifndef SEMAPHORES_NOMMES |
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
|
# else |
|
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; |
Line 1166 instruction_smphrdecr(struct_processus *
|
Line 1124 instruction_smphrdecr(struct_processus *
|
{ |
{ |
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 1178 instruction_smphrdecr(struct_processus *
|
Line 1142 instruction_smphrdecr(struct_processus *
|
} |
} |
} |
} |
|
|
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
# ifndef SEMAPHORES_NOMMES |
|
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
|
# else |
|
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
Line 1297 instruction_smphrtrydecr(struct_processu
|
Line 1265 instruction_smphrtrydecr(struct_processu
|
} |
} |
} |
} |
|
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
# ifndef SEMAPHORES_NOMMES |
|
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
|
# else |
|
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; |
} |
} |
Line 1341 instruction_smphrtrydecr(struct_processu
|
Line 1318 instruction_smphrtrydecr(struct_processu
|
} |
} |
} |
} |
|
|
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
# ifndef SEMAPHORES_NOMMES |
|
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
|
# else |
|
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |