Annotation of rpl/src/gestion_objets.c, revision 1.74
1.1 bertrand 1: /*
2: ================================================================================
1.73 bertrand 3: RPL/2 (R) version 4.1.4
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.69 bertrand 2806:
1.71 bertrand 2807: // Les sémaphores sont initialisés dans le nouveau thread. Il
2808: // s'agit d'une limitation de l'implantation de l'émulation
2809: // de sem_init().
1.1 bertrand 2810:
1.60 bertrand 2811: initialisation_contexte_cas(s_etat_processus);
2812:
1.1 bertrand 2813: (*s_nouvel_etat_processus).var_volatile_processus_pere = 0;
1.39 bertrand 2814: (*s_nouvel_etat_processus).var_volatile_processus_racine = 0;
1.1 bertrand 2815: (*s_nouvel_etat_processus).fichiers_graphiques = NULL;
2816: (*s_nouvel_etat_processus).entree_standard = NULL;
2817: (*s_nouvel_etat_processus).s_marques = NULL;
2818: (*s_nouvel_etat_processus).requete_nouveau_plan = d_vrai;
2819: (*s_nouvel_etat_processus).mise_a_jour_trace_requise = d_faux;
2820: (*s_nouvel_etat_processus).nom_fichier_impression = NULL;
2821: (*s_nouvel_etat_processus).expression_courante = NULL;
2822: (*s_nouvel_etat_processus).objet_courant = NULL;
2823: (*s_nouvel_etat_processus).processus_detache = d_faux;
1.3 bertrand 2824: (*s_nouvel_etat_processus).evaluation_forcee = 'N';
1.1 bertrand 2825:
2826: (*s_nouvel_etat_processus).nombre_objets_envoyes_non_lus = 0;
2827: (*s_nouvel_etat_processus).nombre_objets_injectes = 0;
2828: (*s_nouvel_etat_processus).presence_fusible = d_faux;
2829: (*s_nouvel_etat_processus).thread_fusible = 0;
2830: (*s_nouvel_etat_processus).niveau_initial =
2831: (*s_etat_processus).niveau_courant;
2832: (*s_nouvel_etat_processus).presence_pipes = d_faux;
2833: (*s_nouvel_etat_processus).debug_programme = d_faux;
2834: (*s_nouvel_etat_processus).s_fichiers = NULL;
2835: (*s_nouvel_etat_processus).s_connecteurs_sql = NULL;
2836:
2837: // On réinitialise toutes les interruptions.
2838:
2839: (*s_nouvel_etat_processus).traitement_interruption = 'N';
2840: (*s_nouvel_etat_processus).traitement_interruptible = 'Y';
2841: (*s_nouvel_etat_processus).nombre_interruptions_en_queue = 0;
2842: (*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0;
2843:
1.14 bertrand 2844: (*s_nouvel_etat_processus).at_exit = NULL;
1.32 bertrand 2845: (*s_nouvel_etat_processus).at_poke = NULL;
2846: (*s_nouvel_etat_processus).traitement_at_poke = 'N';
1.13 bertrand 2847:
1.1 bertrand 2848: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2849: {
2850: (*s_nouvel_etat_processus).corps_interruptions[i] = NULL;
2851: (*s_nouvel_etat_processus).masque_interruptions[i] = 'N';
2852: (*s_nouvel_etat_processus).queue_interruptions[i] = 0;
2853: (*s_nouvel_etat_processus).pile_origine_interruptions[i] = NULL;
2854: }
2855:
2856: if ((*s_nouvel_etat_processus).generateur_aleatoire != NULL)
2857: {
1.35 bertrand 2858: if (((*s_nouvel_etat_processus).generateur_aleatoire =
2859: gsl_rng_clone((*s_etat_processus).generateur_aleatoire))
2860: == NULL)
2861: {
2862: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2863: return(NULL);
2864: }
2865:
2866: gsl_rng_set((*s_nouvel_etat_processus).generateur_aleatoire,
2867: gsl_rng_get((*s_etat_processus).generateur_aleatoire));
1.1 bertrand 2868: }
2869:
2870: // Copie de la localisation
2871:
2872: if (((*s_nouvel_etat_processus).localisation = malloc((strlen(
2873: (*s_etat_processus).localisation) + 1) * sizeof(unsigned char)))
2874: == NULL)
2875: {
2876: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2877: return(NULL);
2878: }
2879:
2880: strcpy((*s_nouvel_etat_processus).localisation,
2881: (*s_etat_processus).localisation);
2882:
2883: if ((*s_etat_processus).indep != NULL)
2884: {
2885: if (((*s_nouvel_etat_processus).indep = copie_objet(s_etat_processus,
2886: (*s_etat_processus).indep, 'P')) == NULL)
2887: {
2888: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2889: {
2890: (*s_etat_processus).erreur_systeme = d_es_processus;
2891: return(NULL);
2892: }
2893:
2894: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2895: return(NULL);
2896: }
2897: }
2898: else
2899: {
2900: (*s_nouvel_etat_processus).indep = NULL;
2901: }
2902:
2903: if ((*s_etat_processus).depend != NULL)
2904: {
2905: if (((*s_nouvel_etat_processus).depend = copie_objet(s_etat_processus,
2906: (*s_etat_processus).depend, 'P')) == NULL)
2907: {
2908: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2909: {
2910: (*s_etat_processus).erreur_systeme = d_es_processus;
2911: return(NULL);
2912: }
2913:
2914: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2915: return(NULL);
2916: }
2917: }
2918: else
2919: {
2920: (*s_nouvel_etat_processus).depend = NULL;
2921: }
2922:
2923: if ((*s_etat_processus).parametres_courbes_de_niveau != NULL)
2924: {
2925: if (((*s_nouvel_etat_processus).parametres_courbes_de_niveau =
2926: copie_objet(s_etat_processus, (*s_etat_processus)
2927: .parametres_courbes_de_niveau, 'P')) == NULL)
2928: {
2929: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2930: {
2931: (*s_etat_processus).erreur_systeme = d_es_processus;
2932: return(NULL);
2933: }
2934:
2935: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2936: return(NULL);
2937: }
2938: }
2939: else
2940: {
2941: (*s_nouvel_etat_processus).parametres_courbes_de_niveau = NULL;
2942: }
2943:
2944: (*s_nouvel_etat_processus).instruction_derniere_erreur = NULL;
2945:
2946: if (((*s_etat_processus).instruction_courante != NULL) &&
2947: (*s_etat_processus).evaluation_expression_compilee == 'N')
2948: {
2949: if (((*s_nouvel_etat_processus).instruction_courante = malloc((strlen(
2950: (*s_etat_processus).instruction_courante) + 1) *
2951: sizeof(unsigned char))) == NULL)
2952: {
2953: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2954: {
2955: (*s_etat_processus).erreur_systeme = d_es_processus;
2956: return(NULL);
2957: }
2958:
2959: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2960: return(NULL);
2961: }
2962:
2963: strcpy((*s_nouvel_etat_processus).instruction_courante,
2964: (*s_etat_processus).instruction_courante);
2965: }
2966: else
2967: {
2968: (*s_nouvel_etat_processus).instruction_courante = NULL;
2969: }
2970:
2971: if ((*s_etat_processus).label_x != NULL)
2972: {
2973: if (((*s_nouvel_etat_processus).label_x = malloc((strlen(
2974: (*s_etat_processus).label_x) + 1) *
2975: sizeof(unsigned char))) == NULL)
2976: {
2977: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
2978: {
2979: (*s_etat_processus).erreur_systeme = d_es_processus;
2980: return(NULL);
2981: }
2982:
2983: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2984: return(NULL);
2985: }
2986:
2987: strcpy((*s_nouvel_etat_processus).label_x,
2988: (*s_etat_processus).label_x);
2989: }
2990: else
2991: {
2992: (*s_nouvel_etat_processus).label_x = NULL;
2993: }
2994:
2995: if ((*s_etat_processus).label_y != NULL)
2996: {
2997: if (((*s_nouvel_etat_processus).label_y = malloc((strlen(
2998: (*s_etat_processus).label_y) + 1) *
2999: sizeof(unsigned char))) == NULL)
3000: {
3001: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3002: {
3003: (*s_etat_processus).erreur_systeme = d_es_processus;
3004: return(NULL);
3005: }
3006:
3007: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3008: return(NULL);
3009: }
3010:
3011: strcpy((*s_nouvel_etat_processus).label_y,
3012: (*s_etat_processus).label_y);
3013: }
3014: else
3015: {
3016: (*s_nouvel_etat_processus).label_y = NULL;
3017: }
3018:
3019: if ((*s_etat_processus).label_z != NULL)
3020: {
3021: if (((*s_nouvel_etat_processus).label_z = malloc((strlen(
3022: (*s_etat_processus).label_z) + 1) *
3023: sizeof(unsigned char))) == NULL)
3024: {
3025: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3026: {
3027: (*s_etat_processus).erreur_systeme = d_es_processus;
3028: return(NULL);
3029: }
3030:
3031: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3032: return(NULL);
3033: }
3034:
3035: strcpy((*s_nouvel_etat_processus).label_z,
3036: (*s_etat_processus).label_z);
3037: }
3038: else
3039: {
3040: (*s_nouvel_etat_processus).label_z = NULL;
3041: }
3042:
3043: if ((*s_etat_processus).titre != NULL)
3044: {
3045: if (((*s_nouvel_etat_processus).titre = malloc((strlen(
3046: (*s_etat_processus).titre) + 1) *
3047: sizeof(unsigned char))) == NULL)
3048: {
3049: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3050: {
3051: (*s_etat_processus).erreur_systeme = d_es_processus;
3052: return(NULL);
3053: }
3054:
3055: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3056: return(NULL);
3057: }
3058:
3059: strcpy((*s_nouvel_etat_processus).titre,
3060: (*s_etat_processus).titre);
3061: }
3062: else
3063: {
3064: (*s_nouvel_etat_processus).titre = NULL;
3065: }
3066:
3067: if ((*s_etat_processus).legende != NULL)
3068: {
3069: if (((*s_nouvel_etat_processus).legende = malloc((strlen(
3070: (*s_etat_processus).legende) + 1) *
3071: sizeof(unsigned char))) == NULL)
3072: {
3073: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3074: {
3075: (*s_etat_processus).erreur_systeme = d_es_processus;
3076: return(NULL);
3077: }
3078:
3079: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3080: return(NULL);
3081: }
3082:
3083: strcpy((*s_nouvel_etat_processus).legende,
3084: (*s_etat_processus).legende);
3085: }
3086: else
3087: {
3088: (*s_nouvel_etat_processus).legende = NULL;
3089: }
3090:
3091: /*
3092: * Copie de la table des variables
3093: */
3094:
1.51 bertrand 3095: copie_arbre_variables(s_etat_processus, s_nouvel_etat_processus);
3096:
3097: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
1.1 bertrand 3098: {
3099: return(NULL);
3100: }
3101:
3102: /*
3103: * Copie de la table des variables statiques
3104: */
3105:
3106: if (((*s_nouvel_etat_processus).s_liste_variables_statiques =
3107: malloc((*s_etat_processus).nombre_variables_statiques_allouees *
3108: sizeof(struct_variable_statique))) == NULL)
3109: {
3110: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3111: {
3112: (*s_etat_processus).erreur_systeme = d_es_processus;
3113: return(NULL);
3114: }
3115:
3116: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3117: return(NULL);
3118: }
3119:
3120: for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++)
3121: {
3122: if (((*s_nouvel_etat_processus).s_liste_variables_statiques[i].nom =
3123: malloc((strlen((*s_etat_processus).s_liste_variables_statiques
3124: [i].nom) + 1) * sizeof(unsigned char))) == NULL)
3125: {
3126: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3127: {
3128: (*s_etat_processus).erreur_systeme = d_es_processus;
3129: return(NULL);
3130: }
3131:
3132: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3133: return(NULL);
3134: }
3135:
3136: strcpy((*s_nouvel_etat_processus).s_liste_variables_statiques[i].nom,
3137: (*s_etat_processus).s_liste_variables_statiques[i].nom);
3138:
3139: (*s_nouvel_etat_processus).s_liste_variables_statiques[i].origine =
3140: (*s_etat_processus).s_liste_variables_statiques[i].origine;
3141: (*s_nouvel_etat_processus).s_liste_variables_statiques[i].niveau =
3142: (*s_etat_processus).s_liste_variables_statiques[i].niveau;
3143: (*s_nouvel_etat_processus).s_liste_variables_statiques[i]
3144: .variable_statique = (*s_etat_processus)
3145: .s_liste_variables_statiques[i].variable_statique;
3146:
3147: if (((*s_nouvel_etat_processus).s_liste_variables_statiques[i].objet =
3148: copie_objet(s_etat_processus, (*s_etat_processus)
3149: .s_liste_variables_statiques[i].objet, 'P')) == NULL)
3150: {
3151: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3152: {
3153: (*s_etat_processus).erreur_systeme = d_es_processus;
3154: return(NULL);
3155: }
3156:
3157: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3158: return(NULL);
3159: }
3160: }
3161:
3162: /*
3163: * Copie de la pile opérationnelle
3164: */
3165:
3166: (*s_nouvel_etat_processus).l_base_pile = NULL;
3167: l_element_lecture = (*s_etat_processus).l_base_pile;
3168: l_element_precedent = NULL;
3169:
3170: while(l_element_lecture != NULL)
3171: {
3172: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3173: {
3174: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3175: {
3176: (*s_etat_processus).erreur_systeme = d_es_processus;
3177: return(NULL);
3178: }
3179:
3180: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3181: return(NULL);
3182: }
3183:
3184: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3185: (*l_element_lecture).donnee, 'P')) == NULL)
3186: {
3187: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3188: {
3189: (*s_etat_processus).erreur_systeme = d_es_processus;
3190: return(NULL);
3191: }
3192:
3193: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3194: return(NULL);
3195: }
3196:
3197: (*l_element_suivant).suivant = NULL;
3198:
3199: if ((*s_nouvel_etat_processus).l_base_pile == NULL)
3200: {
3201: (*s_nouvel_etat_processus).l_base_pile = l_element_suivant;
3202: }
3203: else
3204: {
3205: (*l_element_precedent).suivant = l_element_suivant;
3206: }
3207:
3208: l_element_precedent = l_element_suivant;
3209: l_element_lecture = (*l_element_lecture).suivant;
3210: }
3211:
3212: /*
3213: * Copie de la pile système
3214: */
3215:
3216: (*s_nouvel_etat_processus).l_base_pile_systeme = NULL;
3217: (*s_nouvel_etat_processus).hauteur_pile_systeme = 0;
3218:
3219: empilement_pile_systeme(s_nouvel_etat_processus);
3220:
3221: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
3222: {
3223: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3224: {
3225: (*s_etat_processus).erreur_systeme = d_es_processus;
3226: return(NULL);
3227: }
3228:
3229: (*s_etat_processus).erreur_systeme =
3230: (*s_nouvel_etat_processus).erreur_systeme;
3231: return(NULL);
3232: }
3233:
3234: (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
3235:
3236: /*
3237: * On empile deux valeurs retour_definition pour pouvoir récupérer
3238: * les variables dans le cas d'un programme compilé.
3239: */
3240:
3241: empilement_pile_systeme(s_nouvel_etat_processus);
3242:
3243: if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
3244: {
3245: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3246: {
3247: (*s_etat_processus).erreur_systeme = d_es_processus;
3248: return(NULL);
3249: }
3250:
3251: (*s_etat_processus).erreur_systeme =
3252: (*s_nouvel_etat_processus).erreur_systeme;
3253: return(NULL);
3254: }
3255:
3256: (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
3257:
3258: /*
3259: * Destruction de la pile last pour le thread en cours.
3260: */
3261:
3262: (*s_nouvel_etat_processus).l_base_pile_last = NULL;
3263: (*s_nouvel_etat_processus).l_base_pile_processus = NULL;
3264:
3265: /*
3266: * Copie des différents contextes
3267: */
3268:
1.66 bertrand 3269: (*s_nouvel_etat_processus).pointeur_signal_lecture = d_faux;
3270: (*s_nouvel_etat_processus).pointeur_signal_ecriture = d_faux;
3271:
1.1 bertrand 3272: (*s_nouvel_etat_processus).l_base_pile_contextes = NULL;
3273: l_element_lecture = (*s_etat_processus).l_base_pile_contextes;
3274:
3275: while(l_element_lecture != NULL)
3276: {
3277: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3278: {
3279: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3280: {
3281: (*s_etat_processus).erreur_systeme = d_es_processus;
3282: return(NULL);
3283: }
3284:
3285: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3286: return(NULL);
3287: }
3288:
3289: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3290: (*l_element_lecture).donnee, 'P')) == NULL)
3291: {
3292: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3293: {
3294: (*s_etat_processus).erreur_systeme = d_es_processus;
3295: return(NULL);
3296: }
3297:
3298: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3299: return(NULL);
3300: }
3301:
3302: (*l_element_suivant).suivant = NULL;
3303:
3304: if ((*s_nouvel_etat_processus).l_base_pile_contextes == NULL)
3305: {
3306: (*s_nouvel_etat_processus).l_base_pile_contextes =
3307: l_element_suivant;
3308: }
3309: else
3310: {
3311: (*l_element_precedent).suivant = l_element_suivant;
3312: }
3313:
3314: l_element_precedent = l_element_suivant;
3315: l_element_lecture = (*l_element_lecture).suivant;
3316: }
3317:
3318: (*s_nouvel_etat_processus).l_base_pile_taille_contextes = NULL;
3319: l_element_lecture = (*s_etat_processus).l_base_pile_taille_contextes;
3320:
3321: while(l_element_lecture != NULL)
3322: {
3323: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3324: {
3325: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3326: {
3327: (*s_etat_processus).erreur_systeme = d_es_processus;
3328: return(NULL);
3329: }
3330:
3331: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3332: return(NULL);
3333: }
3334:
3335: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3336: (*l_element_lecture).donnee, 'P')) == NULL)
3337: {
3338: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3339: {
3340: (*s_etat_processus).erreur_systeme = d_es_processus;
3341: return(NULL);
3342: }
3343:
3344: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3345: return(NULL);
3346: }
3347:
3348: (*l_element_suivant).suivant = NULL;
3349:
3350: if ((*s_nouvel_etat_processus).l_base_pile_taille_contextes == NULL)
3351: {
3352: (*s_nouvel_etat_processus).l_base_pile_taille_contextes =
3353: l_element_suivant;
3354: }
3355: else
3356: {
3357: (*l_element_precedent).suivant = l_element_suivant;
3358: }
3359:
3360: l_element_precedent = l_element_suivant;
3361: l_element_lecture = (*l_element_lecture).suivant;
3362: }
3363:
3364: /*
3365: * Copies des piles s_sockets, s_bibliotheques et
3366: * s_instructions_externes.
3367: */
3368:
3369: (*s_nouvel_etat_processus).s_sockets = NULL;
3370: l_element_lecture = (*s_etat_processus).s_sockets;
3371:
3372: while(l_element_lecture != NULL)
3373: {
3374: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3375: {
3376: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3377: {
3378: (*s_etat_processus).erreur_systeme = d_es_processus;
3379: return(NULL);
3380: }
3381:
3382: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3383: return(NULL);
3384: }
3385:
3386: if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
3387: (*l_element_lecture).donnee, 'P')) == NULL)
3388: {
3389: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3390: {
3391: (*s_etat_processus).erreur_systeme = d_es_processus;
3392: return(NULL);
3393: }
3394:
3395: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3396: return(NULL);
3397: }
3398:
3399: (*l_element_suivant).suivant = NULL;
3400:
3401: if ((*s_nouvel_etat_processus).s_sockets == NULL)
3402: {
3403: (*s_nouvel_etat_processus).s_sockets = l_element_suivant;
3404: }
3405: else
3406: {
3407: (*l_element_precedent).suivant = l_element_suivant;
3408: }
3409:
3410: l_element_precedent = l_element_suivant;
3411: l_element_lecture = (*l_element_lecture).suivant;
3412: }
3413:
3414: (*s_nouvel_etat_processus).s_bibliotheques = NULL;
3415: l_element_precedent = NULL;
3416: l_element_lecture = (*s_etat_processus).s_bibliotheques;
3417:
3418: while(l_element_lecture != NULL)
3419: {
3420: if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
3421: {
3422: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3423: {
3424: (*s_etat_processus).erreur_systeme = d_es_processus;
3425: return(NULL);
3426: }
3427:
3428: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3429: return(NULL);
3430: }
3431:
3432: if (((*l_element_suivant).donnee = malloc(sizeof(struct_bibliotheque)))
3433: == NULL)
3434: {
3435: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3436: return(NULL);
3437: }
3438:
3439: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).descripteur
3440: = (*((struct_bibliotheque *) (*l_element_lecture).donnee))
3441: .descripteur;
3442: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).pid
3443: = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).pid;
3444: (*((struct_bibliotheque *) (*l_element_suivant).donnee)).tid
3445: = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).tid;
3446:
3447: if (((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom =
3448: malloc((strlen((*((struct_bibliotheque *) (*l_element_lecture)
3449: .donnee)).nom) + 1) * sizeof(unsigned char))) == NULL)
3450: {
3451: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3452: {
3453: (*s_etat_processus).erreur_systeme = d_es_processus;
3454: return(NULL);
3455: }
3456:
3457: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
3458: return(NULL);
3459: }
3460:
3461: strcpy((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom,
3462: (*((struct_bibliotheque *) (*l_element_lecture).donnee)).nom);
3463:
3464: (*l_element_suivant).suivant = NULL;
3465:
3466: if ((*s_nouvel_etat_processus).s_bibliotheques == NULL)
3467: {
3468: (*s_nouvel_etat_processus).s_bibliotheques = l_element_suivant;
3469: }
3470: else
3471: {
3472: (*l_element_precedent).suivant = l_element_suivant;
3473: }
3474:
3475: l_element_precedent = l_element_suivant;
3476: l_element_lecture = (*l_element_lecture).suivant;
3477: }
3478:
3479: if ((*s_etat_processus).nombre_instructions_externes != 0)
3480: {
3481: if (((*s_nouvel_etat_processus).s_instructions_externes =
3482: malloc((*s_etat_processus).nombre_instructions_externes *
3483: sizeof(struct_instruction_externe))) == NULL)
3484: {
3485: (*s_etat_processus).erreur_systeme = d_es_processus;
3486: return(NULL);
3487: }
3488:
3489: for(i = 0; i < (*s_etat_processus).nombre_instructions_externes; i++)
3490: {
3491: if (((*s_nouvel_etat_processus).s_instructions_externes[i].nom =
3492: malloc((strlen((*s_etat_processus).s_instructions_externes
3493: [i].nom) + 1) * sizeof(unsigned char))) == NULL)
3494: {
3495: (*s_etat_processus).erreur_systeme = d_es_processus;
3496: return(NULL);
3497: }
3498:
3499: strcpy((*s_nouvel_etat_processus).s_instructions_externes[i].nom,
3500: (*s_etat_processus).s_instructions_externes[i].nom);
3501:
3502: if (((*s_nouvel_etat_processus).s_instructions_externes[i]
3503: .nom_bibliotheque = malloc((strlen((*s_etat_processus)
3504: .s_instructions_externes[i].nom_bibliotheque) + 1) *
3505: sizeof(unsigned char))) == NULL)
3506: {
3507: (*s_etat_processus).erreur_systeme = d_es_processus;
3508: return(NULL);
3509: }
3510:
3511: strcpy((*s_nouvel_etat_processus).s_instructions_externes[i]
3512: .nom_bibliotheque, (*s_etat_processus)
3513: .s_instructions_externes[i].nom_bibliotheque);
3514:
3515: (*s_nouvel_etat_processus).s_instructions_externes[i]
3516: .descripteur_bibliotheque = (*s_etat_processus)
3517: .s_instructions_externes[i].descripteur_bibliotheque;
3518: }
3519: }
3520: else
3521: {
3522: (*s_nouvel_etat_processus).s_instructions_externes = NULL;
3523: }
3524:
3525: pthread_mutexattr_init(&attributs_mutex);
3526: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
3527: pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex);
3528: pthread_mutexattr_destroy(&attributs_mutex);
3529:
1.28 bertrand 3530: pthread_mutexattr_init(&attributs_mutex);
3531: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
3532: pthread_mutex_init(&((*s_nouvel_etat_processus).mutex_allocation),
3533: &attributs_mutex);
3534: pthread_mutexattr_destroy(&attributs_mutex);
3535:
1.1 bertrand 3536: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
3537: {
3538: (*s_etat_processus).erreur_systeme = d_es_processus;
3539: return(NULL);
3540: }
3541:
3542: return(s_nouvel_etat_processus);
3543:
3544: #undef return
3545: }
3546:
1.6 bertrand 3547:
3548: /*
3549: ================================================================================
3550: Routines de debug
3551: ================================================================================
3552: entrées :
3553: --------------------------------------------------------------------------------
3554: sorties :
3555: --------------------------------------------------------------------------------
3556: effets de bord : néant
3557: ================================================================================
3558: */
3559:
3560: #ifdef DEBUG_MEMOIRE
3561:
3562: #undef malloc
3563: #undef realloc
3564: #undef free
1.21 bertrand 3565: #undef fork
1.6 bertrand 3566:
3567: #ifdef return
3568: # undef return
3569: #endif
3570:
1.16 bertrand 3571: #ifdef __BACKTRACE
1.21 bertrand 3572: #define PROFONDEUR_PILE 64
1.6 bertrand 3573: #define return(a) { if (a == NULL) \
1.21 bertrand 3574: { BACKTRACE(PROFONDEUR_PILE); \
3575: fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \
1.6 bertrand 3576: return(a); } while(0)
1.16 bertrand 3577: #endif
1.6 bertrand 3578:
1.21 bertrand 3579: #undef fprintf
3580: #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b))
3581: #undef CORE_DUMP
3582:
1.6 bertrand 3583: typedef struct memoire
3584: {
3585: void *pointeur;
3586: unsigned char *fonction;
3587: unsigned char *argument;
3588: unsigned long ligne;
3589: size_t taille;
3590: unsigned long long ordre;
1.16 bertrand 3591: # ifdef __BACKTRACE
3592: void *pile[PROFONDEUR_PILE];
3593: int profondeur;
3594: # endif
1.6 bertrand 3595: struct memoire *suivant;
3596: } struct_memoire;
3597:
3598: static struct_memoire *debug = NULL;
3599: static unsigned long long ordre = 0;
1.21 bertrand 3600: static pthread_mutex_t mutex_allocation;
3601:
3602: void
3603: debug_memoire_initialisation()
3604: {
3605: pthread_mutexattr_t attributs_mutex;
3606:
3607: pthread_mutexattr_init(&attributs_mutex);
3608: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE);
3609: pthread_mutex_init(&mutex_allocation, &attributs_mutex);
3610: pthread_mutexattr_destroy(&attributs_mutex);
1.6 bertrand 3611:
1.21 bertrand 3612: return;
3613: }
1.6 bertrand 3614:
3615: void *
3616: debug_memoire_ajout(size_t taille, const unsigned char *fonction,
3617: unsigned long ligne, const unsigned char *argument)
3618: {
3619: struct_memoire *ancienne_base;
3620:
1.21 bertrand 3621: void *pointeur;
3622:
1.6 bertrand 3623: pthread_mutex_lock(&mutex_allocation);
3624:
3625: ancienne_base = debug;
3626:
3627: if ((debug = malloc(sizeof(struct_memoire))) == NULL)
3628: {
3629: pthread_mutex_unlock(&mutex_allocation);
3630: return(NULL);
3631: }
3632:
3633: if (((*debug).pointeur = malloc(taille)) == NULL)
3634: {
3635: pthread_mutex_unlock(&mutex_allocation);
3636: return(NULL);
3637: }
3638:
3639: (*debug).suivant = ancienne_base;
3640: (*debug).ligne = ligne;
3641: (*debug).taille = taille;
3642: (*debug).ordre = ordre;
1.16 bertrand 3643:
1.21 bertrand 3644: pointeur = (*debug).pointeur;
3645:
1.16 bertrand 3646: # ifdef __BACKTRACE
3647: (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE);
3648: # endif
1.6 bertrand 3649:
3650: if (((*debug).fonction = malloc((strlen(fonction) + 1) *
3651: sizeof(unsigned char))) == NULL)
3652: {
1.18 bertrand 3653: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3654: return(NULL);
3655: }
3656:
3657: if (((*debug).argument = malloc((strlen(argument) + 1) *
3658: sizeof(unsigned char))) == NULL)
3659: {
1.18 bertrand 3660: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3661: return(NULL);
3662: }
3663:
3664: strcpy((*debug).fonction, fonction);
3665: strcpy((*debug).argument, argument);
3666:
1.21 bertrand 3667: memset((*debug).pointeur, 0, (*debug).taille);
3668:
1.18 bertrand 3669: pthread_mutex_unlock(&mutex_allocation);
1.6 bertrand 3670: ordre++;
3671:
1.21 bertrand 3672: return(pointeur);
1.6 bertrand 3673: }
3674:
3675: void *
3676: debug_memoire_modification(void *pointeur, size_t taille,
3677: const unsigned char *fonction, unsigned long ligne,
3678: const unsigned char *argument)
3679: {
3680: struct_memoire *element_courant;
3681:
3682: if (pointeur != NULL)
3683: {
3684: if (taille == 0)
3685: {
1.21 bertrand 3686: // Revient à free(). Il n'y a pas de parenthèses car on ne veut
3687: // pas utiliser la macro return().
3688:
1.6 bertrand 3689: debug_memoire_retrait(pointeur);
1.21 bertrand 3690: return NULL ;
1.6 bertrand 3691: }
3692: else
3693: {
3694: // Réallocation réelle
3695:
3696: pthread_mutex_lock(&mutex_allocation);
3697:
3698: element_courant = debug;
3699:
3700: while(element_courant != NULL)
3701: {
3702: if ((*element_courant).pointeur == pointeur)
3703: {
3704: break;
3705: }
3706:
3707: element_courant = (*element_courant).suivant;
3708: }
3709:
3710: if (element_courant == NULL)
3711: {
3712: pthread_mutex_unlock(&mutex_allocation);
1.21 bertrand 3713:
1.26 bertrand 3714: uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n",
1.21 bertrand 3715: getpid(), (unsigned long long) pthread_self());
3716: # ifdef __BACKTRACE
3717: BACKTRACE(PROFONDEUR_PILE);
3718: # endif
3719:
3720: return(realloc(pointeur, taille));
1.6 bertrand 3721: }
1.21 bertrand 3722: else
1.6 bertrand 3723: {
1.21 bertrand 3724: if (((*element_courant).pointeur = realloc(pointeur, taille))
3725: == NULL)
3726: {
3727: pthread_mutex_unlock(&mutex_allocation);
3728: return(NULL);
3729: }
1.6 bertrand 3730:
1.21 bertrand 3731: (*element_courant).ligne = ligne;
3732: (*element_courant).taille = taille;
3733: free((*element_courant).fonction);
3734: free((*element_courant).argument);
1.6 bertrand 3735:
1.21 bertrand 3736: if (((*element_courant).fonction = malloc((strlen(fonction)
3737: + 1) * sizeof(unsigned char))) == NULL)
3738: {
3739: pthread_mutex_unlock(&mutex_allocation);
3740: return(NULL);
3741: }
1.6 bertrand 3742:
1.21 bertrand 3743: if (((*element_courant).argument = malloc((strlen(argument)
3744: + 1) * sizeof(unsigned char))) == NULL)
3745: {
3746: pthread_mutex_unlock(&mutex_allocation);
3747: return(NULL);
3748: }
1.6 bertrand 3749:
1.21 bertrand 3750: strcpy((*element_courant).fonction, fonction);
3751: strcpy((*element_courant).argument, argument);
1.6 bertrand 3752:
1.21 bertrand 3753: pthread_mutex_unlock(&mutex_allocation);
1.18 bertrand 3754:
1.21 bertrand 3755: return((*element_courant).pointeur);
3756: }
1.6 bertrand 3757: }
3758: }
3759: else
3760: {
3761: // Revient à malloc()
3762: pointeur = debug_memoire_ajout(taille, fonction, ligne, argument);
3763: return(pointeur);
3764: }
3765: }
3766:
3767: void
3768: debug_memoire_retrait(void *pointeur)
3769: {
3770: struct_memoire *element_courant;
3771: struct_memoire *element_precedent;
3772:
3773: pthread_mutex_lock(&mutex_allocation);
3774:
3775: element_courant = debug;
3776: element_precedent = NULL;
3777:
3778: while(element_courant != NULL)
3779: {
3780: if ((*element_courant).pointeur == pointeur)
3781: {
3782: if (element_precedent == NULL)
3783: {
3784: debug = (*debug).suivant;
3785: }
3786: else
3787: {
3788: (*element_precedent).suivant = (*element_courant).suivant;
3789: }
3790:
1.21 bertrand 3791: if (pointeur != NULL)
3792: {
3793: memset(pointeur, 0, (*element_courant).taille);
3794: }
3795:
1.6 bertrand 3796: free((*element_courant).fonction);
3797: free((*element_courant).argument);
3798: free(element_courant);
3799:
3800: break;
3801: }
3802:
3803: element_precedent = element_courant;
3804: element_courant = (*element_courant).suivant;
3805: }
3806:
3807: pthread_mutex_unlock(&mutex_allocation);
3808:
1.21 bertrand 3809: if (element_courant == NULL)
3810: {
1.26 bertrand 3811: uprintf("[%d-%llu] ILLEGAL POINTER (free)\n",
1.21 bertrand 3812: getpid(), (unsigned long long) pthread_self());
3813: # ifdef __BACKTRACE
3814: BACKTRACE(PROFONDEUR_PILE);
3815: # endif
3816: }
3817:
1.6 bertrand 3818: free(pointeur);
3819: return;
3820: }
3821:
3822: void
1.17 bertrand 3823: debug_memoire_verification()
1.6 bertrand 3824: {
1.16 bertrand 3825: # ifdef __BACKTRACE
3826: char **appels;
3827:
3828: int j;
1.17 bertrand 3829: # endif
1.16 bertrand 3830:
1.6 bertrand 3831: integer8 i;
3832:
3833: struct_memoire *element_courant;
3834: struct_memoire *element_suivant;
3835:
1.17 bertrand 3836: fprintf(stderr, "[%d-%llu] LIST OF MEMORY LEAKS\n",
1.6 bertrand 3837: getpid(), (unsigned long long) pthread_self());
3838:
3839: pthread_mutex_lock(&mutex_allocation);
3840:
3841: element_courant = debug;
3842: i = 1;
3843:
3844: while(element_courant != NULL)
3845: {
1.17 bertrand 3846: fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(),
3847: (unsigned long long) pthread_self(), i,
3848: (*element_courant).ordre);
3849: fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n",
3850: getpid(), (unsigned long long) pthread_self(),
3851: (*element_courant).pointeur,
3852: (*element_courant).fonction, (*element_courant).ligne,
3853: (int) (*element_courant).taille);
3854: fprintf(stderr, "[%d-%llu] A: %s\n", getpid(),
3855: (unsigned long long) pthread_self(),
3856: (*element_courant).argument);
1.16 bertrand 3857:
1.18 bertrand 3858: if (strstr((*element_courant).argument, "sizeof(unsigned char)")
3859: != NULL)
3860: {
3861: fprintf(stderr, "[%d-%llu] ", getpid(),
3862: (unsigned long long) pthread_self());
3863: fprintf(stderr, "O: %s\n", (unsigned char *)
3864: (*element_courant).pointeur);
3865: }
3866: else if (strcmp((*element_courant).argument, "sizeof(struct_objet)")
3867: == 0)
3868: {
3869: fprintf(stderr, "[%d-%llu] ", getpid(),
3870: (unsigned long long) pthread_self());
3871: fprintf(stderr, "O: %d\n", (*((struct_objet *)
3872: (*element_courant).pointeur)).type);
3873: }
3874: else if (strcmp((*element_courant).argument,
3875: "sizeof(struct_liste_chainee)") == 0)
3876: {
3877: fprintf(stderr, "[%d-%llu] ", getpid(),
3878: (unsigned long long) pthread_self());
3879: fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *)
3880: (*element_courant).pointeur)).donnee,
3881: (*((struct_liste_chainee *) (*element_courant).pointeur))
3882: .suivant);
3883: }
3884:
1.17 bertrand 3885: # ifdef __BACKTRACE
3886: appels = backtrace_symbols((*element_courant).pile,
3887: (*element_courant).profondeur);
1.16 bertrand 3888:
1.17 bertrand 3889: fprintf(stderr, "[%d-%llu] BACKTRACE\n",
3890: getpid(), (unsigned long long) pthread_self());
1.6 bertrand 3891:
1.17 bertrand 3892: if (appels != NULL)
3893: {
3894: for(j = 0; j < (*element_courant).profondeur; j++)
1.6 bertrand 3895: {
1.17 bertrand 3896: fprintf(stderr, "[%d-%llu] %s\n", getpid(),
3897: (unsigned long long) pthread_self(), appels[j]);
3898: }
1.16 bertrand 3899:
1.17 bertrand 3900: free(appels);
3901: }
3902: # endif
1.16 bertrand 3903:
1.17 bertrand 3904: fprintf(stderr, "\n");
1.16 bertrand 3905:
1.17 bertrand 3906: i++;
1.6 bertrand 3907:
3908: element_suivant = (*element_courant).suivant;
1.17 bertrand 3909:
3910: # ifndef CORE_DUMP
1.6 bertrand 3911: free((*element_courant).fonction);
3912: free((*element_courant).argument);
3913: free(element_courant);
1.17 bertrand 3914: # endif
3915:
1.6 bertrand 3916: element_courant = element_suivant;
3917: }
3918:
3919: pthread_mutex_unlock(&mutex_allocation);
1.21 bertrand 3920: pthread_mutex_destroy(&mutex_allocation);
1.6 bertrand 3921:
3922: fprintf(stderr, "[%d-%llu] END OF LIST\n", getpid(),
3923: (unsigned long long) pthread_self());
3924:
3925: return;
3926: }
3927:
1.21 bertrand 3928: pid_t
3929: debug_fork()
3930: {
3931: pid_t pid;
3932:
3933: pthread_mutex_lock(&mutex_allocation);
3934: pid = fork();
1.18 bertrand 3935:
1.21 bertrand 3936: if (pid == 0)
3937: {
1.66 bertrand 3938: liberation_queue_signaux(s_etat_processus);
3939: creation_queue_signaux(s_etat_processus);
1.37 bertrand 3940:
1.21 bertrand 3941: pthread_mutex_destroy(&mutex_allocation);
3942: debug_memoire_initialisation();
3943: }
3944: else
3945: {
3946: pthread_mutex_unlock(&mutex_allocation);
3947: }
3948:
3949: // Pas de parenthèses pour ne pas remplacer return par sa macro.
3950: return pid;
1.18 bertrand 3951: }
3952:
3953: void
1.17 bertrand 3954: analyse_post_mortem()
3955: {
3956: # ifdef CORE_DUMP
3957: BUG(debug != NULL, uprintf("[%d-%llu] CREATE CORE DUMP FILE FOR "
3958: "POST MORTEM ANALYZE\n", getpid(),
3959: (unsigned long long) pthread_self()));
3960: # endif
3961:
3962: return;
3963: }
3964:
1.6 bertrand 3965: #endif
3966:
1.1 bertrand 3967: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>