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