Annotation of rpl/src/gestion_objets.c, revision 1.68
1.1 bertrand 1: /*
2: ================================================================================
1.61 bertrand 3: RPL/2 (R) version 4.1.3
1.44 bertrand 4: Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1 bertrand 5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
1.33 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
1.6 bertrand 28: Routines de gestion du nombre d'occurrences comme grandeur atomique
1.1 bertrand 29: ================================================================================
30: entrées : structure sur l'état du processus et objet à afficher
31: --------------------------------------------------------------------------------
32: sorties : chaine de caractères
33: --------------------------------------------------------------------------------
34: effets de bord : néant
35: ================================================================================
36: */
37:
38: static inline void
39: incrementation_atomique(struct_objet *s_objet)
40: {
41: // Le mutex est sur l'objet.
42:
43: (*s_objet).nombre_occurrences++;
44:
45: BUG((*s_objet).nombre_occurrences <= 0,
46: uprintf("Capacity exceeded %ld\n", (*s_objet).nombre_occurrences));
47:
48: return;
49: }
50:
51: static inline long
52: decrementation_atomique(struct_objet *s_objet)
53: {
54: // Le mutex est sur l'objet.
55:
56: (*s_objet).nombre_occurrences--;
57: return((*s_objet).nombre_occurrences);
58: }
59:
1.43 bertrand 60: void
1.1 bertrand 61: initialisation_objet(struct_objet *s_objet)
62: {
63: pthread_mutexattr_t attributs_mutex;
64:
65: pthread_mutexattr_init(&attributs_mutex);
66: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
67: pthread_mutex_init(&((*s_objet).mutex), &attributs_mutex);
68: pthread_mutexattr_destroy(&attributs_mutex);
69:
70: (*s_objet).nombre_occurrences = 1;
71:
72: return;
73: }
74:
75:
76: /*
77: ================================================================================
78: Routines d'initialisation et de purge de l'allocateur
79: ================================================================================
80: Entrées : structure sur l'état du processus et objet à afficher
81: --------------------------------------------------------------------------------
82: Sorties : chaine de caractères
83: --------------------------------------------------------------------------------
84: Effets de bord : néant
85: ================================================================================
86: */
87:
88: void
89: initialisation_allocateur(struct_processus *s_etat_processus)
90: {
91: (*s_etat_processus).estimation_taille_pile_tampon = 0;
92: (*s_etat_processus).taille_pile_tampon = 0;
93: (*s_etat_processus).pile_tampon = NULL;
94:
95: (*s_etat_processus).estimation_taille_pile_systeme_tampon = 0;
96: (*s_etat_processus).taille_pile_systeme_tampon = 0;
97: (*s_etat_processus).pile_systeme_tampon = NULL;
98:
99: (*s_etat_processus).taille_pile_objets = 0;
100: (*s_etat_processus).pile_objets = NULL;
101:
102: (*s_etat_processus).pointeur_adr = 0;
103: (*s_etat_processus).pointeur_bin = 0;
104: (*s_etat_processus).pointeur_cpl = 0;
105: (*s_etat_processus).pointeur_fct = 0;
106: (*s_etat_processus).pointeur_int = 0;
107: (*s_etat_processus).pointeur_mat = 0;
108: (*s_etat_processus).pointeur_nom = 0;
109: (*s_etat_processus).pointeur_rel = 0;
110: (*s_etat_processus).pointeur_tab = 0;
111: (*s_etat_processus).pointeur_vec = 0;
112: (*s_etat_processus).pointeur_maillons = 0;
113:
1.53 bertrand 114: (*s_etat_processus).pointeur_variables_noeud = 0;
115: (*s_etat_processus).pointeur_variables_feuille = 0;
116: (*s_etat_processus).pointeur_variables_variable = 0;
117: (*s_etat_processus).pointeur_variables_tableau_noeuds = 0;
118:
1.1 bertrand 119: return;
120: }
121:
122:
123: void
124: liberation_allocateur(struct_processus *s_etat_processus)
125: {
126: int i;
127:
128: for(i = 0; i < (*s_etat_processus).pointeur_adr;
129: free((*s_etat_processus).objets_adr[i++]));
130: for(i = 0; i < (*s_etat_processus).pointeur_bin;
131: free((*s_etat_processus).objets_bin[i++]));
132: for(i = 0; i < (*s_etat_processus).pointeur_cpl;
133: free((*s_etat_processus).objets_cpl[i++]));
134: for(i = 0; i < (*s_etat_processus).pointeur_fct;
135: free((*s_etat_processus).objets_fct[i++]));
136: for(i = 0; i < (*s_etat_processus).pointeur_int;
137: free((*s_etat_processus).objets_int[i++]));
138: for(i = 0; i < (*s_etat_processus).pointeur_mat;
139: free((*s_etat_processus).objets_mat[i++]));
140: for(i = 0; i < (*s_etat_processus).pointeur_nom;
141: free((*s_etat_processus).objets_nom[i++]));
142: for(i = 0; i < (*s_etat_processus).pointeur_rel;
143: free((*s_etat_processus).objets_rel[i++]));
144: for(i = 0; i < (*s_etat_processus).pointeur_tab;
145: free((*s_etat_processus).objets_tab[i++]));
146: for(i = 0; i < (*s_etat_processus).pointeur_vec;
147: free((*s_etat_processus).objets_vec[i++]));
148: for(i = 0; i < (*s_etat_processus).pointeur_maillons;
149: free((*s_etat_processus).maillons[i++]));
150:
1.53 bertrand 151: for(i = 0; i < (*s_etat_processus).pointeur_variables_noeud;
152: free((*s_etat_processus).variables_noeud[i++]));
153: for(i = 0; i < (*s_etat_processus).pointeur_variables_feuille;
154: free((*s_etat_processus).variables_feuille[i++]));
155: for(i = 0; i < (*s_etat_processus).pointeur_variables_variable;
156: free((*s_etat_processus).variables_variable[i++]));
157: for(i = 0; i < (*s_etat_processus).pointeur_variables_tableau_noeuds;
158: free((*s_etat_processus).variables_tableau_noeuds[i++]));
159:
1.1 bertrand 160: {
161: struct_liste_chainee *l_element_courant;
162: struct_liste_chainee *l_element_suivant;
163:
164: l_element_courant = (*s_etat_processus).pile_tampon;
165:
166: while(l_element_courant != NULL)
167: {
168: l_element_suivant = (*l_element_courant).suivant;
169: liberation(s_etat_processus, (*l_element_courant).donnee);
170: free(l_element_courant);
171: l_element_courant = l_element_suivant;
172: }
173: }
174:
175: {
176: struct_liste_pile_systeme *l_element_courant;
177: struct_liste_pile_systeme *l_element_suivant;
178:
179: l_element_courant = (*s_etat_processus).pile_systeme_tampon;
180:
181: while(l_element_courant != NULL)
182: {
183: l_element_suivant = (*l_element_courant).suivant;
184: free(l_element_courant);
185: l_element_courant = l_element_suivant;
186: }
187: }
188:
189: {
190: struct_objet *l_element_courant;
191: struct_objet *l_element_suivant;
192:
193: l_element_courant = (*s_etat_processus).pile_objets;
194:
195: while(l_element_courant != NULL)
196: {
197: l_element_suivant = (*l_element_courant).objet;
198:
199: if (pthread_mutex_destroy(&((*l_element_courant).mutex)) != 0)
200: {
201: (*s_etat_processus).erreur_systeme = d_es_processus;
202: BUG(1, printf("Mutex error\n"));
203: return;
204: }
205:
206: free(l_element_courant);
207: l_element_courant = l_element_suivant;
208: }
209: }
210:
211: return;
212: }
213:
214:
215: /*
216: ================================================================================
217: Routine d'allocation d'un maillon d'un objet (liste, expression...)
218: ================================================================================
219: Entrées : structure sur l'état du processus et objet à afficher
220: --------------------------------------------------------------------------------
221: Sorties : chaine de caractères
222: --------------------------------------------------------------------------------
223: Effets de bord : néant
224: ================================================================================
225: */
226:
227: void *
228: allocation_maillon(struct_processus *s_etat_processus)
229: {
230: struct_liste_chainee *s_maillon;
231:
232: if ((*s_etat_processus).pointeur_maillons > 0)
233: {
234: s_maillon = (*s_etat_processus).maillons
235: [--(*s_etat_processus).pointeur_maillons];
236: }
237: else
238: {
239: if ((s_maillon = malloc(sizeof(struct_liste_chainee))) == NULL)
240: {
241: return(NULL);
242: }
243: }
244:
245: return(s_maillon);
246: }
247:
248:
249: /*
250: ================================================================================
1.53 bertrand 251: Routine de libération d'un maillon d'un objet (liste, expression...)
1.1 bertrand 252: ================================================================================
253: Entrées : structure sur l'état du processus et objet à afficher
254: --------------------------------------------------------------------------------
255: Sorties : chaine de caractères
256: --------------------------------------------------------------------------------
257: Effets de bord : néant
258: ================================================================================
259: */
260:
261: void
262: liberation_maillon(struct_processus *s_etat_processus,
263: struct_liste_chainee *maillon)
264: {
265: if ((*s_etat_processus).pointeur_maillons < TAILLE_CACHE)
266: {
267: (*s_etat_processus).maillons
268: [(*s_etat_processus).pointeur_maillons++] = maillon;
269: }
270: else
271: {
272: free(maillon);
273: }
274:
275: return;
276: }
277:
278:
279: /*
280: ================================================================================
281: Routine d'allocation d'une structure *s_objet
282: ================================================================================
1.28 bertrand 283: Entrées : structure sur l'état du processus et objet à allouer
1.1 bertrand 284: --------------------------------------------------------------------------------
285: Sorties : chaine de caractères
286: --------------------------------------------------------------------------------
287: Effets de bord : néant
288: ================================================================================
289: */
290:
1.55 bertrand 291: struct_objet *
1.1 bertrand 292: allocation(struct_processus *s_etat_processus, enum t_type type)
293: {
294: struct_objet *s_objet;
295:
1.28 bertrand 296: if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0)
297: {
298: (*s_etat_processus).erreur_systeme = d_es_processus;
299: return(NULL);
300: }
301:
1.1 bertrand 302: if ((*s_etat_processus).pile_objets == NULL)
303: {
1.28 bertrand 304: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
305: {
306: (*s_etat_processus).erreur_systeme = d_es_processus;
307: return(NULL);
308: }
309:
1.1 bertrand 310: // Il n'existe aucune structure struct_objet disponible dans le cache.
311:
312: if ((s_objet = malloc(sizeof(struct_objet))) == NULL)
313: {
314: return(NULL);
315: }
316:
317: initialisation_objet(s_objet);
318: }
319: else
320: {
321: // Récupération d'une structure dans le cache.
322:
323: s_objet = (*s_etat_processus).pile_objets;
324: (*s_etat_processus).pile_objets = (*s_objet).objet;
325: (*s_etat_processus).taille_pile_objets--;
326:
327: (*s_objet).nombre_occurrences = 1;
1.28 bertrand 328:
329: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
330: {
331: (*s_etat_processus).erreur_systeme = d_es_processus;
332: return(NULL);
333: }
1.1 bertrand 334: }
335:
336: (*s_objet).type = type;
337:
338: switch(type)
339: {
340: case ADR :
341: {
342: if ((*s_etat_processus).pointeur_adr > 0)
343: {
344: (*s_objet).objet = (*s_etat_processus).objets_adr
345: [--(*s_etat_processus).pointeur_adr];
346: }
347: else
348: {
349: if (((*s_objet).objet = malloc(sizeof(unsigned long))) == NULL)
350: {
351: free(s_objet);
352: return(NULL);
353: }
354: }
355:
356: break;
357: }
358:
359: case ALG :
360: {
361: (*s_objet).objet = NULL;
362: break;
363: }
364:
365: case BIN :
366: {
367: if ((*s_etat_processus).pointeur_bin > 0)
368: {
369: (*s_objet).objet = (*s_etat_processus).objets_bin
370: [--(*s_etat_processus).pointeur_bin];
371: }
372: else
373: {
374: if (((*s_objet).objet = malloc(sizeof(logical8))) == NULL)
375: {
376: free(s_objet);
377: return(NULL);
378: }
379: }
380:
381: break;
382: }
383:
384: case CHN :
385: {
386: (*s_objet).objet = NULL;
387: break;
388: }
389:
390: case CPL :
391: {
392: if ((*s_etat_processus).pointeur_cpl > 0)
393: {
394: (*s_objet).objet = (*s_etat_processus).objets_cpl
395: [--(*s_etat_processus).pointeur_cpl];
396: }
397: else
398: {
399: if (((*s_objet).objet = malloc(sizeof(struct_complexe16)))
400: == NULL)
401: {
402: free(s_objet);
403: return(NULL);
404: }
405: }
406:
407: break;
408: }
409:
410: case FCH :
411: {
412: if (((*s_objet).objet = malloc(sizeof(struct_fichier))) == NULL)
413: {
414: free(s_objet);
415: return(NULL);
416: }
417:
418: break;
419: }
420:
421: case FCT :
422: {
423: if ((*s_etat_processus).pointeur_fct > 0)
424: {
425: (*s_objet).objet = (*s_etat_processus).objets_fct
426: [--(*s_etat_processus).pointeur_fct];
427: }
428: else
429: {
430: if (((*s_objet).objet = malloc(sizeof(struct_fonction)))
431: == NULL)
432: {
433: free(s_objet);
434: return(NULL);
435: }
436: }
437:
1.5 bertrand 438: (*((struct_fonction *) (*s_objet).objet)).fonction = NULL;
1.1 bertrand 439: (*((struct_fonction *) (*s_objet).objet)).prediction_saut = NULL;
1.5 bertrand 440: (*((struct_fonction *) (*s_objet).objet)).prediction_execution
441: = d_faux;
1.1 bertrand 442: break;
443: }
444:
445: case INT :
446: {
447: if ((*s_etat_processus).pointeur_int > 0)
448: {
449: (*s_objet).objet = (*s_etat_processus).objets_int
450: [--(*s_etat_processus).pointeur_int];
451: }
452: else
453: {
454: if (((*s_objet).objet = malloc(sizeof(integer8))) == NULL)
455: {
456: free(s_objet);
457: return(NULL);
458: }
459: }
460:
461: break;
462: }
463:
464: case LST :
465: {
466: (*s_objet).objet = NULL;
467: break;
468: }
469:
470: case MCX :
471: {
472: if ((*s_etat_processus).pointeur_mat > 0)
473: {
474: (*s_objet).objet = (*s_etat_processus).objets_mat
475: [--(*s_etat_processus).pointeur_mat];
476: }
477: else
478: {
479: if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
480: {
481: free(s_objet);
482: return(NULL);
483: }
484: }
485:
486: (*((struct_matrice *) (*s_objet).objet)).type = 'C';
487: (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
488: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
489: (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
490: break;
491: }
492:
493: case MIN :
494: {
495: if ((*s_etat_processus).pointeur_mat > 0)
496: {
497: (*s_objet).objet = (*s_etat_processus).objets_mat
498: [--(*s_etat_processus).pointeur_mat];
499: }
500: else
501: {
502: if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
503: {
504: free(s_objet);
505: return(NULL);
506: }
507: }
508:
509: (*((struct_matrice *) (*s_objet).objet)).type = 'I';
510: (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
511: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
512: (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
513: break;
514: }
515:
516: case MRL :
517: {
518: if ((*s_etat_processus).pointeur_mat > 0)
519: {
520: (*s_objet).objet = (*s_etat_processus).objets_mat
521: [--(*s_etat_processus).pointeur_mat];
522: }
523: else
524: {
525: if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
526: {
527: free(s_objet);
528: return(NULL);
529: }
530: }
531:
532: (*((struct_matrice *) (*s_objet).objet)).type = 'R';
533: (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
534: (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
535: (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
536: break;
537: }
538:
539: case MTX :
540: {
541: if (((*s_objet).objet = malloc(sizeof(struct_mutex))) == NULL)
542: {
543: free(s_objet);
544: return(NULL);
545: }
546:
547: break;
548: }
549:
550: case NOM :
551: {
552: if ((*s_etat_processus).pointeur_nom > 0)
553: {
554: (*s_objet).objet = (*s_etat_processus).objets_nom
555: [--(*s_etat_processus).pointeur_nom];
556: }
557: else
558: {
559: if (((*s_objet).objet = malloc(sizeof(struct_nom))) == NULL)
560: {
561: free(s_objet);
562: return(NULL);
563: }
564: }
565:
566: break;
567: }
568:
569: case NON :
570: {
571: (*s_objet).objet = NULL;
572: break;
573: }
574:
575: case PRC :
576: {
577: if (((*s_objet).objet = malloc(sizeof(struct_processus_fils)))
578: == NULL)
579: {
580: free(s_objet);
581: return(NULL);
582: }
583:
584: break;
585: }
586:
587: case REL :
588: {
589: if ((*s_etat_processus).pointeur_rel > 0)
590: {
591: (*s_objet).objet = (*s_etat_processus).objets_rel
592: [--(*s_etat_processus).pointeur_rel];
593: }
594: else
595: {
596: if (((*s_objet).objet = malloc(sizeof(real8))) == NULL)
597: {
598: free(s_objet);
599: return(NULL);
600: }
601: }
602:
603: break;
604: }
605:
606: case RPN :
607: {
608: (*s_objet).objet = NULL;
609: break;
610: }
611:
612: case SCK :
613: {
614: if (((*s_objet).objet = malloc(sizeof(struct_socket))) == NULL)
615: {
616: free(s_objet);
617: return(NULL);
618: }
619:
620: break;
621: }
622:
623: case SLB :
624: {
625: if (((*s_objet).objet = malloc(sizeof(struct_bibliotheque)))
626: == NULL)
627: {
628: free(s_objet);
629: return(NULL);
630: }
631:
632: break;
633: }
634:
635: case SPH :
636: {
637: if (((*s_objet).objet = malloc(sizeof(struct_semaphore))) == NULL)
638: {
639: free(s_objet);
640: return(NULL);
641: }
642:
643: break;
644: }
645:
646: case SQL :
647: {
648: if (((*s_objet).objet = malloc(sizeof(struct_connecteur_sql)))
649: == NULL)
650: {
651: free(s_objet);
652: return(NULL);
653: }
654:
655: break;
656: }
657:
658: case TBL :
659: {
660: if ((*s_etat_processus).pointeur_tab > 0)
661: {
662: (*s_objet).objet = (*s_etat_processus).objets_tab
663: [--(*s_etat_processus).pointeur_tab];
664: }
665: else
666: {
667: if (((*s_objet).objet = malloc(sizeof(struct_tableau))) == NULL)
668: {
669: free(s_objet);
670: return(NULL);
671: }
672: }
673:
674: (*((struct_tableau *) (*s_objet).objet)).nombre_elements = 0;
675: (*((struct_tableau *) (*s_objet).objet)).elements = NULL;
676: break;
677: }
678:
679: case VCX :
680: {
681: if ((*s_etat_processus).pointeur_vec > 0)
682: {
683: (*s_objet).objet = (*s_etat_processus).objets_vec
684: [--(*s_etat_processus).pointeur_vec];
685: }
686: else
687: {
688: if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
689: {
690: free(s_objet);
691: return(NULL);
692: }
693: }
694:
695: (*((struct_vecteur *) (*s_objet).objet)).type = 'C';
696: (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
697: (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
698: break;
699: }
700:
701: case VIN :
702: {
703: if ((*s_etat_processus).pointeur_vec > 0)
704: {
705: (*s_objet).objet = (*s_etat_processus).objets_vec
706: [--(*s_etat_processus).pointeur_vec];
707: }
708: else
709: {
710: if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
711: {
712: free(s_objet);
713: return(NULL);
714: }
715: }
716:
717: (*((struct_vecteur *) (*s_objet).objet)).type = 'I';
718: (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
719: (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
720: break;
721: }
722:
723: case VRL :
724: {
725: if ((*s_etat_processus).pointeur_vec > 0)
726: {
727: (*s_objet).objet = (*s_etat_processus).objets_vec
728: [--(*s_etat_processus).pointeur_vec];
729: }
730: else
731: {
732: if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
733: {
734: free(s_objet);
735: return(NULL);
736: }
737: }
738:
739: (*((struct_vecteur *) (*s_objet).objet)).type = 'R';
740: (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
741: (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
742: break;
743: }
744:
745: default :
746: {
747: free(s_objet);
748: BUG(1, printf("Allocation failure (type %d)\n", type));
749:
750: return(NULL);
751: }
752: }
753:
754: return(s_objet);
755: }
756:
757:
758: /*
759: ================================================================================
760: Routine de libération d'une structure *s_objet
761: ================================================================================
762: Entrées : structure sur l'état du processus et objet à afficher
763: --------------------------------------------------------------------------------
764: Sorties : chaine de caractères
765: --------------------------------------------------------------------------------
766: Effets de bord : néant
767: ================================================================================
768: */
769:
770: void
771: liberation(struct_processus *s_etat_processus, struct_objet *s_objet)
772: {
773: logical1 drapeau;
774:
775: struct_liste_chainee *l_element_courant;
776: struct_liste_chainee *l_element_suivant;
777:
778: unsigned long i;
779:
780: if (s_objet == NULL)
781: {
782: return;
783: }
784:
785: if (pthread_mutex_lock(&((*s_objet).mutex)) != 0)
786: {
787: (*s_etat_processus).erreur_systeme = d_es_processus;
788: return;
789: }
790:
791: #define return \
792: if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0) \
793: { (*s_etat_processus).erreur_systeme = d_es_processus; return; } \
794: return
795:
796: BUG((*s_objet).nombre_occurrences <= 0,
797: pthread_mutex_unlock(&((*s_objet).mutex)),
798: printf("(*s_objet).nombre_occurrences=%ld\n",
799: (*s_objet).nombre_occurrences));
800:
801: switch((*s_objet).type)
802: {
803: case ADR :
804: {
805: if (decrementation_atomique(s_objet) > 0)
806: {
807: return;
808: }
809:
810: if ((*s_etat_processus).pointeur_adr < TAILLE_CACHE)
811: {
812: (*s_etat_processus).objets_adr
813: [(*s_etat_processus).pointeur_adr++] = (*s_objet).objet;
814: }
815: else
816: {
817: free((unsigned long *) ((*s_objet).objet));
818: }
819:
820: break;
821: }
822:
823: case ALG :
824: {
825: l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
826:
827: if (decrementation_atomique(s_objet) > 0)
828: { // Il reste un pointeur sur l'objet.
829: while(l_element_courant != NULL)
830: {
831: BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
832: pthread_mutex_unlock(&((*s_objet).mutex)),
833: printf("(*(*l_element_courant).donnee)"
834: ".nombre_occurrences=%ld\n",
835: (*(*l_element_courant).donnee).nombre_occurrences));
836:
837: liberation(s_etat_processus, (*l_element_courant).donnee);
838: l_element_courant = (*l_element_courant).suivant;
839: }
840:
841: return;
842: }
843: else
844: { // Il ne reste plus aucun pointeur sur l'objet.
845: while(l_element_courant != NULL)
846: {
847: l_element_suivant = (*l_element_courant).suivant;
848: liberation(s_etat_processus, (*l_element_courant).donnee);
849: liberation_maillon(s_etat_processus, l_element_courant);
850: l_element_courant = l_element_suivant;
851: }
852: }
853:
854: break;
855: }
856:
857: case BIN :
858: {
859: if (decrementation_atomique(s_objet) > 0)
860: {
861: return;
862: }
863:
864: if ((*s_etat_processus).pointeur_bin < TAILLE_CACHE)
865: {
866: (*s_etat_processus).objets_bin
867: [(*s_etat_processus).pointeur_bin++] = (*s_objet).objet;
868: }
869: else
870: {
871: free((logical8 *) ((*s_objet).objet));
872: }
873:
874: break;
875: }
876:
877: case CHN :
878: {
879: if (decrementation_atomique(s_objet) > 0)
880: {
881: return;
882: }
883:
884: free((unsigned char *) ((*s_objet).objet));
885: break;
886: }
887:
888: case CPL :
889: {
890: if (decrementation_atomique(s_objet) > 0)
891: {
892: return;
893: }
894:
895: if ((*s_etat_processus).pointeur_cpl < TAILLE_CACHE)
896: {
897: (*s_etat_processus).objets_cpl
898: [(*s_etat_processus).pointeur_cpl++] = (*s_objet).objet;
899: }
900: else
901: {
902: free((struct_complexe16 *) ((*s_objet).objet));
903: }
904:
905: break;
906: }
907:
908: case FCH :
909: {
910: if (decrementation_atomique(s_objet) > 0)
911: {
1.18 bertrand 912: BUG((*(*((struct_fichier *) (*s_objet).objet)).format)
913: .nombre_occurrences <= 1,
914: pthread_mutex_unlock(&((*s_objet).mutex)),
915: printf("(*(*((struct_fichier *) (*s_objet).objet))"
916: ".format).nombre_occurrences=%ld\n",
917: (*(*((struct_fichier *) (*s_objet).objet)).format)
918: .nombre_occurrences));
919:
920: liberation(s_etat_processus,
921: (*((struct_fichier *) (*s_objet).objet)).format);
1.1 bertrand 922: return;
923: }
924:
925: liberation(s_etat_processus,
926: (*((struct_fichier *) (*s_objet).objet)).format);
927: free((unsigned char *) (*((struct_fichier *)
928: (*s_objet).objet)).nom);
929: free((struct_fichier *) ((*s_objet).objet));
930: break;
931: }
932:
933: case FCT :
934: {
935: if (decrementation_atomique(s_objet) > 0)
936: {
937: return;
938: }
939:
940: free((unsigned char *) (*((struct_fonction *)
941: (*s_objet).objet)).nom_fonction);
942:
943: if ((*s_etat_processus).pointeur_fct < TAILLE_CACHE)
944: {
945: (*s_etat_processus).objets_fct
946: [(*s_etat_processus).pointeur_fct++] = (*s_objet).objet;
947: }
948: else
949: {
950: free((struct_fonction *) (*s_objet).objet);
951: }
952:
953: break;
954: }
955:
956: case INT :
957: {
958: if (decrementation_atomique(s_objet) > 0)
959: {
960: return;
961: }
962:
963: if ((*s_etat_processus).pointeur_int < TAILLE_CACHE)
964: {
965: (*s_etat_processus).objets_int
966: [(*s_etat_processus).pointeur_int++] = (*s_objet).objet;
967: }
968: else
969: {
970: free((integer8 *) ((*s_objet).objet));
971: }
972:
973: break;
974: }
975:
976: case LST :
977: {
978: l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
979:
980: if (decrementation_atomique(s_objet) > 0)
981: { // Il reste un pointeur sur l'objet.
982: while(l_element_courant != NULL)
983: {
984: BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
985: pthread_mutex_unlock(&((*s_objet).mutex)),
986: printf("(*(*l_element_courant).donnee)"
987: ".nombre_occurrences=%ld\n",
988: (*(*l_element_courant).donnee).nombre_occurrences));
989:
990: liberation(s_etat_processus, (*l_element_courant).donnee);
991: l_element_courant = (*l_element_courant).suivant;
992: }
993:
994: return;
995: }
996: else
997: { // Il ne reste plus aucun pointeur sur l'objet.
998: while(l_element_courant != NULL)
999: {
1000: l_element_suivant = (*l_element_courant).suivant;
1001: liberation(s_etat_processus, (*l_element_courant).donnee);
1002: liberation_maillon(s_etat_processus, l_element_courant);
1003: l_element_courant = l_element_suivant;
1004: }
1005: }
1006:
1007: break;
1008: }
1009:
1010: case MIN :
1011: {
1012: if (decrementation_atomique(s_objet) > 0)
1013: {
1014: return;
1015: }
1016:
1017: for(i = 0; i < (*((struct_matrice *)
1018: ((*s_objet).objet))).nombre_lignes; i++)
1019: {
1020: free(((integer8 **) (*((struct_matrice *)
1021: (*s_objet).objet)).tableau)[i]);
1022: }
1023:
1024: free((integer8 **) (*((struct_matrice *)
1025: (*s_objet).objet)).tableau);
1026:
1027: if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
1028: {
1029: (*s_etat_processus).objets_mat
1030: [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
1031: }
1032: else
1033: {
1034: free((struct_matrice *) (*s_objet).objet);
1035: }
1036:
1037: break;
1038: }
1039:
1040: case MCX :
1041: {
1042: if (decrementation_atomique(s_objet) > 0)
1043: {
1044: return;
1045: }
1046:
1047: for(i = 0; i < (*((struct_matrice *)
1048: ((*s_objet).objet))).nombre_lignes; i++)
1049: {
1050: free(((struct_complexe16 **) (*((struct_matrice *)
1051: (*s_objet).objet)).tableau)[i]);
1052: }
1053:
1054: free((struct_complexe16 **) (*((struct_matrice *)
1055: (*s_objet).objet)).tableau);
1056:
1057: if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
1058: {
1059: (*s_etat_processus).objets_mat
1060: [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
1061: }
1062: else
1063: {
1064: free((struct_matrice *) (*s_objet).objet);
1065: }
1066:
1067: break;
1068: }
1069:
1070: case MRL :
1071: {
1072: if (decrementation_atomique(s_objet) > 0)
1073: {
1074: return;
1075: }
1076:
1077: for(i = 0; i < (*((struct_matrice *)
1078: ((*s_objet).objet))).nombre_lignes; i++)
1079: {
1080: free(((real8 **) (*((struct_matrice *)
1081: (*s_objet).objet)).tableau)[i]);
1082: }
1083:
1084: free((real8 **) (*((struct_matrice *) (*s_objet).objet)).tableau);
1085:
1086: if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
1087: {
1088: (*s_etat_processus).objets_mat
1089: [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
1090: }
1091: else
1092: {
1093: free((struct_matrice *) (*s_objet).objet);
1094: }
1095:
1096: break;
1097: }
1098:
1099: case MTX :
1100: {
1101: if (decrementation_atomique(s_objet) > 0)
1102: {
1103: return;
1104: }
1105:
1106: free((struct_mutex *) (*s_objet).objet);
1107: break;
1108: }
1109:
1110: case NOM :
1111: {
1112: if (decrementation_atomique(s_objet) > 0)
1113: {
1114: return;
1115: }
1116:
1117: free((*((struct_nom *) (*s_objet).objet)).nom);
1118:
1119: if ((*s_etat_processus).pointeur_nom < TAILLE_CACHE)
1120: {
1121: (*s_etat_processus).objets_nom
1122: [(*s_etat_processus).pointeur_nom++] = (*s_objet).objet;
1123: }
1124: else
1125: {
1126: free((struct_nom *) (*s_objet).objet);
1127: }
1128:
1129: break;
1130: }
1131:
1132: case NON :
1133: {
1134: if (decrementation_atomique(s_objet) > 0)
1135: {
1136: return;
1137: }
1138:
1139: break;
1140: }
1141:
1142: case PRC :
1143: {
1144: if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
1.40 bertrand 1145: (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1 bertrand 1146: {
1147: (*s_etat_processus).erreur_systeme = d_es_processus;
1148: return;
1149: }
1150:
1151: (*(*((struct_processus_fils *) (*s_objet).objet)).thread)
1152: .nombre_references--;
1153:
1154: BUG((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
1.24 bertrand 1155: .nombre_references < 0, uprintf(
1156: "(*(*((struct_processus_fils"
1.1 bertrand 1157: " *) (*s_objet).objet)).thread).nombre_references = %d\n",
1158: (int) (*(*((struct_processus_fils *) (*s_objet).objet))
1159: .thread).nombre_references));
1160:
1161: if ((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
1162: .nombre_references == 0)
1163: {
1164: drapeau = d_vrai;
1165: }
1166: else
1167: {
1168: drapeau = d_faux;
1169: }
1170:
1171: if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
1.40 bertrand 1172: (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1 bertrand 1173: {
1174: (*s_etat_processus).erreur_systeme = d_es_processus;
1175: return;
1176: }
1177:
1178: if (drapeau == d_vrai)
1179: {
1180: pthread_mutex_destroy(&((*(*((struct_processus_fils *)
1181: (*s_objet).objet)).thread).mutex));
1.40 bertrand 1182: pthread_mutex_destroy(&((*(*((struct_processus_fils *)
1183: (*s_objet).objet)).thread).mutex_nombre_references));
1.1 bertrand 1184: free((*((struct_processus_fils *) (*s_objet).objet)).thread);
1185: }
1186:
1187: if (decrementation_atomique(s_objet) > 0)
1188: {
1.28 bertrand 1189: BUG(drapeau == d_vrai, uprintf("(*(*((struct_processus_fils"
1190: " *) (*s_objet).objet)).thread).nombre_references "
1191: "= 0 with nombre_occurrences > 0\n"));
1.1 bertrand 1192: return;
1193: }
1194:
1195: free((struct_processus_fils *) ((*s_objet).objet));
1196: break;
1197: }
1198:
1199: case REL :
1200: {
1201: if (decrementation_atomique(s_objet) > 0)
1202: {
1203: return;
1204: }
1205:
1206: if ((*s_etat_processus).pointeur_rel < TAILLE_CACHE)
1207: {
1208: (*s_etat_processus).objets_rel
1209: [(*s_etat_processus).pointeur_rel++] = (*s_objet).objet;
1210: }
1211: else
1212: {
1213: free((real8 *) ((*s_objet).objet));
1214: }
1215:
1216: break;
1217: }
1218:
1219: case RPN :
1220: {
1221: l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
1222:
1223: if (decrementation_atomique(s_objet) > 0)
1224: { // Il reste un pointeur sur l'objet.
1225: while(l_element_courant != NULL)
1226: {
1227: BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
1228: pthread_mutex_unlock(&((*s_objet).mutex)),
1229: printf("(*(*l_element_courant).donnee)"
1230: ".nombre_occurrences=%ld\n",
1231: (*(*l_element_courant).donnee).nombre_occurrences));
1232:
1233: liberation(s_etat_processus, (*l_element_courant).donnee);
1234: l_element_courant = (*l_element_courant).suivant;
1235: }
1236:
1237: return;
1238: }
1239: else
1240: { // Il ne reste plus aucun pointeur sur l'objet.
1241: while(l_element_courant != NULL)
1242: {
1243: l_element_suivant = (*l_element_courant).suivant;
1244: liberation(s_etat_processus, (*l_element_courant).donnee);
1245: liberation_maillon(s_etat_processus, l_element_courant);
1246: l_element_courant = l_element_suivant;
1247: }
1248: }
1249:
1250: break;
1251: }
1252:
1253: case SCK :
1254: {
1255: if (decrementation_atomique(s_objet) > 0)
1256: {
1.18 bertrand 1257: BUG((*(*((struct_socket *) (*s_objet).objet)).format)
1258: .nombre_occurrences <= 1,
1259: pthread_mutex_unlock(&((*s_objet).mutex)),
1260: printf("(*(*((struct_socket *) (*s_objet).objet))"
1261: ".format).nombre_occurrences=%ld\n",
1262: (*(*((struct_socket *) (*s_objet).objet)).format)
1263: .nombre_occurrences));
1264:
1.17 bertrand 1265: liberation(s_etat_processus, (*((struct_socket *)
1266: (*s_objet).objet)).format);
1.1 bertrand 1267: return;
1268: }
1269:
1270: liberation(s_etat_processus, (*((struct_socket *)
1271: (*s_objet).objet)).format);
1.18 bertrand 1272:
1.1 bertrand 1273: free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
1274: .adresse);
1275: free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
1276: .adresse_distante);
1277: free((struct_socket *) ((*s_objet).objet));
1278: break;
1279: }
1280:
1281: case SLB :
1282: {
1283: if (decrementation_atomique(s_objet) > 0)
1284: {
1285: return;
1286: }
1287:
1288: free((*((struct_bibliotheque *) (*s_objet).objet)).nom);
1289: free((struct_bibliotheque *) (*s_objet).objet);
1290: break;
1291: }
1292:
1293: case SPH :
1294: {
1295: if (decrementation_atomique(s_objet) > 0)
1296: {
1297: return;
1298: }
1299:
1300: free((*((struct_semaphore *) (*s_objet).objet)).nom);
1301: free((struct_bibliotheque *) (*s_objet).objet);
1302: break;
1303: }
1304:
1305: case SQL :
1306: {
1307: if (decrementation_atomique(s_objet) > 0)
1308: {
1309: return;
1310: }
1311:
1312: free((*((struct_connecteur_sql *) (*s_objet).objet)).type);
1313: free((*((struct_connecteur_sql *) (*s_objet).objet)).locale);
1314: free((struct_connecteur_sql *) (*s_objet).objet);
1315: break;
1316: }
1317:
1318: case TBL :
1319: {
1320: if (decrementation_atomique(s_objet) > 0)
1321: {
1322: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
1323: .nombre_elements; i++)
1324: {
1325: BUG((*((*((struct_tableau *)
1326: (*s_objet).objet)).elements[i]))
1327: .nombre_occurrences <= 1,
1328: pthread_mutex_unlock(&((*s_objet).mutex)),
1329: printf("(*((*((struct_tableau *) (*s_objet).objet))"
1330: ".element[%lu])).nombre_occurrences=%ld\n", i,
1331: (*((*((struct_tableau *) (*s_objet).objet))
1332: .elements[i])).nombre_occurrences));
1333: liberation(s_etat_processus, (*((struct_tableau *)
1334: (*s_objet).objet)).elements[i]);
1335: }
1336:
1337: return;
1338: }
1339:
1340: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
1341: .nombre_elements; i++)
1342: {
1343: liberation(s_etat_processus, (*((struct_tableau *)
1344: (*s_objet).objet)).elements[i]);
1345: }
1346:
1347: free((*((struct_tableau *) (*s_objet).objet)).elements);
1348:
1349: if ((*s_etat_processus).pointeur_tab < TAILLE_CACHE)
1350: {
1351: (*s_etat_processus).objets_tab
1352: [(*s_etat_processus).pointeur_tab++] = (*s_objet).objet;
1353: }
1354: else
1355: {
1356: free((struct_tableau *) (*s_objet).objet);
1357: }
1358:
1359: break;
1360: }
1361:
1362: case VIN :
1363: {
1364: if (decrementation_atomique(s_objet) > 0)
1365: {
1366: return;
1367: }
1368:
1369: free((integer8 *) (*((struct_vecteur *) (*s_objet).objet)).tableau);
1370:
1371: if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
1372: {
1373: (*s_etat_processus).objets_vec
1374: [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
1375: }
1376: else
1377: {
1378: free((struct_vecteur *) (*s_objet).objet);
1379: }
1380:
1381: break;
1382: }
1383:
1384: case VCX :
1385: {
1386: if (decrementation_atomique(s_objet) > 0)
1387: {
1388: return;
1389: }
1390:
1391: free((struct_complexe16 *) (*((struct_vecteur *)
1392: (*s_objet).objet)).tableau);
1393:
1394: if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
1395: {
1396: (*s_etat_processus).objets_vec
1397: [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
1398: }
1399: else
1400: {
1401: free((struct_vecteur *) (*s_objet).objet);
1402: }
1403:
1404: break;
1405: }
1406:
1407: case VRL :
1408: {
1409: if (decrementation_atomique(s_objet) > 0)
1410: {
1411: return;
1412: }
1413:
1414: free((real8 *) (*((struct_vecteur *) (*s_objet).objet)).tableau);
1415:
1416: if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
1417: {
1418: (*s_etat_processus).objets_vec
1419: [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
1420: }
1421: else
1422: {
1423: free((struct_vecteur *) (*s_objet).objet);
1424: }
1425:
1426: break;
1427: }
1428:
1429: default :
1430: {
1431: if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0)
1432: {
1433: (*s_etat_processus).erreur_systeme = d_es_processus;
1434: return;
1435: }
1436:
1437: if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0)
1438: {
1439: (*s_etat_processus).erreur_systeme = d_es_processus;
1440: return;
1441: }
1442:
1443: BUG(1, printf("Free failure (type %d)\n", (*s_objet).type));
1444: return;
1445: }
1446: }
1447:
1448: #undef return
1449:
1450: if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0)
1451: {
1452: (*s_etat_processus).erreur_systeme = d_es_processus;
1453: return;
1454: }
1455:
1.28 bertrand 1456: if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0)
1.1 bertrand 1457: {
1.28 bertrand 1458: (*s_etat_processus).erreur_systeme = d_es_processus;
1459: return;
1460: }
1461:
1462: if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE)
1463: {
1464: (*s_objet).objet = (*s_etat_processus).pile_objets;
1465: (*s_etat_processus).pile_objets = s_objet;
1466: (*s_etat_processus).taille_pile_objets++;
1467: }
1468: else
1469: {
1470: if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0)
1.1 bertrand 1471: {
1.28 bertrand 1472: pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation));
1473: (*s_etat_processus).erreur_systeme = d_es_processus;
1474: return;
1.1 bertrand 1475: }
1476:
1.28 bertrand 1477: free(s_objet);
1.1 bertrand 1478: }
1.28 bertrand 1479:
1480: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
1.1 bertrand 1481: {
1.28 bertrand 1482: (*s_etat_processus).erreur_systeme = d_es_processus;
1483: return;
1.1 bertrand 1484: }
1485:
1486: return;
1487: }
1488:
1489:
1490: /*
1491: ================================================================================
1492: Routine de copie d'une structure *s_objet
1493: ================================================================================
1494: Entrées : structure *s_objet à copier
1495: type :
1496: 'P' : renvoie le même objet en incrémentant le nombre
1497: d'occurrence de chaque objet élémentaire ;
1498: 'O' : crée un nouvel objet en copiant chaque objet élémentaire ;
1499: 'N' : crée un nouvel objet mais les objets élémentaires
1500: sont réutilisés (voir 'P'). Dans le cas d'un objet
1501: élémentaire, 'N' et 'P' sont identiques.
1502: 'Q' : 'P' si nombre_occurrences vaut 1, 'O' sinon.
1503: 'R' : 'P' si nombre_occurrences vaut 1, 'N' sinon.
1504: --------------------------------------------------------------------------------
1505: Sorties : structure identique (tous les objets sont copiés)
1506: --------------------------------------------------------------------------------
1507: Effets de bord : néant
1508: ================================================================================
1509: */
1510:
1511: struct_objet *
1512: copie_objet(struct_processus *s_etat_processus,
1513: struct_objet *s_objet, unsigned char type)
1514: {
1515: struct_liste_chainee *l_element_base;
1516: struct_liste_chainee *l_element_courant;
1517: struct_liste_chainee *l_element_courant_ecriture;
1518: struct_liste_chainee *l_element_courant_lecture;
1519: struct_liste_chainee *l_element_suivant_ecriture;
1520: struct_liste_chainee *l_element_suivant_lecture;
1521:
1522: struct_objet *s_nouvel_objet;
1523: struct_objet *s_objet_tampon;
1524:
1525: unsigned long i;
1526: unsigned long j;
1527:
1528: if (pthread_mutex_lock(&((*s_objet).mutex)) != 0)
1529: {
1530: (*s_etat_processus).erreur_systeme = d_es_processus;
1531: return(NULL);
1532: }
1533:
1534: if (type == 'Q')
1535: {
1536: if ((*s_objet).nombre_occurrences == 1)
1537: {
1538: type = 'P';
1539: }
1540: else
1541: {
1542: type = 'O';
1543: }
1544: }
1545: else if (type == 'R')
1546: {
1547: if ((*s_objet).nombre_occurrences == 1)
1548: {
1549: type = 'P';
1550: }
1551: else
1552: {
1553: type = 'N';
1554: }
1555: }
1556:
1557: #define return(pointeur) \
1558: if (pthread_mutex_unlock(&((*s_objet).mutex))) \
1559: { (*s_etat_processus).erreur_systeme = d_es_processus; return(NULL); } \
1560: return(pointeur)
1561:
1562: switch((*s_objet).type)
1563: {
1564: case ADR :
1565: {
1566: if (type != 'O')
1567: {
1568: incrementation_atomique(s_objet);
1569: return(s_objet);
1570: }
1571:
1572: if ((s_nouvel_objet = allocation(s_etat_processus, ADR)) == NULL)
1573: {
1574: return(NULL);
1575: }
1576:
1577: (*((unsigned long *) ((*s_nouvel_objet).objet))) =
1578: (*((unsigned long *) ((*s_objet).objet)));
1579: break;
1580: }
1581:
1582: case ALG :
1583: {
1584: if (type != 'P')
1585: {
1586: if ((s_nouvel_objet = allocation(s_etat_processus, ALG))
1587: == NULL)
1588: {
1589: return(NULL);
1590: }
1591:
1592: l_element_courant_lecture = (struct_liste_chainee *)
1593: ((*s_objet).objet);
1594:
1595: l_element_base = NULL;
1596: l_element_courant_ecriture = l_element_base;
1597:
1598: while(l_element_courant_lecture != NULL)
1599: {
1600: s_objet_tampon = copie_objet(s_etat_processus,
1601: (*l_element_courant_lecture).donnee, type);
1602: l_element_suivant_ecriture = (struct_liste_chainee *)
1603: malloc(sizeof(struct_liste_chainee));
1604:
1605: if ((s_objet_tampon == NULL) ||
1606: (l_element_suivant_ecriture == NULL))
1607: {
1608: l_element_courant_lecture = (struct_liste_chainee *)
1609: ((*s_nouvel_objet).objet);
1610:
1611: while(l_element_courant_lecture != NULL)
1612: {
1613: l_element_suivant_lecture =
1614: (*l_element_courant_lecture).suivant;
1615: liberation(s_etat_processus,
1616: (*l_element_courant_lecture).donnee);
1617: free(l_element_courant_lecture);
1618: l_element_courant_lecture =
1619: l_element_suivant_lecture;
1620: }
1621:
1622: return(NULL);
1623: }
1624:
1625: if (l_element_courant_ecriture == NULL)
1626: {
1627: l_element_base = l_element_suivant_ecriture;
1628: }
1629: else
1630: {
1631: (*l_element_courant_ecriture).suivant =
1632: l_element_suivant_ecriture;
1633: }
1634:
1635: l_element_courant_ecriture = l_element_suivant_ecriture;
1636:
1637: (*l_element_courant_ecriture).donnee = s_objet_tampon;
1638: (*l_element_courant_ecriture).suivant = NULL;
1639: l_element_courant_lecture =
1640: (*l_element_courant_lecture).suivant;
1641: }
1642:
1643: (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
1644: l_element_base);
1645: }
1646: else // type == 'P'
1647: {
1648: incrementation_atomique(s_objet);
1649: l_element_courant = (*s_objet).objet;
1650:
1651: while(l_element_courant != NULL)
1652: {
1653: (*l_element_courant).donnee = copie_objet(s_etat_processus,
1654: (*l_element_courant).donnee, 'P');
1655: l_element_courant = (*l_element_courant).suivant;
1656: }
1657:
1658: return(s_objet);
1659: }
1660:
1661: break;
1662: }
1663:
1664: case BIN :
1665: {
1666: if (type != 'O')
1667: {
1668: incrementation_atomique(s_objet);
1669: return(s_objet);
1670: }
1671:
1672: if ((s_nouvel_objet = allocation(s_etat_processus, BIN)) == NULL)
1673: {
1674: return(NULL);
1675: }
1676:
1677: (*((logical8 *) ((*s_nouvel_objet).objet))) =
1678: (*((logical8 *) ((*s_objet).objet)));
1679: break;
1680: }
1681:
1682: case CHN :
1683: {
1684: if (type != 'O')
1685: {
1686: incrementation_atomique(s_objet);
1687: return(s_objet);
1688: }
1689:
1690: if ((s_nouvel_objet = allocation(s_etat_processus, CHN)) == NULL)
1691: {
1692: return(NULL);
1693: }
1694:
1695: (*s_nouvel_objet).objet = (void *) ((unsigned char *)
1696: malloc((strlen((unsigned char *) ((*s_objet).objet)) + 1)
1697: * sizeof(unsigned char)));
1698:
1699: if ((*s_nouvel_objet).objet == NULL)
1700: {
1701: free(s_nouvel_objet);
1702: return(NULL);
1703: }
1704:
1705: strcpy((unsigned char *) ((*s_nouvel_objet).objet),
1706: (unsigned char *) ((*s_objet).objet));
1707: break;
1708: }
1709:
1710: case CPL :
1711: {
1712: if (type != 'O')
1713: {
1714: incrementation_atomique(s_objet);
1715: return(s_objet);
1716: }
1717:
1718: if ((s_nouvel_objet = allocation(s_etat_processus, CPL)) == NULL)
1719: {
1720: return(NULL);
1721: }
1722:
1723: (*((struct_complexe16 *) ((*s_nouvel_objet).objet))) =
1724: (*((struct_complexe16 *) ((*s_objet).objet)));
1725: break;
1726: }
1727:
1728: case RPN :
1729: {
1730: if (type != 'P')
1731: {
1732: if ((s_nouvel_objet = allocation(s_etat_processus, RPN))
1733: == NULL)
1734: {
1735: return(NULL);
1736: }
1737:
1738: l_element_courant_lecture = (struct_liste_chainee *)
1739: ((*s_objet).objet);
1740:
1741: l_element_base = NULL;
1742: l_element_courant_ecriture = l_element_base;
1743:
1744: while(l_element_courant_lecture != NULL)
1745: {
1746: s_objet_tampon = copie_objet(s_etat_processus,
1747: (*l_element_courant_lecture).donnee, type);
1748: l_element_suivant_ecriture = (struct_liste_chainee *)
1749: malloc(sizeof(struct_liste_chainee));
1750:
1751: if ((s_objet_tampon == NULL) ||
1752: (l_element_suivant_ecriture == NULL))
1753: {
1754: l_element_courant_lecture = (struct_liste_chainee *)
1755: ((*s_nouvel_objet).objet);
1756:
1757: while(l_element_courant_lecture != NULL)
1758: {
1759: l_element_suivant_lecture =
1760: (*l_element_courant_lecture).suivant;
1761: liberation(s_etat_processus,
1762: (*l_element_courant_lecture).donnee);
1763: free(l_element_courant_lecture);
1764: l_element_courant_lecture =
1765: l_element_suivant_lecture;
1766: }
1767:
1768: return(NULL);
1769: }
1770:
1771: if (l_element_courant_ecriture == NULL)
1772: {
1773: l_element_base = l_element_suivant_ecriture;
1774: }
1775: else
1776: {
1777: (*l_element_courant_ecriture).suivant =
1778: l_element_suivant_ecriture;
1779: }
1780:
1781: l_element_courant_ecriture = l_element_suivant_ecriture;
1782:
1783: (*l_element_courant_ecriture).donnee = s_objet_tampon;
1784: (*l_element_courant_ecriture).suivant = NULL;
1785: l_element_courant_lecture =
1786: (*l_element_courant_lecture).suivant;
1787: }
1788:
1789: (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
1790: l_element_base);
1791: }
1792: else // type == 'P'
1793: {
1794: incrementation_atomique(s_objet);
1795: l_element_courant = (*s_objet).objet;
1796:
1797: while(l_element_courant != NULL)
1798: {
1799: (*l_element_courant).donnee = copie_objet(s_etat_processus,
1800: (*l_element_courant).donnee, 'P');
1801: l_element_courant = (*l_element_courant).suivant;
1802: }
1803:
1804: return(s_objet);
1805: }
1806:
1807: break;
1808: }
1809:
1810: case FCH :
1811: {
1812: if (type == 'P')
1813: {
1814: incrementation_atomique(s_objet);
1.17 bertrand 1815:
1816: if (((*((struct_fichier *) ((*s_objet).objet))).format =
1817: copie_objet(s_etat_processus, (*((struct_fichier *)
1818: ((*s_objet).objet))).format, 'P')) == NULL)
1819: {
1820: return(NULL);
1821: }
1822:
1.1 bertrand 1823: return(s_objet);
1824: }
1825:
1826: if ((s_nouvel_objet = allocation(s_etat_processus, FCH)) == NULL)
1827: {
1828: return(NULL);
1829: }
1830:
1831: (*((struct_fichier *) ((*s_nouvel_objet).objet))).descripteur =
1832: (*((struct_fichier *) ((*s_objet).objet))).descripteur;
1833: (*((struct_fichier *) ((*s_nouvel_objet).objet))).acces =
1834: (*((struct_fichier *) ((*s_objet).objet))).acces;
1835: (*((struct_fichier *) ((*s_nouvel_objet).objet))).binaire =
1836: (*((struct_fichier *) ((*s_objet).objet))).binaire;
1837: (*((struct_fichier *) ((*s_nouvel_objet).objet))).ouverture =
1838: (*((struct_fichier *) ((*s_objet).objet))).ouverture;
1839: (*((struct_fichier *) ((*s_nouvel_objet).objet))).protection =
1840: (*((struct_fichier *) ((*s_objet).objet))).protection;
1841: (*((struct_fichier *) ((*s_nouvel_objet).objet)))
1842: .position_clef = (*((struct_fichier *)
1843: ((*s_objet).objet))).position_clef;
1844: (*((struct_fichier *) ((*s_nouvel_objet).objet))).pid =
1845: (*((struct_fichier *) ((*s_objet).objet))).pid;
1846: (*((struct_fichier *) ((*s_nouvel_objet).objet))).tid =
1847: (*((struct_fichier *) ((*s_objet).objet))).tid;
1848:
1849: if (((*((struct_fichier *) ((*s_nouvel_objet).objet))).format =
1850: copie_objet(s_etat_processus, (*((struct_fichier *)
1851: ((*s_objet).objet))).format, type)) == NULL)
1852: {
1853: free((*s_nouvel_objet).objet);
1854: free(s_nouvel_objet);
1855: return(NULL);
1856: }
1857:
1858: if (((*((struct_fichier *) ((*s_nouvel_objet).objet))).nom =
1859: (unsigned char *) malloc((strlen((*((struct_fichier *)
1860: ((*s_objet).objet))).nom) + 1) * sizeof(unsigned char)))
1861: == NULL)
1862: {
1863: liberation(s_etat_processus, (*((struct_fichier *)
1864: (*s_nouvel_objet).objet)).format);
1865: free((*s_nouvel_objet).objet);
1866: free(s_nouvel_objet);
1867: return(NULL);
1868: }
1869:
1870: strcpy((*((struct_fichier *) ((*s_nouvel_objet).objet))).nom,
1871: (*((struct_fichier *) ((*s_objet).objet))).nom);
1872: break;
1873: }
1874:
1875: case FCT :
1876: {
1877: if (type != 'O')
1878: {
1879: /*
1880: * Remise à zéro de la prédiction pour respecter la cohérence
1881: * du saut dans les cas EXSUB et OBSUB.
1882: */
1883:
1884: (*((struct_fonction *) ((*s_objet).objet)))
1885: .prediction_saut = NULL;
1886: incrementation_atomique(s_objet);
1887: return(s_objet);
1888: }
1889:
1890: if ((s_nouvel_objet = allocation(s_etat_processus, FCT)) == NULL)
1891: {
1892: return(NULL);
1893: }
1894:
1895: if (((*((struct_fonction *) ((*s_nouvel_objet).objet)))
1896: .nom_fonction = (unsigned char *)
1897: malloc((strlen((*((struct_fonction *)
1898: ((*s_objet).objet))).nom_fonction) + 1) *
1899: sizeof(unsigned char))) == NULL)
1900: {
1901: free(s_nouvel_objet);
1902: return(NULL);
1903: }
1904:
1905: strcpy((unsigned char *) (*((struct_fonction *)
1906: ((*s_nouvel_objet).objet))).nom_fonction,
1907: (unsigned char *) (*((struct_fonction *)
1908: ((*s_objet).objet))).nom_fonction);
1909: (*((struct_fonction *) ((*s_nouvel_objet).objet)))
1910: .nombre_arguments = (*((struct_fonction *)
1911: ((*s_objet).objet))).nombre_arguments;
1912: (*((struct_fonction *) ((*s_nouvel_objet).objet))).fonction =
1913: (*((struct_fonction *) ((*s_objet).objet))).fonction;
1914: break;
1915: }
1916:
1917: case INT :
1918: {
1919: if (type != 'O')
1920: {
1921: incrementation_atomique(s_objet);
1922: return(s_objet);
1923: }
1924:
1925: if ((s_nouvel_objet = allocation(s_etat_processus, INT)) == NULL)
1926: {
1927: return(NULL);
1928: }
1929:
1930: (*((integer8 *) ((*s_nouvel_objet).objet))) =
1931: (*((integer8 *) ((*s_objet).objet)));
1932: break;
1933: }
1934:
1935: case LST :
1936: {
1937: if (type != 'P')
1938: {
1939: if ((s_nouvel_objet = allocation(s_etat_processus, LST))
1940: == NULL)
1941: {
1942: return(NULL);
1943: }
1944:
1945: l_element_courant_lecture = (struct_liste_chainee *)
1946: ((*s_objet).objet);
1947:
1948: l_element_base = NULL;
1949: l_element_courant_ecriture = l_element_base;
1950:
1951: while(l_element_courant_lecture != NULL)
1952: {
1953: s_objet_tampon = copie_objet(s_etat_processus,
1954: (*l_element_courant_lecture).donnee, type);
1955: l_element_suivant_ecriture = (struct_liste_chainee *)
1956: malloc(sizeof(struct_liste_chainee));
1957:
1958: if ((s_objet_tampon == NULL) ||
1959: (l_element_suivant_ecriture == NULL))
1960: {
1961: l_element_courant_lecture = (struct_liste_chainee *)
1962: ((*s_nouvel_objet).objet);
1963:
1964: while(l_element_courant_lecture != NULL)
1965: {
1966: l_element_suivant_lecture =
1967: (*l_element_courant_lecture).suivant;
1968: liberation(s_etat_processus,
1969: (*l_element_courant_lecture).donnee);
1970: free(l_element_courant_lecture);
1971: l_element_courant_lecture =
1972: l_element_suivant_lecture;
1973: }
1974:
1975: return(NULL);
1976: }
1977:
1978: if (l_element_courant_ecriture == NULL)
1979: {
1980: l_element_base = l_element_suivant_ecriture;
1981: }
1982: else
1983: {
1984: (*l_element_courant_ecriture).suivant =
1985: l_element_suivant_ecriture;
1986: }
1987:
1988: l_element_courant_ecriture = l_element_suivant_ecriture;
1989:
1990: (*l_element_courant_ecriture).donnee = s_objet_tampon;
1991: (*l_element_courant_ecriture).suivant = NULL;
1992: l_element_courant_lecture =
1993: (*l_element_courant_lecture).suivant;
1994: }
1995:
1996: (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
1997: l_element_base);
1998: }
1999: else
2000: {
2001: incrementation_atomique(s_objet);
2002: l_element_courant = (*s_objet).objet;
2003:
2004: while(l_element_courant != NULL)
2005: {
2006: (*l_element_courant).donnee = copie_objet(s_etat_processus,
2007: (*l_element_courant).donnee, 'P');
2008: l_element_courant = (*l_element_courant).suivant;
2009: }
2010:
2011: return(s_objet);
2012: }
2013:
2014: break;
2015: }
2016:
2017: case MIN :
2018: {
2019: if (type != 'O')
2020: {
2021: incrementation_atomique(s_objet);
2022: return(s_objet);
2023: }
2024:
2025: if ((s_nouvel_objet = allocation(s_etat_processus, MIN)) == NULL)
2026: {
2027: return(NULL);
2028: }
2029:
2030: (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau =
2031: (void **) ((integer8 **) malloc(
2032: ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
2033: * sizeof(integer8 *)));
2034:
2035: if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
2036: == NULL)
2037: {
2038: free((*s_nouvel_objet).objet);
2039: free(s_nouvel_objet);
2040: return(NULL);
2041: }
2042:
2043: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
2044: (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
2045: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
2046: (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
2047: (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
2048: (*((struct_matrice *) ((*s_objet).objet))).type;
2049:
2050: for(i = 0; i < (*((struct_matrice *)
2051: ((*s_objet).objet))).nombre_lignes; i++)
2052: {
2053: if ((((integer8 **) ((*((struct_matrice *)
2054: ((*s_nouvel_objet).objet))).tableau))[i] =
2055: (void *) ((integer8 *) malloc(
2056: ((*((struct_matrice *) ((*s_objet).objet)))
2057: .nombre_colonnes) * sizeof(integer8)))) == NULL)
2058: {
2059: for(j = 0; j < i; j++)
2060: {
2061: free(((integer8 **) ((*((struct_matrice *)
2062: ((*s_nouvel_objet).objet))).tableau))[j]);
2063: }
2064:
2065: free((*s_nouvel_objet).objet);
2066: free(s_nouvel_objet);
2067: return(NULL);
2068: }
2069:
2070: for(j = 0; j < (*((struct_matrice *)
2071: ((*s_objet).objet))).nombre_colonnes; j++)
2072: {
2073: ((integer8 **) ((*((struct_matrice *)
2074: ((*s_nouvel_objet).objet))).tableau))[i][j] =
2075: ((integer8 **) ((*((struct_matrice *)
2076: ((*s_objet).objet))).tableau))[i][j];
2077: }
2078: }
2079:
2080: break;
2081: }
2082:
2083: case MCX :
2084: {
2085: if (type != 'O')
2086: {
2087: incrementation_atomique(s_objet);
2088: return(s_objet);
2089: }
2090:
2091: if ((s_nouvel_objet = allocation(s_etat_processus, MCX))
2092: == NULL)
2093: {
2094: return(NULL);
2095: }
2096:
2097: (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau =
2098: (void **) ((struct_complexe16 **) malloc(
2099: ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
2100: * sizeof(struct_complexe16 *)));
2101:
2102: if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
2103: == NULL)
2104: {
2105: free((*s_nouvel_objet).objet);
2106: free(s_nouvel_objet);
2107: return(NULL);
2108: }
2109:
2110: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
2111: (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
2112: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
2113: (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
2114: (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
2115: (*((struct_matrice *) ((*s_objet).objet))).type;
2116:
2117: for(i = 0; i < (*((struct_matrice *)
2118: ((*s_objet).objet))).nombre_lignes; i++)
2119: {
2120: if ((((struct_complexe16 **) ((*((struct_matrice *)
2121: ((*s_nouvel_objet).objet))).tableau))[i] =
2122: (void *) ((struct_complexe16 *) malloc(
2123: ((*((struct_matrice *) ((*s_objet).objet)))
2124: .nombre_colonnes) * sizeof(struct_complexe16))))
2125: == NULL)
2126: {
2127: for(j = 0; j < i; j++)
2128: {
2129: free(((struct_complexe16 **) ((*((struct_matrice *)
2130: ((*s_nouvel_objet).objet))).tableau))[j]);
2131: }
2132:
2133: free((*s_nouvel_objet).objet);
2134: free(s_nouvel_objet);
2135: return(NULL);
2136: }
2137:
2138: for(j = 0; j < (*((struct_matrice *)
2139: ((*s_objet).objet))).nombre_colonnes; j++)
2140: {
2141: ((struct_complexe16 **) ((*((struct_matrice *)
2142: ((*s_nouvel_objet).objet))).tableau))[i][j] =
2143: ((struct_complexe16 **) ((*((struct_matrice *)
2144: ((*s_objet).objet))).tableau))[i][j];
2145: }
2146: }
2147:
2148: break;
2149: }
2150:
2151: case MRL :
2152: {
2153: if (type != 'O')
2154: {
2155: incrementation_atomique(s_objet);
2156: return(s_objet);
2157: }
2158:
2159: if ((s_nouvel_objet = allocation(s_etat_processus, MRL)) == NULL)
2160: {
2161: return(NULL);
2162: }
2163:
2164: (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau =
2165: (void **) ((real8 **) malloc(
2166: ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
2167: * sizeof(real8 *)));
2168:
2169: if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
2170: == NULL)
2171: {
2172: free((*s_nouvel_objet).objet);
2173: free(s_nouvel_objet);
2174: return(NULL);
2175: }
2176:
2177: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
2178: (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
2179: (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
2180: (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
2181: (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
2182: (*((struct_matrice *) ((*s_objet).objet))).type;
2183:
2184: for(i = 0; i < (*((struct_matrice *)
2185: ((*s_objet).objet))).nombre_lignes; i++)
2186: {
2187: if ((((real8 **) ((*((struct_matrice *)
2188: ((*s_nouvel_objet).objet))).tableau))[i] =
2189: (void *) ((real8 *) malloc(
2190: ((*((struct_matrice *) ((*s_objet).objet)))
2191: .nombre_colonnes) * sizeof(real8)))) == NULL)
2192: {
2193: for(j = 0; j < i; j++)
2194: {
2195: free(((real8 **) ((*((struct_matrice *)
2196: ((*s_nouvel_objet).objet))).tableau))[j]);
2197: }
2198:
2199: free((*s_nouvel_objet).objet);
2200: free(s_nouvel_objet);
2201: return(NULL);
2202: }
2203:
2204: for(j = 0; j < (*((struct_matrice *)
2205: ((*s_objet).objet))).nombre_colonnes; j++)
2206: {
2207: ((real8 **) ((*((struct_matrice *)
2208: ((*s_nouvel_objet).objet))).tableau))[i][j] =
2209: ((real8 **) ((*((struct_matrice *)
2210: ((*s_objet).objet))).tableau))[i][j];
2211: }
2212: }
2213:
2214: break;
2215: }
2216:
2217: case MTX :
2218: {
2219: if (type != 'O')
2220: {
2221: incrementation_atomique(s_objet);
2222: return(s_objet);
2223: }
2224:
2225: if ((s_nouvel_objet = allocation(s_etat_processus, MTX)) == NULL)
2226: {
2227: return(NULL);
2228: }
2229:
2230: (*((struct_mutex *) ((*s_nouvel_objet).objet))).mutex =
2231: (*((struct_mutex *) ((*s_objet).objet))).mutex;
2232: break;
2233: }
2234:
2235: case NOM :
2236: {
2237: if (type != 'O')
2238: {
2239: incrementation_atomique(s_objet);
2240: return(s_objet);
2241: }
2242:
2243: if ((s_nouvel_objet = allocation(s_etat_processus, NOM)) == NULL)
2244: {
2245: return(NULL);
2246: }
2247:
2248: (*((struct_nom *) (*s_nouvel_objet).objet)).nom = malloc((
2249: strlen((*((struct_nom *) (*s_objet).objet)).nom) + 1) *
2250: sizeof(unsigned char));
2251:
2252: if ((*((struct_nom *) (*s_nouvel_objet).objet)).nom == NULL)
2253: {
2254: free((*s_nouvel_objet).objet);
2255: free(s_nouvel_objet);
2256: return(NULL);
2257: }
2258:
2259: strcpy((*((struct_nom *) (*s_nouvel_objet).objet)).nom,
2260: (*((struct_nom *) (*s_objet).objet)).nom);
2261: (*((struct_nom *) (*s_nouvel_objet).objet)).symbole =
2262: (*((struct_nom *) (*s_objet).objet)).symbole;
2263: break;
2264: }
2265:
2266: case NON :
2267: {
2268: if (type != 'O')
2269: {
2270: incrementation_atomique(s_objet);
2271: return(s_objet);
2272: }
2273:
2274: if ((s_nouvel_objet = allocation(s_etat_processus, NON)) == NULL)
2275: {
2276: return(NULL);
2277: }
2278:
2279: (*s_nouvel_objet).objet = NULL;
2280: break;
2281: }
2282:
2283: case PRC :
2284: {
2285: if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
1.40 bertrand 2286: (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1 bertrand 2287: {
2288: return(NULL);
2289: }
2290:
2291: (*(*((struct_processus_fils *) (*s_objet).objet)).thread)
2292: .nombre_references++;
2293:
2294: if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
1.40 bertrand 2295: (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1 bertrand 2296: {
2297: return(NULL);
2298: }
2299:
2300: if (type != 'O')
2301: {
2302: incrementation_atomique(s_objet);
2303: return(s_objet);
2304: }
2305:
2306: if ((s_nouvel_objet = allocation(s_etat_processus, PRC)) == NULL)
2307: {
2308: return(NULL);
2309: }
2310:
2311: (*((struct_processus_fils *) (*s_nouvel_objet).objet)) =
2312: (*((struct_processus_fils *) (*s_objet).objet));
2313: break;
2314: }
2315:
2316: case REL :
2317: {
2318: if (type != 'O')
2319: {
2320: incrementation_atomique(s_objet);
2321: return(s_objet);
2322: }
2323:
2324: if ((s_nouvel_objet = allocation(s_etat_processus, REL)) == NULL)
2325: {
2326: return(NULL);
2327: }
2328:
2329: (*((real8 *) ((*s_nouvel_objet).objet))) =
2330: (*((real8 *) ((*s_objet).objet)));
2331: break;
2332: }
2333:
2334: case SCK :
2335: {
2336: if (type == 'P')
2337: {
2338: incrementation_atomique(s_objet);
1.17 bertrand 2339:
1.18 bertrand 2340: if (((*((struct_socket *) ((*s_objet).objet)))
2341: .format = copie_objet(s_etat_processus,
2342: (*((struct_socket *) ((*s_objet).objet))).format, 'P'))
2343: == NULL)
1.17 bertrand 2344: {
2345: return(NULL);
2346: }
2347:
1.1 bertrand 2348: return(s_objet);
2349: }
2350:
2351: if ((s_nouvel_objet = allocation(s_etat_processus, SCK)) == NULL)
2352: {
2353: return(NULL);
2354: }
2355:
2356: (*((struct_socket *) ((*s_nouvel_objet).objet))).socket =
2357: (*((struct_socket *) ((*s_objet).objet))).socket;
2358: (*((struct_socket *) ((*s_nouvel_objet).objet))).domaine =
2359: (*((struct_socket *) ((*s_objet).objet))).domaine;
2360: (*((struct_socket *) ((*s_nouvel_objet).objet))).socket_en_ecoute =
2361: (*((struct_socket *) ((*s_objet).objet))).socket_en_ecoute;
2362: (*((struct_socket *) ((*s_nouvel_objet).objet))).socket_connectee =
2363: (*((struct_socket *) ((*s_objet).objet))).socket_connectee;
2364: (*((struct_socket *) ((*s_nouvel_objet).objet))).pid =
2365: (*((struct_socket *) ((*s_objet).objet))).pid;
2366: (*((struct_socket *) ((*s_nouvel_objet).objet))).binaire =
2367: (*((struct_socket *) ((*s_objet).objet))).binaire;
2368: (*((struct_socket *) ((*s_nouvel_objet).objet))).effacement =
2369: (*((struct_socket *) ((*s_objet).objet))).effacement;
2370: (*((struct_socket *) ((*s_nouvel_objet).objet))).protection =
2371: (*((struct_socket *) ((*s_objet).objet))).protection;
2372: (*((struct_socket *) ((*s_nouvel_objet).objet))).localisation =
2373: (*((struct_socket *) ((*s_objet).objet))).localisation;
2374: (*((struct_socket *) ((*s_nouvel_objet).objet))).pid =
2375: (*((struct_socket *) ((*s_objet).objet))).pid;
2376: (*((struct_socket *) ((*s_nouvel_objet).objet))).tid =
2377: (*((struct_socket *) ((*s_objet).objet))).tid;
2378:
2379: if (((*((struct_socket *) ((*s_nouvel_objet).objet))).format =
2380: copie_objet(s_etat_processus, (*((struct_socket *)
2381: ((*s_objet).objet))).format, type)) == NULL)
2382: {
2383: free((*s_nouvel_objet).objet);
2384: free(s_nouvel_objet);
2385: return(NULL);
2386: }
2387:
2388: if (((*((struct_socket *) ((*s_nouvel_objet).objet))).adresse =
2389: (unsigned char *) malloc((strlen((*((struct_socket *)
2390: ((*s_objet).objet))).adresse) + 1) * sizeof(unsigned char)))
2391: == NULL)
2392: {
2393: liberation(s_etat_processus, (*((struct_fichier *)
2394: (*s_nouvel_objet).objet)).format);
2395: free((*s_nouvel_objet).objet);
2396: free(s_nouvel_objet);
2397: return(NULL);
2398: }
2399:
2400: strcpy((*((struct_socket *) ((*s_nouvel_objet).objet)))
2401: .adresse, (*((struct_socket *) ((*s_objet).objet)))
2402: .adresse);
2403:
2404: if (((*((struct_socket *) ((*s_nouvel_objet).objet)))
2405: .adresse_distante = malloc((strlen((*((struct_socket *)
2406: ((*s_objet).objet))).adresse_distante) + 1) *
2407: sizeof(unsigned char))) == NULL)
2408: {
2409: liberation(s_etat_processus, (*((struct_fichier *)
2410: (*s_nouvel_objet).objet)).format);
2411: free((*s_nouvel_objet).objet);
2412: free(s_nouvel_objet);
2413: return(NULL);
2414: }
2415:
2416: strcpy((*((struct_socket *) ((*s_nouvel_objet).objet)))
2417: .adresse_distante, (*((struct_socket *) ((*s_objet).objet)))
2418: .adresse_distante);
2419:
2420: strcpy((*((struct_socket *) ((*s_nouvel_objet).objet))).type,
2421: (*((struct_socket *) ((*s_objet).objet))).type);
2422: break;
2423: }
2424:
2425: case SLB :
2426: {
2427: if (type != 'O')
2428: {
2429: incrementation_atomique(s_objet);
2430: return(s_objet);
2431: }
2432:
2433: if ((s_nouvel_objet = allocation(s_etat_processus, SLB)) == NULL)
2434: {
2435: return(NULL);
2436: }
2437:
2438: if (((*((struct_bibliotheque *) ((*s_nouvel_objet).objet))).nom =
2439: (unsigned char *) malloc((strlen((*((struct_bibliotheque *)
2440: ((*s_objet).objet))).nom) + 1) * sizeof(unsigned char)))
2441: == NULL)
2442: {
2443: free((*s_nouvel_objet).objet);
2444: free(s_nouvel_objet);
2445: return(NULL);
2446: }
2447:
2448: strcpy((*((struct_bibliotheque *) ((*s_nouvel_objet).objet))).nom,
2449: (*((struct_bibliotheque *) ((*s_objet).objet))).nom);
2450:
2451: /*
2452: * C'est objet est non modifiable et est un pointeur
2453: * sur un objet système. Seul la référence est copiée.
2454: */
2455:
2456: (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).descripteur =
2457: (*((struct_bibliotheque *) (*s_objet).objet)).descripteur;
2458: (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).pid =
2459: (*((struct_bibliotheque *) (*s_objet).objet)).pid;
2460: (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).tid =
2461: (*((struct_bibliotheque *) (*s_objet).objet)).tid;
2462: break;
2463: }
2464:
2465: case SPH :
2466: {
2467: if (type != 'O')
2468: {
2469: incrementation_atomique(s_objet);
2470: return(s_objet);
2471: }
2472:
2473: if ((s_nouvel_objet = allocation(s_etat_processus, SPH)) == NULL)
2474: {
2475: return(NULL);
2476: }
2477:
2478: if (((*((struct_semaphore *) (*s_nouvel_objet).objet)).nom =
2479: malloc((strlen((*((struct_semaphore *) (*s_objet).objet))
2480: .nom) + 1) * sizeof(unsigned char))) == NULL)
2481: {
2482: free((*s_nouvel_objet).objet);
2483: free(s_nouvel_objet);
2484: return(NULL);
2485: }
2486:
2487: strcpy((*((struct_semaphore *) (*s_nouvel_objet).objet)).nom,
2488: (*((struct_semaphore *) (*s_objet).objet)).nom);
2489: break;
2490: }
2491:
2492: case SQL :
2493: {
2494: if (type != 'O')
2495: {
2496: incrementation_atomique(s_objet);
2497: return(s_objet);
2498: }
2499:
2500: if ((s_nouvel_objet = allocation(s_etat_processus, SQL)) == NULL)
2501: {
2502: return(NULL);
2503: }
2504:
2505: (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).pid =
2506: (*((struct_connecteur_sql *) (*s_objet).objet)).pid;
2507: (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).tid =
2508: (*((struct_connecteur_sql *) (*s_objet).objet)).tid;
2509: (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).descripteur =
2510: (*((struct_connecteur_sql *) (*s_objet).objet)).descripteur;
2511:
2512: if (((*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).type =
2513: malloc((strlen((*((struct_connecteur_sql *)
2514: (*s_objet).objet)).type) + 1) * sizeof(unsigned char)))
2515: == NULL)
2516: {
2517: free(s_nouvel_objet);
2518: return(NULL);
2519: }
2520:
2521: strcpy((*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).type,
2522: (*((struct_connecteur_sql *) (*s_objet).objet)).type);
2523:
2524: if ((*((struct_connecteur_sql *) (*s_objet).objet)).locale != NULL)
2525: {
2526: if (((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
2527: .locale = malloc((strlen((*((struct_connecteur_sql *)
2528: (*s_objet).objet)).locale) + 1) *
2529: sizeof(unsigned char))) == NULL)
2530: {
2531: free((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
2532: .locale);
2533: free(s_nouvel_objet);
2534: return(NULL);
2535: }
2536:
2537: strcpy((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
2538: .locale, (*((struct_connecteur_sql *)
2539: (*s_objet).objet)).locale);
2540: }
2541: else
2542: {
2543: (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).locale
2544: = NULL;
2545: }
2546:
2547: break;
2548: }
2549:
2550: case TBL :
2551: {
2552: if (type != 'P')
2553: {
2554: if ((s_nouvel_objet = allocation(s_etat_processus, TBL))
2555: == NULL)
2556: {
2557: return(NULL);
2558: }
2559:
2560: (*((struct_tableau *) (*s_nouvel_objet).objet))
2561: .nombre_elements = (*((struct_tableau *)
2562: (*s_objet).objet)).nombre_elements;
2563:
2564: if (((*((struct_tableau *) (*s_nouvel_objet).objet)).elements =
2565: malloc((*((struct_tableau *) (*s_objet).objet))
2566: .nombre_elements * sizeof(struct_objet *))) == NULL)
2567: {
2568: return(NULL);
2569: }
2570:
2571: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
2572: .nombre_elements; i++)
2573: {
2574: if (((*((struct_tableau *) (*s_nouvel_objet).objet))
2575: .elements[i] = copie_objet(s_etat_processus,
2576: (*((struct_tableau *) (*s_objet).objet))
2577: .elements[i], type)) == NULL)
2578: {
2579: for(j = 0; j < i; j++)
2580: {
2581: liberation(s_etat_processus, (*((struct_tableau *)
2582: (*s_nouvel_objet).objet)).elements[j]);
2583: }
2584:
2585: free((*((struct_tableau *) (*s_nouvel_objet).objet))
2586: .elements);
2587: free((*s_nouvel_objet).objet);
2588: free(s_nouvel_objet);
2589:
2590: return(NULL);
2591: }
2592: }
2593: }
2594: else
2595: {
2596: incrementation_atomique(s_objet);
2597:
2598: for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
2599: .nombre_elements; i++)
2600: {
2601: (*((struct_tableau *) (*s_objet).objet)).elements[i] =
2602: copie_objet(s_etat_processus, (*((struct_tableau *)
2603: (*s_objet).objet)).elements[i], 'P');
2604: }
2605:
2606: return(s_objet);
2607: }
2608:
2609: break;
2610: }
2611:
2612: case VIN :
2613: {
2614: if (type != 'O')
2615: {
2616: incrementation_atomique(s_objet);
2617: return(s_objet);
2618: }
2619:
2620: if ((s_nouvel_objet = allocation(s_etat_processus, VIN)) == NULL)
2621: {
2622: return(NULL);
2623: }
2624:
2625: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau =
2626: (void *) ((integer8 *) malloc(
2627: ((*((struct_vecteur *) ((*s_objet).objet))).taille)
2628: * sizeof(integer8)));
2629:
2630: if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
2631: == NULL)
2632: {
2633: free((*s_nouvel_objet).objet);
2634: free(s_nouvel_objet);
2635: return(NULL);
2636: }
2637:
2638: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
2639: (*((struct_vecteur *) ((*s_objet).objet))).taille;
2640: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
2641: (*((struct_vecteur *) ((*s_objet).objet))).type;
2642:
2643: for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
2644: i++)
2645: {
2646: ((integer8 *) ((*((struct_vecteur *)
2647: ((*s_nouvel_objet).objet))).tableau))[i] =
2648: ((integer8 *) ((*((struct_vecteur *)
2649: ((*s_objet).objet))).tableau))[i];
2650: }
2651:
2652: break;
2653: }
2654:
2655: case VCX :
2656: {
2657: if (type != 'O')
2658: {
2659: incrementation_atomique(s_objet);
2660: return(s_objet);
2661: }
2662:
2663: if ((s_nouvel_objet = allocation(s_etat_processus, VCX)) == NULL)
2664: {
2665: return(NULL);
2666: }
2667:
2668: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau =
2669: (void *) ((struct_complexe16 *) malloc(
2670: ((*((struct_vecteur *) ((*s_objet).objet))).taille)
2671: * sizeof(struct_complexe16)));
2672:
2673: if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
2674: == NULL)
2675: {
2676: free((*s_nouvel_objet).objet);
2677: free(s_nouvel_objet);
2678: return(NULL);
2679: }
2680:
2681: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
2682: (*((struct_vecteur *) ((*s_objet).objet))).taille;
2683: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
2684: (*((struct_vecteur *) ((*s_objet).objet))).type;
2685:
2686: for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
2687: i++)
2688: {
2689: ((struct_complexe16 *) ((*((struct_vecteur *)
2690: ((*s_nouvel_objet).objet))).tableau))[i] =
2691: ((struct_complexe16 *) ((*((struct_vecteur *)
2692: ((*s_objet).objet))).tableau))[i];
2693: }
2694:
2695: break;
2696: }
2697:
2698: case VRL :
2699: {
2700: if (type != 'O')
2701: {
2702: incrementation_atomique(s_objet);
2703: return(s_objet);
2704: }
2705:
2706: if ((s_nouvel_objet = allocation(s_etat_processus, VRL)) == NULL)
2707: {
2708: return(NULL);
2709: }
2710:
2711: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau =
2712: (void *) ((real8 *) malloc(
2713: ((*((struct_vecteur *) ((*s_objet).objet))).taille)
2714: * sizeof(real8)));
2715:
2716: if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
2717: == NULL)
2718: {
2719: free((*s_nouvel_objet).objet);
2720: free(s_nouvel_objet);
2721: return(NULL);
2722: }
2723:
2724: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
2725: (*((struct_vecteur *) ((*s_objet).objet))).taille;
2726: (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
2727: (*((struct_vecteur *) ((*s_objet).objet))).type;
2728:
2729: for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
2730: i++)
2731: {
2732: ((real8 *) ((*((struct_vecteur *)
2733: ((*s_nouvel_objet).objet))).tableau))[i] =
2734: ((real8 *) ((*((struct_vecteur *)
2735: ((*s_objet).objet))).tableau))[i];
2736: }
2737:
2738: break;
2739: }
2740:
2741: default :
2742: {
2743: return(NULL);
2744: }
2745: }
2746:
2747: return(s_nouvel_objet);
2748:
2749: #undef return
2750: }
2751:
2752:
2753: /*
2754: ================================================================================
2755: Routine de copie d'une structure de description d'un processus
2756: ================================================================================
2757: Entrées : pointeur sur la structure de description d'un processus
2758: --------------------------------------------------------------------------------
2759: Sorties : structure identique (tous les objets sont copiés)
2760: --------------------------------------------------------------------------------
2761: Effets de bord : néant
2762: ================================================================================
2763: */
2764:
2765: struct_processus *
2766: copie_etat_processus(struct_processus *s_etat_processus)
2767: {
2768: pthread_mutexattr_t attributs_mutex;
2769:
2770: struct_liste_chainee *l_element_lecture;
2771: struct_liste_chainee *l_element_precedent;
2772: struct_liste_chainee *l_element_suivant;
2773:
2774: struct_processus *s_nouvel_etat_processus;
2775:
2776: unsigned long i;
2777:
2778: if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
2779: {
2780: (*s_etat_processus).erreur_systeme = d_es_processus;
2781: return(NULL);
2782: }
2783:
2784: if ((s_nouvel_etat_processus = malloc(sizeof(struct_processus))) == NULL)
2785: {
2786: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2787: return(NULL);
2788: }
2789:
2790: (*s_nouvel_etat_processus) = (*s_etat_processus);
2791:
2792: // On réinitialise l'allocateur.
2793:
2794: initialisation_allocateur(s_nouvel_etat_processus);
2795:
2796: /*
2797: * (*s_etat_processus).definition_chainee,
2798: * (*s_etat_processus).nom_fichier_source,
2799: * (*s_etat_processus).nom_fichier_historique et
2800: * (*s_etat_processus).chemin_fichier_temporaires
2801: * n'ont aucune raison de changer.
2802: */
2803:
1.67 bertrand 2804: pthread_mutexattr_init(&attributs_mutex);
2805: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
1.68 ! bertrand 2806: sem_init(&((*s_nouvel_etat_processus).semaphore_fork), 0, 0);
1.1 bertrand 2807:
1.60 bertrand 2808: initialisation_contexte_cas(s_etat_processus);
2809:
1.1 bertrand 2810: (*s_nouvel_etat_processus).var_volatile_processus_pere = 0;
1.39 bertrand 2811: (*s_nouvel_etat_processus).var_volatile_processus_racine = 0;
1.1 bertrand 2812: (*s_nouvel_etat_processus).fichiers_graphiques = NULL;
2813: (*s_nouvel_etat_processus).entree_standard = NULL;
2814: (*s_nouvel_etat_processus).s_marques = NULL;
2815: (*s_nouvel_etat_processus).requete_nouveau_plan = d_vrai;
2816: (*s_nouvel_etat_processus).mise_a_jour_trace_requise = d_faux;
2817: (*s_nouvel_etat_processus).nom_fichier_impression = NULL;
2818: (*s_nouvel_etat_processus).expression_courante = NULL;
2819: (*s_nouvel_etat_processus).objet_courant = NULL;
2820: (*s_nouvel_etat_processus).processus_detache = d_faux;
1.3 bertrand 2821: (*s_nouvel_etat_processus).evaluation_forcee = 'N';
1.1 bertrand 2822:
1.64 bertrand 2823: (*s_nouvel_etat_processus).compteur_violation_d_acces = 0;
2824:
1.1 bertrand 2825: (*s_nouvel_etat_processus).nombre_objets_envoyes_non_lus = 0;
2826: (*s_nouvel_etat_processus).nombre_objets_injectes = 0;
2827: (*s_nouvel_etat_processus).presence_fusible = d_faux;
2828: (*s_nouvel_etat_processus).thread_fusible = 0;
2829: (*s_nouvel_etat_processus).niveau_initial =
2830: (*s_etat_processus).niveau_courant;
2831: (*s_nouvel_etat_processus).presence_pipes = d_faux;
2832: (*s_nouvel_etat_processus).debug_programme = d_faux;
2833: (*s_nouvel_etat_processus).s_fichiers = NULL;
2834: (*s_nouvel_etat_processus).s_connecteurs_sql = NULL;
2835:
2836: // On réinitialise toutes les interruptions.
2837:
2838: (*s_nouvel_etat_processus).traitement_interruption = 'N';
2839: (*s_nouvel_etat_processus).traitement_interruptible = 'Y';
2840: (*s_nouvel_etat_processus).nombre_interruptions_en_queue = 0;
2841: (*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0;
2842:
1.14 bertrand 2843: (*s_nouvel_etat_processus).at_exit = NULL;
1.32 bertrand 2844: (*s_nouvel_etat_processus).at_poke = NULL;
2845: (*s_nouvel_etat_processus).traitement_at_poke = 'N';
1.13 bertrand 2846:
1.1 bertrand 2847: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2848: {
2849: (*s_nouvel_etat_processus).corps_interruptions[i] = NULL;
2850: (*s_nouvel_etat_processus).masque_interruptions[i] = 'N';
2851: (*s_nouvel_etat_processus).queue_interruptions[i] = 0;
2852: (*s_nouvel_etat_processus).pile_origine_interruptions[i] = NULL;
2853: }
2854:
2855: if ((*s_nouvel_etat_processus).generateur_aleatoire != NULL)
2856: {
1.35 bertrand 2857: if (((*s_nouvel_etat_processus).generateur_aleatoire =
2858: gsl_rng_clone((*s_etat_processus).generateur_aleatoire))
2859: == NULL)
2860: {
2861: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2862: return(NULL);
2863: }
2864:
2865: gsl_rng_set((*s_nouvel_etat_processus).generateur_aleatoire,
2866: gsl_rng_get((*s_etat_processus).generateur_aleatoire));
1.1 bertrand 2867: }
2868:
2869: // Copie de la localisation
2870:
2871: if (((*s_nouvel_etat_processus).localisation = malloc((strlen(
2872: (*s_etat_processus).localisation) + 1) * sizeof(unsigned char)))
2873: == NULL)
2874: {
2875: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2876: return(NULL);
2877: }
2878:
2879: strcpy((*s_nouvel_etat_processus).localisation,
2880: (*s_etat_processus).localisation);
2881:
2882: if ((*s_etat_processus).indep != NULL)
2883: {
2884: if (((*s_nouvel_etat_processus).indep = copie_objet(s_etat_processus,
2885: (*s_etat_processus).indep, 'P')) == NULL)
2886: {
2887: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2888: {
2889: (*s_etat_processus).erreur_systeme = d_es_processus;
2890: return(NULL);
2891: }
2892:
2893: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2894: return(NULL);
2895: }
2896: }
2897: else
2898: {
2899: (*s_nouvel_etat_processus).indep = NULL;
2900: }
2901:
2902: if ((*s_etat_processus).depend != NULL)
2903: {
2904: if (((*s_nouvel_etat_processus).depend = copie_objet(s_etat_processus,
2905: (*s_etat_processus).depend, 'P')) == NULL)
2906: {
2907: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2908: {
2909: (*s_etat_processus).erreur_systeme = d_es_processus;
2910: return(NULL);
2911: }
2912:
2913: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2914: return(NULL);
2915: }
2916: }
2917: else
2918: {
2919: (*s_nouvel_etat_processus).depend = NULL;
2920: }
2921:
2922: if ((*s_etat_processus).parametres_courbes_de_niveau != NULL)
2923: {
2924: if (((*s_nouvel_etat_processus).parametres_courbes_de_niveau =
2925: copie_objet(s_etat_processus, (*s_etat_processus)
2926: .parametres_courbes_de_niveau, 'P')) == NULL)
2927: {
2928: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2929: {
2930: (*s_etat_processus).erreur_systeme = d_es_processus;
2931: return(NULL);
2932: }
2933:
2934: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2935: return(NULL);
2936: }
2937: }
2938: else
2939: {
2940: (*s_nouvel_etat_processus).parametres_courbes_de_niveau = NULL;
2941: }
2942:
2943: (*s_nouvel_etat_processus).instruction_derniere_erreur = NULL;
2944:
2945: if (((*s_etat_processus).instruction_courante != NULL) &&
2946: (*s_etat_processus).evaluation_expression_compilee == 'N')
2947: {
2948: if (((*s_nouvel_etat_processus).instruction_courante = malloc((strlen(
2949: (*s_etat_processus).instruction_courante) + 1) *
2950: sizeof(unsigned char))) == NULL)
2951: {
2952: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2953: {
2954: (*s_etat_processus).erreur_systeme = d_es_processus;
2955: return(NULL);
2956: }
2957:
2958: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2959: return(NULL);
2960: }
2961:
2962: strcpy((*s_nouvel_etat_processus).instruction_courante,
2963: (*s_etat_processus).instruction_courante);
2964: }
2965: else
2966: {
2967: (*s_nouvel_etat_processus).instruction_courante = NULL;
2968: }
2969:
2970: if ((*s_etat_processus).label_x != NULL)
2971: {
2972: if (((*s_nouvel_etat_processus).label_x = malloc((strlen(
2973: (*s_etat_processus).label_x) + 1) *
2974: sizeof(unsigned char))) == NULL)
2975: {
2976: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2977: {
2978: (*s_etat_processus).erreur_systeme = d_es_processus;
2979: return(NULL);
2980: }
2981:
2982: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2983: return(NULL);
2984: }
2985:
2986: strcpy((*s_nouvel_etat_processus).label_x,
2987: (*s_etat_processus).label_x);
2988: }
2989: else
2990: {
2991: (*s_nouvel_etat_processus).label_x = NULL;
2992: }
2993:
2994: if ((*s_etat_processus).label_y != NULL)
2995: {
2996: if (((*s_nouvel_etat_processus).label_y = malloc((strlen(
2997: (*s_etat_processus).label_y) + 1) *
2998: sizeof(unsigned char))) == NULL)
2999: {
3000: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3001: {
3002: (*s_etat_processus).erreur_systeme = d_es_processus;
3003: return(NULL);
3004: }
3005:
3006: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3007: return(NULL);
3008: }
3009:
3010: strcpy((*s_nouvel_etat_processus).label_y,
3011: (*s_etat_processus).label_y);
3012: }
3013: else
3014: {
3015: (*s_nouvel_etat_processus).label_y = NULL;
3016: }
3017:
3018: if ((*s_etat_processus).label_z != NULL)
3019: {
3020: if (((*s_nouvel_etat_processus).label_z = malloc((strlen(
3021: (*s_etat_processus).label_z) + 1) *
3022: sizeof(unsigned char))) == NULL)
3023: {
3024: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3025: {
3026: (*s_etat_processus).erreur_systeme = d_es_processus;
3027: return(NULL);
3028: }
3029:
3030: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3031: return(NULL);
3032: }
3033:
3034: strcpy((*s_nouvel_etat_processus).label_z,
3035: (*s_etat_processus).label_z);
3036: }
3037: else
3038: {
3039: (*s_nouvel_etat_processus).label_z = NULL;
3040: }
3041:
3042: if ((*s_etat_processus).titre != NULL)
3043: {
3044: if (((*s_nouvel_etat_processus).titre = malloc((strlen(
3045: (*s_etat_processus).titre) + 1) *
3046: sizeof(unsigned char))) == NULL)
3047: {
3048: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3049: {
3050: (*s_etat_processus).erreur_systeme = d_es_processus;
3051: return(NULL);
3052: }
3053:
3054: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3055: return(NULL);
3056: }
3057:
3058: strcpy((*s_nouvel_etat_processus).titre,
3059: (*s_etat_processus).titre);
3060: }
3061: else
3062: {
3063: (*s_nouvel_etat_processus).titre = NULL;
3064: }
3065:
3066: if ((*s_etat_processus).legende != NULL)
3067: {
3068: if (((*s_nouvel_etat_processus).legende = malloc((strlen(
3069: (*s_etat_processus).legende) + 1) *
3070: sizeof(unsigned char))) == NULL)
3071: {
3072: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3073: {
3074: (*s_etat_processus).erreur_systeme = d_es_processus;
3075: return(NULL);
3076: }
3077:
3078: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3079: return(NULL);
3080: }
3081:
3082: strcpy((*s_nouvel_etat_processus).legende,
3083: (*s_etat_processus).legende);
3084: }
3085: else
3086: {
3087: (*s_nouvel_etat_processus).legende = NULL;
3088: }
3089:
3090: /*
3091: * Copie de la table des variables
3092: */
3093:
1.51 bertrand 3094: copie_arbre_variables(s_etat_processus, s_nouvel_etat_processus);
3095:
3096: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
1.1 bertrand 3097: {
3098: return(NULL);
3099: }
3100:
3101: /*
3102: * Copie de la table des variables statiques
3103: */
3104:
3105: if (((*s_nouvel_etat_processus).s_liste_variables_statiques =
3106: malloc((*s_etat_processus).nombre_variables_statiques_allouees *
3107: sizeof(struct_variable_statique))) == NULL)
3108: {
3109: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3110: {
3111: (*s_etat_processus).erreur_systeme = d_es_processus;
3112: return(NULL);
3113: }
3114:
3115: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3116: return(NULL);
3117: }
3118:
3119: for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++)
3120: {
3121: if (((*s_nouvel_etat_processus).s_liste_variables_statiques[i].nom =
3122: malloc((strlen((*s_etat_processus).s_liste_variables_statiques
3123: [i].nom) + 1) * sizeof(unsigned char))) == NULL)
3124: {
3125: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3126: {
3127: (*s_etat_processus).erreur_systeme = d_es_processus;
3128: return(NULL);
3129: }
3130:
3131: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3132: return(NULL);
3133: }
3134:
3135: strcpy((*s_nouvel_etat_processus).s_liste_variables_statiques[i].nom,
3136: (*s_etat_processus).s_liste_variables_statiques[i].nom);
3137:
3138: (*s_nouvel_etat_processus).s_liste_variables_statiques[i].origine =
3139: (*s_etat_processus).s_liste_variables_statiques[i].origine;
3140: (*s_nouvel_etat_processus).s_liste_variables_statiques[i].niveau =
3141: (*s_etat_processus).s_liste_variables_statiques[i].niveau;
3142: (*s_nouvel_etat_processus).s_liste_variables_statiques[i]
3143: .variable_statique = (*s_etat_processus)
3144: .s_liste_variables_statiques[i].variable_statique;
3145:
3146: if (((*s_nouvel_etat_processus).s_liste_variables_statiques[i].objet =
3147: copie_objet(s_etat_processus, (*s_etat_processus)
3148: .s_liste_variables_statiques[i].objet, 'P')) == NULL)
3149: {
3150: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3151: {
3152: (*s_etat_processus).erreur_systeme = d_es_processus;
3153: return(NULL);
3154: }
3155:
3156: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3157: return(NULL);
3158: }
3159: }
3160:
3161: /*
3162: * Copie de la pile opérationnelle
3163: */
3164:
3165: (*s_nouvel_etat_processus).l_base_pile = NULL;
3166: l_element_lecture = (*s_etat_processus).l_base_pile;
3167: l_element_precedent = NULL;
3168:
3169: while(l_element_lecture != NULL)
3170: {
3171: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3172: {
3173: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3174: {
3175: (*s_etat_processus).erreur_systeme = d_es_processus;
3176: return(NULL);
3177: }
3178:
3179: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3180: return(NULL);
3181: }
3182:
3183: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3184: (*l_element_lecture).donnee, 'P')) == NULL)
3185: {
3186: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3187: {
3188: (*s_etat_processus).erreur_systeme = d_es_processus;
3189: return(NULL);
3190: }
3191:
3192: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3193: return(NULL);
3194: }
3195:
3196: (*l_element_suivant).suivant = NULL;
3197:
3198: if ((*s_nouvel_etat_processus).l_base_pile == NULL)
3199: {
3200: (*s_nouvel_etat_processus).l_base_pile = l_element_suivant;
3201: }
3202: else
3203: {
3204: (*l_element_precedent).suivant = l_element_suivant;
3205: }
3206:
3207: l_element_precedent = l_element_suivant;
3208: l_element_lecture = (*l_element_lecture).suivant;
3209: }
3210:
3211: /*
3212: * Copie de la pile système
3213: */
3214:
3215: (*s_nouvel_etat_processus).l_base_pile_systeme = NULL;
3216: (*s_nouvel_etat_processus).hauteur_pile_systeme = 0;
3217:
3218: empilement_pile_systeme(s_nouvel_etat_processus);
3219:
3220: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
3221: {
3222: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3223: {
3224: (*s_etat_processus).erreur_systeme = d_es_processus;
3225: return(NULL);
3226: }
3227:
3228: (*s_etat_processus).erreur_systeme =
3229: (*s_nouvel_etat_processus).erreur_systeme;
3230: return(NULL);
3231: }
3232:
3233: (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
3234:
3235: /*
3236: * On empile deux valeurs retour_definition pour pouvoir récupérer
3237: * les variables dans le cas d'un programme compilé.
3238: */
3239:
3240: empilement_pile_systeme(s_nouvel_etat_processus);
3241:
3242: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
3243: {
3244: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3245: {
3246: (*s_etat_processus).erreur_systeme = d_es_processus;
3247: return(NULL);
3248: }
3249:
3250: (*s_etat_processus).erreur_systeme =
3251: (*s_nouvel_etat_processus).erreur_systeme;
3252: return(NULL);
3253: }
3254:
3255: (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
3256:
3257: /*
3258: * Destruction de la pile last pour le thread en cours.
3259: */
3260:
3261: (*s_nouvel_etat_processus).l_base_pile_last = NULL;
3262: (*s_nouvel_etat_processus).l_base_pile_processus = NULL;
3263:
3264: /*
3265: * Copie des différents contextes
3266: */
3267:
1.66 bertrand 3268: (*s_nouvel_etat_processus).pointeur_signal_lecture = d_faux;
3269: (*s_nouvel_etat_processus).pointeur_signal_ecriture = d_faux;
3270:
1.1 bertrand 3271: (*s_nouvel_etat_processus).l_base_pile_contextes = NULL;
3272: l_element_lecture = (*s_etat_processus).l_base_pile_contextes;
3273:
3274: while(l_element_lecture != NULL)
3275: {
3276: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3277: {
3278: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3279: {
3280: (*s_etat_processus).erreur_systeme = d_es_processus;
3281: return(NULL);
3282: }
3283:
3284: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3285: return(NULL);
3286: }
3287:
3288: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3289: (*l_element_lecture).donnee, 'P')) == NULL)
3290: {
3291: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3292: {
3293: (*s_etat_processus).erreur_systeme = d_es_processus;
3294: return(NULL);
3295: }
3296:
3297: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3298: return(NULL);
3299: }
3300:
3301: (*l_element_suivant).suivant = NULL;
3302:
3303: if ((*s_nouvel_etat_processus).l_base_pile_contextes == NULL)
3304: {
3305: (*s_nouvel_etat_processus).l_base_pile_contextes =
3306: l_element_suivant;
3307: }
3308: else
3309: {
3310: (*l_element_precedent).suivant = l_element_suivant;
3311: }
3312:
3313: l_element_precedent = l_element_suivant;
3314: l_element_lecture = (*l_element_lecture).suivant;
3315: }
3316:
3317: (*s_nouvel_etat_processus).l_base_pile_taille_contextes = NULL;
3318: l_element_lecture = (*s_etat_processus).l_base_pile_taille_contextes;
3319:
3320: while(l_element_lecture != NULL)
3321: {
3322: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3323: {
3324: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3325: {
3326: (*s_etat_processus).erreur_systeme = d_es_processus;
3327: return(NULL);
3328: }
3329:
3330: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3331: return(NULL);
3332: }
3333:
3334: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3335: (*l_element_lecture).donnee, 'P')) == NULL)
3336: {
3337: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3338: {
3339: (*s_etat_processus).erreur_systeme = d_es_processus;
3340: return(NULL);
3341: }
3342:
3343: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3344: return(NULL);
3345: }
3346:
3347: (*l_element_suivant).suivant = NULL;
3348:
3349: if ((*s_nouvel_etat_processus).l_base_pile_taille_contextes == NULL)
3350: {
3351: (*s_nouvel_etat_processus).l_base_pile_taille_contextes =
3352: l_element_suivant;
3353: }
3354: else
3355: {
3356: (*l_element_precedent).suivant = l_element_suivant;
3357: }
3358:
3359: l_element_precedent = l_element_suivant;
3360: l_element_lecture = (*l_element_lecture).suivant;
3361: }
3362:
3363: /*
3364: * Copies des piles s_sockets, s_bibliotheques et
3365: * s_instructions_externes.
3366: */
3367:
3368: (*s_nouvel_etat_processus).s_sockets = NULL;
3369: l_element_lecture = (*s_etat_processus).s_sockets;
3370:
3371: while(l_element_lecture != NULL)
3372: {
3373: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3374: {
3375: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3376: {
3377: (*s_etat_processus).erreur_systeme = d_es_processus;
3378: return(NULL);
3379: }
3380:
3381: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3382: return(NULL);
3383: }
3384:
3385: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3386: (*l_element_lecture).donnee, 'P')) == NULL)
3387: {
3388: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3389: {
3390: (*s_etat_processus).erreur_systeme = d_es_processus;
3391: return(NULL);
3392: }
3393:
3394: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3395: return(NULL);
3396: }
3397:
3398: (*l_element_suivant).suivant = NULL;
3399:
3400: if ((*s_nouvel_etat_processus).s_sockets == NULL)
3401: {
3402: (*s_nouvel_etat_processus).s_sockets = l_element_suivant;
3403: }
3404: else
3405: {
3406: (*l_element_precedent).suivant = l_element_suivant;
3407: }
3408:
3409: l_element_precedent = l_element_suivant;
3410: l_element_lecture = (*l_element_lecture).suivant;
3411: }
3412:
3413: (*s_nouvel_etat_processus).s_bibliotheques = NULL;
3414: l_element_precedent = NULL;
3415: l_element_lecture = (*s_etat_processus).s_bibliotheques;
3416:
3417: while(l_element_lecture != NULL)
3418: {
3419: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3420: {
3421: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3422: {
3423: (*s_etat_processus).erreur_systeme = d_es_processus;
3424: return(NULL);
3425: }
3426:
3427: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3428: return(NULL);
3429: }
3430:
3431: if (((*l_element_suivant).donnee = malloc(sizeof(struct_bibliotheque)))
3432: == NULL)
3433: {
3434: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3435: return(NULL);
3436: }
3437:
3438: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).descripteur
3439: = (*((struct_bibliotheque *) (*l_element_lecture).donnee))
3440: .descripteur;
3441: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).pid
3442: = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).pid;
3443: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).tid
3444: = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).tid;
3445:
3446: if (((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom =
3447: malloc((strlen((*((struct_bibliotheque *) (*l_element_lecture)
3448: .donnee)).nom) + 1) * sizeof(unsigned char))) == NULL)
3449: {
3450: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3451: {
3452: (*s_etat_processus).erreur_systeme = d_es_processus;
3453: return(NULL);
3454: }
3455:
3456: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3457: return(NULL);
3458: }
3459:
3460: strcpy((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom,
3461: (*((struct_bibliotheque *) (*l_element_lecture).donnee)).nom);
3462:
3463: (*l_element_suivant).suivant = NULL;
3464:
3465: if ((*s_nouvel_etat_processus).s_bibliotheques == NULL)
3466: {
3467: (*s_nouvel_etat_processus).s_bibliotheques = l_element_suivant;
3468: }
3469: else
3470: {
3471: (*l_element_precedent).suivant = l_element_suivant;
3472: }
3473:
3474: l_element_precedent = l_element_suivant;
3475: l_element_lecture = (*l_element_lecture).suivant;
3476: }
3477:
3478: if ((*s_etat_processus).nombre_instructions_externes != 0)
3479: {
3480: if (((*s_nouvel_etat_processus).s_instructions_externes =
3481: malloc((*s_etat_processus).nombre_instructions_externes *
3482: sizeof(struct_instruction_externe))) == NULL)
3483: {
3484: (*s_etat_processus).erreur_systeme = d_es_processus;
3485: return(NULL);
3486: }
3487:
3488: for(i = 0; i < (*s_etat_processus).nombre_instructions_externes; i++)
3489: {
3490: if (((*s_nouvel_etat_processus).s_instructions_externes[i].nom =
3491: malloc((strlen((*s_etat_processus).s_instructions_externes
3492: [i].nom) + 1) * sizeof(unsigned char))) == NULL)
3493: {
3494: (*s_etat_processus).erreur_systeme = d_es_processus;
3495: return(NULL);
3496: }
3497:
3498: strcpy((*s_nouvel_etat_processus).s_instructions_externes[i].nom,
3499: (*s_etat_processus).s_instructions_externes[i].nom);
3500:
3501: if (((*s_nouvel_etat_processus).s_instructions_externes[i]
3502: .nom_bibliotheque = malloc((strlen((*s_etat_processus)
3503: .s_instructions_externes[i].nom_bibliotheque) + 1) *
3504: sizeof(unsigned char))) == NULL)
3505: {
3506: (*s_etat_processus).erreur_systeme = d_es_processus;
3507: return(NULL);
3508: }
3509:
3510: strcpy((*s_nouvel_etat_processus).s_instructions_externes[i]
3511: .nom_bibliotheque, (*s_etat_processus)
3512: .s_instructions_externes[i].nom_bibliotheque);
3513:
3514: (*s_nouvel_etat_processus).s_instructions_externes[i]
3515: .descripteur_bibliotheque = (*s_etat_processus)
3516: .s_instructions_externes[i].descripteur_bibliotheque;
3517: }
3518: }
3519: else
3520: {
3521: (*s_nouvel_etat_processus).s_instructions_externes = NULL;
3522: }
3523:
3524: pthread_mutexattr_init(&attributs_mutex);
3525: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
3526: pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex);
3527: pthread_mutexattr_destroy(&attributs_mutex);
3528:
1.28 bertrand 3529: pthread_mutexattr_init(&attributs_mutex);
3530: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
3531: pthread_mutex_init(&((*s_nouvel_etat_processus).mutex_allocation),
3532: &attributs_mutex);
3533: pthread_mutexattr_destroy(&attributs_mutex);
3534:
1.1 bertrand 3535: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3536: {
3537: (*s_etat_processus).erreur_systeme = d_es_processus;
3538: return(NULL);
3539: }
3540:
3541: return(s_nouvel_etat_processus);
3542:
3543: #undef return
3544: }
3545:
1.6 bertrand 3546:
3547: /*
3548: ================================================================================
3549: Routines de debug
3550: ================================================================================
3551: entrées :
3552: --------------------------------------------------------------------------------
3553: sorties :
3554: --------------------------------------------------------------------------------
3555: effets de bord : néant
3556: ================================================================================
3557: */
3558:
3559: #ifdef DEBUG_MEMOIRE
3560:
3561: #undef malloc
3562: #undef realloc
3563: #undef free
1.21 bertrand 3564: #undef fork
1.6 bertrand 3565:
3566: #ifdef return
3567: # undef return
3568: #endif
3569:
1.16 bertrand 3570: #ifdef __BACKTRACE
1.21 bertrand 3571: #define PROFONDEUR_PILE 64
1.6 bertrand 3572: #define return(a) { if (a == NULL) \
1.21 bertrand 3573: { BACKTRACE(PROFONDEUR_PILE); \
3574: fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \
1.6 bertrand 3575: return(a); } while(0)
1.16 bertrand 3576: #endif
1.6 bertrand 3577:
1.21 bertrand 3578: #undef fprintf
3579: #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b))
3580: #undef CORE_DUMP
3581:
1.6 bertrand 3582: typedef struct memoire
3583: {
3584: void *pointeur;
3585: unsigned char *fonction;
3586: unsigned char *argument;
3587: unsigned long ligne;
3588: size_t taille;
3589: unsigned long long ordre;
1.16 bertrand 3590: # ifdef __BACKTRACE
3591: void *pile[PROFONDEUR_PILE];
3592: int profondeur;
3593: # endif
1.6 bertrand 3594: struct memoire *suivant;
3595: } struct_memoire;
3596:
3597: static struct_memoire *debug = NULL;
3598: static unsigned long long ordre = 0;
1.21 bertrand 3599: static pthread_mutex_t mutex_allocation;
3600:
3601: void
3602: debug_memoire_initialisation()
3603: {
3604: pthread_mutexattr_t attributs_mutex;
3605:
3606: pthread_mutexattr_init(&attributs_mutex);
3607: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE);
3608: pthread_mutex_init(&mutex_allocation, &attributs_mutex);
3609: pthread_mutexattr_destroy(&attributs_mutex);
1.6 bertrand 3610:
1.21 bertrand 3611: return;
3612: }
1.6 bertrand 3613:
3614: void *
3615: debug_memoire_ajout(size_t taille, const unsigned char *fonction,
3616: unsigned long ligne, const unsigned char *argument)
3617: {
3618: struct_memoire *ancienne_base;
3619:
1.21 bertrand 3620: void *pointeur;
3621:
1.6 bertrand 3622: pthread_mutex_lock(&mutex_allocation);
3623:
3624: ancienne_base = debug;
3625:
3626: if ((debug = malloc(sizeof(struct_memoire))) == NULL)
3627: {
3628: pthread_mutex_unlock(&mutex_allocation);
3629: return(NULL);
3630: }
3631:
3632: if (((*debug).pointeur = malloc(taille)) == NULL)
3633: {
3634: pthread_mutex_unlock(&mutex_allocation);
3635: return(NULL);
3636: }
3637:
3638: (*debug).suivant = ancienne_base;
3639: (*debug).ligne = ligne;
3640: (*debug).taille = taille;
3641: (*debug).ordre = ordre;
1.16 bertrand 3642:
1.21 bertrand 3643: pointeur = (*debug).pointeur;
3644:
1.16 bertrand 3645: # ifdef __BACKTRACE
3646: (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE);
3647: # endif
1.6 bertrand 3648:
3649: if (((*debug).fonction = malloc((strlen(fonction) + 1) *
3650: sizeof(unsigned char))) == NULL)
3651: {
1.18 bertrand 3652: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3653: return(NULL);
3654: }
3655:
3656: if (((*debug).argument = malloc((strlen(argument) + 1) *
3657: sizeof(unsigned char))) == NULL)
3658: {
1.18 bertrand 3659: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3660: return(NULL);
3661: }
3662:
3663: strcpy((*debug).fonction, fonction);
3664: strcpy((*debug).argument, argument);
3665:
1.21 bertrand 3666: memset((*debug).pointeur, 0, (*debug).taille);
3667:
1.18 bertrand 3668: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3669: ordre++;
3670:
1.21 bertrand 3671: return(pointeur);
1.6 bertrand 3672: }
3673:
3674: void *
3675: debug_memoire_modification(void *pointeur, size_t taille,
3676: const unsigned char *fonction, unsigned long ligne,
3677: const unsigned char *argument)
3678: {
3679: struct_memoire *element_courant;
3680:
3681: if (pointeur != NULL)
3682: {
3683: if (taille == 0)
3684: {
1.21 bertrand 3685: // Revient à free(). Il n'y a pas de parenthèses car on ne veut
3686: // pas utiliser la macro return().
3687:
1.6 bertrand 3688: debug_memoire_retrait(pointeur);
1.21 bertrand 3689: return NULL ;
1.6 bertrand 3690: }
3691: else
3692: {
3693: // Réallocation réelle
3694:
3695: pthread_mutex_lock(&mutex_allocation);
3696:
3697: element_courant = debug;
3698:
3699: while(element_courant != NULL)
3700: {
3701: if ((*element_courant).pointeur == pointeur)
3702: {
3703: break;
3704: }
3705:
3706: element_courant = (*element_courant).suivant;
3707: }
3708:
3709: if (element_courant == NULL)
3710: {
3711: pthread_mutex_unlock(&mutex_allocation);
1.21 bertrand 3712:
1.26 bertrand 3713: uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n",
1.21 bertrand 3714: getpid(), (unsigned long long) pthread_self());
3715: # ifdef __BACKTRACE
3716: BACKTRACE(PROFONDEUR_PILE);
3717: # endif
3718:
3719: return(realloc(pointeur, taille));
1.6 bertrand 3720: }
1.21 bertrand 3721: else
1.6 bertrand 3722: {
1.21 bertrand 3723: if (((*element_courant).pointeur = realloc(pointeur, taille))
3724: == NULL)
3725: {
3726: pthread_mutex_unlock(&mutex_allocation);
3727: return(NULL);
3728: }
1.6 bertrand 3729:
1.21 bertrand 3730: (*element_courant).ligne = ligne;
3731: (*element_courant).taille = taille;
3732: free((*element_courant).fonction);
3733: free((*element_courant).argument);
1.6 bertrand 3734:
1.21 bertrand 3735: if (((*element_courant).fonction = malloc((strlen(fonction)
3736: + 1) * sizeof(unsigned char))) == NULL)
3737: {
3738: pthread_mutex_unlock(&mutex_allocation);
3739: return(NULL);
3740: }
1.6 bertrand 3741:
1.21 bertrand 3742: if (((*element_courant).argument = malloc((strlen(argument)
3743: + 1) * sizeof(unsigned char))) == NULL)
3744: {
3745: pthread_mutex_unlock(&mutex_allocation);
3746: return(NULL);
3747: }
1.6 bertrand 3748:
1.21 bertrand 3749: strcpy((*element_courant).fonction, fonction);
3750: strcpy((*element_courant).argument, argument);
1.6 bertrand 3751:
1.21 bertrand 3752: pthread_mutex_unlock(&mutex_allocation);
1.18 bertrand 3753:
1.21 bertrand 3754: return((*element_courant).pointeur);
3755: }
1.6 bertrand 3756: }
3757: }
3758: else
3759: {
3760: // Revient à malloc()
3761: pointeur = debug_memoire_ajout(taille, fonction, ligne, argument);
3762: return(pointeur);
3763: }
3764: }
3765:
3766: void
3767: debug_memoire_retrait(void *pointeur)
3768: {
3769: struct_memoire *element_courant;
3770: struct_memoire *element_precedent;
3771:
3772: pthread_mutex_lock(&mutex_allocation);
3773:
3774: element_courant = debug;
3775: element_precedent = NULL;
3776:
3777: while(element_courant != NULL)
3778: {
3779: if ((*element_courant).pointeur == pointeur)
3780: {
3781: if (element_precedent == NULL)
3782: {
3783: debug = (*debug).suivant;
3784: }
3785: else
3786: {
3787: (*element_precedent).suivant = (*element_courant).suivant;
3788: }
3789:
1.21 bertrand 3790: if (pointeur != NULL)
3791: {
3792: memset(pointeur, 0, (*element_courant).taille);
3793: }
3794:
1.6 bertrand 3795: free((*element_courant).fonction);
3796: free((*element_courant).argument);
3797: free(element_courant);
3798:
3799: break;
3800: }
3801:
3802: element_precedent = element_courant;
3803: element_courant = (*element_courant).suivant;
3804: }
3805:
3806: pthread_mutex_unlock(&mutex_allocation);
3807:
1.21 bertrand 3808: if (element_courant == NULL)
3809: {
1.26 bertrand 3810: uprintf("[%d-%llu] ILLEGAL POINTER (free)\n",
1.21 bertrand 3811: getpid(), (unsigned long long) pthread_self());
3812: # ifdef __BACKTRACE
3813: BACKTRACE(PROFONDEUR_PILE);
3814: # endif
3815: }
3816:
1.6 bertrand 3817: free(pointeur);
3818: return;
3819: }
3820:
3821: void
1.17 bertrand 3822: debug_memoire_verification()
1.6 bertrand 3823: {
1.16 bertrand 3824: # ifdef __BACKTRACE
3825: char **appels;
3826:
3827: int j;
1.17 bertrand 3828: # endif
1.16 bertrand 3829:
1.6 bertrand 3830: integer8 i;
3831:
3832: struct_memoire *element_courant;
3833: struct_memoire *element_suivant;
3834:
1.17 bertrand 3835: fprintf(stderr, "[%d-%llu] LIST OF MEMORY LEAKS\n",
1.6 bertrand 3836: getpid(), (unsigned long long) pthread_self());
3837:
3838: pthread_mutex_lock(&mutex_allocation);
3839:
3840: element_courant = debug;
3841: i = 1;
3842:
3843: while(element_courant != NULL)
3844: {
1.17 bertrand 3845: fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(),
3846: (unsigned long long) pthread_self(), i,
3847: (*element_courant).ordre);
3848: fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n",
3849: getpid(), (unsigned long long) pthread_self(),
3850: (*element_courant).pointeur,
3851: (*element_courant).fonction, (*element_courant).ligne,
3852: (int) (*element_courant).taille);
3853: fprintf(stderr, "[%d-%llu] A: %s\n", getpid(),
3854: (unsigned long long) pthread_self(),
3855: (*element_courant).argument);
1.16 bertrand 3856:
1.18 bertrand 3857: if (strstr((*element_courant).argument, "sizeof(unsigned char)")
3858: != NULL)
3859: {
3860: fprintf(stderr, "[%d-%llu] ", getpid(),
3861: (unsigned long long) pthread_self());
3862: fprintf(stderr, "O: %s\n", (unsigned char *)
3863: (*element_courant).pointeur);
3864: }
3865: else if (strcmp((*element_courant).argument, "sizeof(struct_objet)")
3866: == 0)
3867: {
3868: fprintf(stderr, "[%d-%llu] ", getpid(),
3869: (unsigned long long) pthread_self());
3870: fprintf(stderr, "O: %d\n", (*((struct_objet *)
3871: (*element_courant).pointeur)).type);
3872: }
3873: else if (strcmp((*element_courant).argument,
3874: "sizeof(struct_liste_chainee)") == 0)
3875: {
3876: fprintf(stderr, "[%d-%llu] ", getpid(),
3877: (unsigned long long) pthread_self());
3878: fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *)
3879: (*element_courant).pointeur)).donnee,
3880: (*((struct_liste_chainee *) (*element_courant).pointeur))
3881: .suivant);
3882: }
3883:
1.17 bertrand 3884: # ifdef __BACKTRACE
3885: appels = backtrace_symbols((*element_courant).pile,
3886: (*element_courant).profondeur);
1.16 bertrand 3887:
1.17 bertrand 3888: fprintf(stderr, "[%d-%llu] BACKTRACE\n",
3889: getpid(), (unsigned long long) pthread_self());
1.6 bertrand 3890:
1.17 bertrand 3891: if (appels != NULL)
3892: {
3893: for(j = 0; j < (*element_courant).profondeur; j++)
1.6 bertrand 3894: {
1.17 bertrand 3895: fprintf(stderr, "[%d-%llu] %s\n", getpid(),
3896: (unsigned long long) pthread_self(), appels[j]);
3897: }
1.16 bertrand 3898:
1.17 bertrand 3899: free(appels);
3900: }
3901: # endif
1.16 bertrand 3902:
1.17 bertrand 3903: fprintf(stderr, "\n");
1.16 bertrand 3904:
1.17 bertrand 3905: i++;
1.6 bertrand 3906:
3907: element_suivant = (*element_courant).suivant;
1.17 bertrand 3908:
3909: # ifndef CORE_DUMP
1.6 bertrand 3910: free((*element_courant).fonction);
3911: free((*element_courant).argument);
3912: free(element_courant);
1.17 bertrand 3913: # endif
3914:
1.6 bertrand 3915: element_courant = element_suivant;
3916: }
3917:
3918: pthread_mutex_unlock(&mutex_allocation);
1.21 bertrand 3919: pthread_mutex_destroy(&mutex_allocation);
1.6 bertrand 3920:
3921: fprintf(stderr, "[%d-%llu] END OF LIST\n", getpid(),
3922: (unsigned long long) pthread_self());
3923:
3924: return;
3925: }
3926:
1.21 bertrand 3927: pid_t
3928: debug_fork()
3929: {
3930: pid_t pid;
3931:
3932: pthread_mutex_lock(&mutex_allocation);
3933: pid = fork();
1.18 bertrand 3934:
1.21 bertrand 3935: if (pid == 0)
3936: {
1.66 bertrand 3937: liberation_queue_signaux(s_etat_processus);
3938: creation_queue_signaux(s_etat_processus);
1.37 bertrand 3939:
1.21 bertrand 3940: pthread_mutex_destroy(&mutex_allocation);
3941: debug_memoire_initialisation();
3942: }
3943: else
3944: {
3945: pthread_mutex_unlock(&mutex_allocation);
3946: }
3947:
3948: // Pas de parenthèses pour ne pas remplacer return par sa macro.
3949: return pid;
1.18 bertrand 3950: }
3951:
3952: void
1.17 bertrand 3953: analyse_post_mortem()
3954: {
3955: # ifdef CORE_DUMP
3956: BUG(debug != NULL, uprintf("[%d-%llu] CREATE CORE DUMP FILE FOR "
3957: "POST MORTEM ANALYZE\n", getpid(),
3958: (unsigned long long) pthread_self()));
3959: # endif
3960:
3961: return;
3962: }
3963:
1.6 bertrand 3964: #endif
3965:
1.1 bertrand 3966: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>