version 1.62, 2012/10/07 21:57:48
|
version 1.77, 2013/04/02 12:20:21
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.11 |
RPL/2 (R) version 4.1.14 |
Copyright (C) 1989-2012 Dr. BERTRAND Joël |
Copyright (C) 1989-2013 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 284 allocation_tableau_noeuds(struct_process
|
Line 284 allocation_tableau_noeuds(struct_process
|
} |
} |
else |
else |
{ |
{ |
objet = malloc((*s_etat_processus).nombre_caracteres_variables |
objet = malloc(((size_t) (*s_etat_processus) |
|
.nombre_caracteres_variables) |
* sizeof(struct_arbre_variables *)); |
* sizeof(struct_arbre_variables *)); |
} |
} |
|
|
Line 988 recherche_variable(struct_processus *s_e
|
Line 989 recherche_variable(struct_processus *s_e
|
|
|
unsigned char *ptr; |
unsigned char *ptr; |
|
|
unsigned long niveau_appel; |
integer8 niveau_appel; |
|
|
if ((*s_etat_processus).s_arbre_variables == NULL) |
if ((*s_etat_processus).s_arbre_variables == NULL) |
{ |
{ |
Line 1203 retrait_variable(struct_processus *s_eta
|
Line 1204 retrait_variable(struct_processus *s_eta
|
struct_liste_variables *variable_a_supprimer; |
struct_liste_variables *variable_a_supprimer; |
struct_liste_variables *variables_par_niveau; |
struct_liste_variables *variables_par_niveau; |
|
|
unsigned long niveau; |
integer8 niveau; |
|
|
(*s_etat_processus).niveau_supprime = d_faux; |
(*s_etat_processus).niveau_supprime = d_faux; |
|
|
Line 1530 retrait_variables_par_niveau(struct_proc
|
Line 1531 retrait_variables_par_niveau(struct_proc
|
break; |
break; |
} |
} |
|
|
|
if (((*s_etat_processus).at_exit != NULL) && |
|
((*s_etat_processus).niveau_courant == 0)) |
|
{ |
|
// Il y a une routine ATEXIT enregistrée. On ne détruit pas |
|
// les variables globales qui pourraient y être utilisées. |
|
|
|
break; |
|
} |
|
|
while((*(*s_etat_processus).l_liste_variables_par_niveau).liste |
while((*(*s_etat_processus).l_liste_variables_par_niveau).liste |
!= NULL) |
!= NULL) |
{ |
{ |
Line 1789 liberation_arbre_variables(struct_proces
|
Line 1799 liberation_arbre_variables(struct_proces
|
================================================================================ |
================================================================================ |
*/ |
*/ |
|
|
int |
static integer8 |
nombre_variables(struct_processus *s_etat_processus, |
nombre_variables_locales(struct_processus *s_etat_processus, |
struct_arbre_variables *l_element_courant) |
struct_arbre_variables *l_element_courant) |
{ |
{ |
int i; |
integer8 i; |
int n; |
integer8 n; |
|
|
struct_liste_variables *l_variable; |
struct_liste_variables *l_variable; |
struct_liste_variables_statiques *l_variable_statique; |
struct_liste_variables_statiques *l_variable_statique; |
|
|
|
if (l_element_courant == NULL) |
|
{ |
|
return(0); |
|
} |
|
|
n = 0; |
n = 0; |
|
|
if ((*l_element_courant).feuille != NULL) |
if ((*l_element_courant).feuille != NULL) |
Line 1834 nombre_variables(struct_processus *s_eta
|
Line 1849 nombre_variables(struct_processus *s_eta
|
{ |
{ |
if ((*l_element_courant).noeuds[i] != NULL) |
if ((*l_element_courant).noeuds[i] != NULL) |
{ |
{ |
n += nombre_variables(s_etat_processus, |
n += nombre_variables_locales(s_etat_processus, |
(*l_element_courant).noeuds[i]); |
(*l_element_courant).noeuds[i]); |
} |
} |
} |
} |
Line 1843 nombre_variables(struct_processus *s_eta
|
Line 1858 nombre_variables(struct_processus *s_eta
|
} |
} |
|
|
|
|
int |
static integer8 |
liste_variables(struct_processus *s_etat_processus, |
nombre_variables_partagees(struct_processus *s_etat_processus, |
struct_tableau_variables *tableau, int position, |
struct_arbre_variables_partagees *l_element_courant) |
struct_arbre_variables *l_element_courant) |
{ |
|
integer8 i; |
|
integer8 n; |
|
|
|
struct_liste_variables_partagees *l_variable; |
|
|
|
if (l_element_courant == NULL) |
|
{ |
|
return(0); |
|
} |
|
|
|
// Mutex deverrouillé par liste_variables_partagees(); |
|
if (pthread_mutex_lock(&((*l_element_courant).mutex_feuille)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(0); |
|
} |
|
|
|
n = 0; |
|
|
|
if ((*l_element_courant).feuille != NULL) |
|
{ |
|
l_variable = (*l_element_courant).feuille; |
|
|
|
do |
|
{ |
|
n++; |
|
l_variable = (*l_variable).suivant; |
|
} while(l_variable != NULL); |
|
} |
|
|
|
for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++) |
|
{ |
|
if ((*l_element_courant).noeuds[i] != NULL) |
|
{ |
|
n += nombre_variables_partagees(s_etat_processus, |
|
(*l_element_courant).noeuds[i]); |
|
} |
|
} |
|
|
|
return(n); |
|
} |
|
|
|
|
|
integer8 |
|
nombre_variables(struct_processus *s_etat_processus) |
|
{ |
|
return(nombre_variables_locales(s_etat_processus, |
|
(*s_etat_processus).s_arbre_variables) |
|
+ nombre_variables_partagees(s_etat_processus, |
|
(*(*s_etat_processus).s_arbre_variables_partagees))); |
|
} |
|
|
|
|
|
void |
|
liberation_mutexes_arbre_variables_partagees(struct_processus *s_etat_processus, |
|
struct_arbre_variables_partagees *l_element_courant) |
{ |
{ |
int i; |
int i; |
|
|
|
if (l_element_courant == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
if (pthread_mutex_trylock(&((*l_element_courant).mutex_feuille)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (pthread_mutex_unlock(&((*l_element_courant).mutex_feuille)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++) |
|
{ |
|
if ((*l_element_courant).noeuds[i] != NULL) |
|
{ |
|
liberation_mutexes_arbre_variables_partagees(s_etat_processus, |
|
(*l_element_courant).noeuds[i]); |
|
} |
|
} |
|
|
|
return; |
|
} |
|
|
|
|
|
static integer8 |
|
liste_variables_locales(struct_processus *s_etat_processus, |
|
struct_tableau_variables *tableau, integer8 position, |
|
struct_arbre_variables *l_element_courant) |
|
{ |
|
integer8 i; |
|
|
struct_liste_variables *l_variable; |
struct_liste_variables *l_variable; |
struct_liste_variables_statiques *l_variable_statique; |
struct_liste_variables_statiques *l_variable_statique; |
|
|
|
if (l_element_courant == NULL) |
|
{ |
|
return(position); |
|
} |
|
|
if ((*l_element_courant).feuille != NULL) |
if ((*l_element_courant).feuille != NULL) |
{ |
{ |
l_variable = (*l_element_courant).feuille; |
l_variable = (*l_element_courant).feuille; |
Line 1870 liste_variables(struct_processus *s_etat
|
Line 1983 liste_variables(struct_processus *s_etat
|
tableau[position].variable_partagee = |
tableau[position].variable_partagee = |
(*(*l_variable).variable).variable_partagee; |
(*(*l_variable).variable).variable_partagee; |
tableau[position].variable_masquee = d_faux; |
tableau[position].variable_masquee = d_faux; |
|
tableau[position].mutex = NULL; |
|
|
position++; |
position++; |
|
|
l_variable = (*l_variable).suivant; |
l_variable = (*l_variable).suivant; |
} while(l_variable != (*l_element_courant).feuille); |
} while(l_variable != (*l_element_courant).feuille); |
} |
} |
Line 1888 liste_variables(struct_processus *s_etat
|
Line 2003 liste_variables(struct_processus *s_etat
|
tableau[position].nom = (*(*l_variable_statique).variable).nom; |
tableau[position].nom = (*(*l_variable_statique).variable).nom; |
tableau[position].niveau = |
tableau[position].niveau = |
(*(*l_variable_statique).variable).niveau; |
(*(*l_variable_statique).variable).niveau; |
tableau[position].objet = |
tableau[position].objet = (*(*l_variable_statique).variable) |
(*(*l_variable_statique).variable).objet; |
.objet; |
tableau[position].variable_verrouillee = d_faux; |
tableau[position].variable_verrouillee = d_faux; |
tableau[position].variable_statique = |
tableau[position].variable_statique = |
(*(*l_variable_statique).variable).variable_statique; |
(*(*l_variable_statique).variable).variable_statique; |
Line 1907 liste_variables(struct_processus *s_etat
|
Line 2022 liste_variables(struct_processus *s_etat
|
{ |
{ |
if ((*l_element_courant).noeuds[i] != NULL) |
if ((*l_element_courant).noeuds[i] != NULL) |
{ |
{ |
position = liste_variables(s_etat_processus, |
position = liste_variables_locales(s_etat_processus, |
tableau, position, (*l_element_courant).noeuds[i]); |
tableau, position, (*l_element_courant).noeuds[i]); |
} |
} |
} |
} |
Line 1916 liste_variables(struct_processus *s_etat
|
Line 2031 liste_variables(struct_processus *s_etat
|
} |
} |
|
|
|
|
|
static integer8 |
|
liste_variables_partagees(struct_processus *s_etat_processus, |
|
struct_tableau_variables *tableau, integer8 position, |
|
struct_arbre_variables_partagees *l_element_courant) |
|
{ |
|
integer8 i; |
|
|
|
struct_liste_variables_partagees *l_variable; |
|
|
|
if (l_element_courant == NULL) |
|
{ |
|
return(position); |
|
} |
|
|
|
if ((*l_element_courant).feuille != NULL) |
|
{ |
|
l_variable = (*l_element_courant).feuille; |
|
|
|
do |
|
{ |
|
tableau[position].origine = 'E'; |
|
tableau[position].nom = (*(*l_variable).variable).nom; |
|
tableau[position].niveau = (*(*l_variable).variable).niveau; |
|
tableau[position].objet = (*(*l_variable).variable).objet; |
|
tableau[position].variable_verrouillee = d_faux; |
|
tableau[position].variable_partagee = |
|
(*(*l_variable).variable).variable_partagee; |
|
tableau[position].variable_statique.pointeur = NULL; |
|
tableau[position].variable_masquee = d_faux; |
|
tableau[position].mutex = &((*(*l_variable).variable).mutex); |
|
pthread_mutex_lock(tableau[position].mutex); |
|
|
|
position++; |
|
|
|
l_variable = (*l_variable).suivant; |
|
} while(l_variable != NULL); |
|
} |
|
|
|
for(i = 0; i < (*s_etat_processus).nombre_caracteres_variables; i++) |
|
{ |
|
if ((*l_element_courant).noeuds[i] != NULL) |
|
{ |
|
position = liste_variables_partagees(s_etat_processus, |
|
tableau, position, (*l_element_courant).noeuds[i]); |
|
} |
|
} |
|
|
|
// Mutex verrouillé par nombre_variables_partagees(); |
|
if (pthread_mutex_unlock(&((*l_element_courant).mutex_feuille)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return(0); |
|
} |
|
|
|
return(position); |
|
} |
|
|
|
|
|
static int |
|
fonction_ordre_variables(const void *argument_1, const void *argument_2) |
|
{ |
|
int comparaison; |
|
|
|
struct_tableau_variables *a1; |
|
struct_tableau_variables *a2; |
|
|
|
a1 = (struct_tableau_variables *) argument_1; |
|
a2 = (struct_tableau_variables *) argument_2; |
|
|
|
comparaison = strcmp((*a1).nom, (*a2).nom); |
|
|
|
if (comparaison != 0) |
|
{ |
|
return(comparaison); |
|
} |
|
else |
|
{ |
|
return(((((*a1).niveau - (*a2).niveau)) > 0) ? 1 : -1); |
|
} |
|
} |
|
|
|
|
|
integer8 |
|
liste_variables(struct_processus *s_etat_processus, |
|
struct_tableau_variables *tableau) |
|
{ |
|
integer8 nombre_elements; |
|
|
|
nombre_elements = liste_variables_locales(s_etat_processus, |
|
tableau, 0, (*s_etat_processus).s_arbre_variables); |
|
nombre_elements = liste_variables_partagees(s_etat_processus, |
|
tableau, nombre_elements, (*(*s_etat_processus) |
|
.s_arbre_variables_partagees)); |
|
|
|
qsort(tableau, (size_t) nombre_elements, sizeof(struct_tableau_variables), |
|
fonction_ordre_variables); |
|
|
|
return(nombre_elements); |
|
} |
|
|
|
|
/* |
/* |
================================================================================ |
================================================================================ |
Procédure de copie de l'arbre des variables |
Procédure de copie de l'arbre des variables |
Line 1958 copie_arbre_variables(struct_processus *
|
Line 2174 copie_arbre_variables(struct_processus *
|
struct_liste_variables_statiques *l_element_statique_courant; |
struct_liste_variables_statiques *l_element_statique_courant; |
|
|
struct_variable s_variable; |
struct_variable s_variable; |
|
struct_variable_statique s_variable_statique; |
|
|
unsigned char *ptr; |
unsigned char *ptr; |
|
|
Line 2181 copie_arbre_variables(struct_processus *
|
Line 2398 copie_arbre_variables(struct_processus *
|
ptr++; |
ptr++; |
} |
} |
|
|
if (creation_variable_statique(s_nouvel_etat_processus, |
// Il faut copier la variable pour la dissocier de la variable |
(*l_element_statique_courant).variable) == d_erreur) |
// restant dans le thread parent. |
|
|
|
s_variable_statique = (*(*l_element_statique_courant).variable); |
|
|
|
if (copie_objet(s_etat_processus, s_variable_statique.objet, 'P') |
|
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
} |
} |
|
|
if (copie_objet(s_etat_processus, (*(*l_element_statique_courant) |
if ((s_variable_statique.nom = malloc((strlen( |
.variable).objet, 'P') == NULL) |
(*(*l_element_statique_courant).variable).nom) + 1) * |
|
sizeof(unsigned char))) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
strcpy(s_variable_statique.nom, (*(*l_element_statique_courant) |
|
.variable).nom); |
|
|
|
if (creation_variable_statique(s_nouvel_etat_processus, |
|
&s_variable_statique) == d_erreur) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 2245 initialisation_variables(struct_processu
|
Line 2478 initialisation_variables(struct_processu
|
} |
} |
|
|
if (((*s_etat_processus).pointeurs_caracteres_variables = |
if (((*s_etat_processus).pointeurs_caracteres_variables = |
malloc(longueur_tableau * sizeof(int))) == NULL) |
malloc(((size_t) longueur_tableau) * sizeof(int))) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |