Annotation of rpl/src/instructions_m4.c, revision 1.31
1.1 bertrand 1: /*
2: ================================================================================
1.30 bertrand 3: RPL/2 (R) version 4.1.3
1.16 bertrand 4: Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1 bertrand 5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
1.12 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Fonction 'mem'
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_mem(struct_processus *s_etat_processus)
40: {
1.23 bertrand 41: int j;
42: int nb_variables;
1.1 bertrand 43:
1.23 bertrand 44: struct_liste_chainee *l_element_courant;
45:
46: struct_objet *s_objet_resultat;
47:
48: struct_tableau_variables *tableau;
1.1 bertrand 49:
1.23 bertrand 50: unsigned long i;
1.1 bertrand 51:
52: (*s_etat_processus).erreur_execution = d_ex;
53:
54: if ((*s_etat_processus).affichage_arguments == 'Y')
55: {
56: printf("\n MEM ");
57:
58: if ((*s_etat_processus).langue == 'F')
59: {
60: printf("(mémoire occupée)\n\n");
61: }
62: else
63: {
64: printf("(used memory)\n\n");
65: }
66:
67: printf("-> 1: %s\n", d_LST);
68:
69: return;
70: }
71: else if ((*s_etat_processus).test_instruction == 'Y')
72: {
73: (*s_etat_processus).nombre_arguments = -1;
74: return;
75: }
76:
77: if (test_cfsf(s_etat_processus, 31) == d_vrai)
78: {
79: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
80: {
81: return;
82: }
83: }
84:
85: if ((s_objet_resultat = allocation(s_etat_processus, LST))
86: == NULL)
87: {
88: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
89: return;
90: }
91:
92: if (((*s_objet_resultat).objet =
93: allocation_maillon(s_etat_processus)) == NULL)
94: {
95: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
96: return;
97: }
98:
99: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet)).donnee =
100: allocation(s_etat_processus, INT)) == NULL)
101: {
102: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
103: return;
104: }
105:
106: /*
107: * Décompte de la mémoire utilisée dans la pile
108: */
109:
110: (*((integer8 *) (*((*((struct_liste_chainee *) (*s_objet_resultat).objet))
111: .donnee)).objet)) = 0;
112:
113: l_element_courant = (*s_etat_processus).l_base_pile;
114:
115: while(l_element_courant != NULL)
116: {
117: (*((integer8 *) (*((*((struct_liste_chainee *) (*s_objet_resultat)
118: .objet)).donnee)).objet)) += occupation_memoire(
119: (*l_element_courant).donnee);
120: l_element_courant = (*l_element_courant).suivant;
121: }
122:
123: /*
124: * Décompte de la mémoire utilisée pour les différentes variables
125: */
126:
127: if (((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant
128: = allocation_maillon(s_etat_processus)) == NULL)
129: {
130: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
131: return;
132: }
133:
134: if (((*((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant))
135: .donnee = allocation(s_etat_processus, INT)) == NULL)
136: {
137: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
138: return;
139: }
140:
141: (*((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant))
142: .suivant = NULL;
143:
144: (*((integer8 *) (*((*((*((struct_liste_chainee *)
145: (*s_objet_resultat).objet)).suivant)).donnee)).objet)) = 0;
146:
1.23 bertrand 147: nb_variables = nombre_variables(s_etat_processus,
148: (*s_etat_processus).s_arbre_variables);
149:
150: if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables)))
151: == NULL)
152: {
153: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
154: return;
155: }
156:
157: liste_variables(s_etat_processus, tableau, 0,
158: (*s_etat_processus).s_arbre_variables);
159:
160: for(j = 0; j < nb_variables; j++)
1.1 bertrand 161: {
162: (*((integer8 *) (*((*((*((struct_liste_chainee *) (*s_objet_resultat)
163: .objet)).suivant)).donnee)).objet)) += sizeof(unsigned char) *
1.23 bertrand 164: strlen(tableau[j].nom);
1.1 bertrand 165: (*((integer8 *) (*((*((*((struct_liste_chainee *) (*s_objet_resultat)
166: .objet)).suivant)).donnee)).objet)) += occupation_memoire(
1.23 bertrand 167: tableau[j].objet);
1.1 bertrand 168: }
1.23 bertrand 169:
170: free(tableau);
1.1 bertrand 171:
172: for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++)
173: {
174: // Comptabilisation des empreintes mémoire des variables
175: // statiques qui ne sont pas accessibles, les variables statiques
176: // accessibles étant déjà comptabilitées par la boucle précédente.
177:
178: if ((*s_etat_processus).s_liste_variables_statiques[i].objet != NULL)
179: {
180: (*((integer8 *) (*((*((*((struct_liste_chainee *)
181: (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
182: sizeof(unsigned char) * strlen((*s_etat_processus)
183: .s_liste_variables_statiques[i].nom);
184: (*((integer8 *) (*((*((*((struct_liste_chainee *)
185: (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
186: occupation_memoire((*s_etat_processus)
187: .s_liste_variables_statiques[i].objet);
188: }
189: }
190:
191: for(i = 0; i < (*(*s_etat_processus).s_liste_variables_partagees)
192: .nombre_variables; i++)
193: {
194: (*((integer8 *) (*((*((*((struct_liste_chainee *)
195: (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
196: sizeof(unsigned char) * strlen((*(*s_etat_processus)
197: .s_liste_variables_partagees).table[i].nom);
198: (*((integer8 *) (*((*((*((struct_liste_chainee *)
199: (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
200: occupation_memoire((*(*s_etat_processus)
201: .s_liste_variables_partagees).table[i].objet);
202: }
203:
204: /*
205: * Empilement du résultat
206: */
207:
208: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
209: s_objet_resultat) == d_erreur)
210: {
211: return;
212: }
213:
214: return;
215: }
216:
217:
218: /*
219: ================================================================================
220: Fonction 'mclrin'
221: ================================================================================
222: Entrées :
223: --------------------------------------------------------------------------------
224: Sorties :
225: --------------------------------------------------------------------------------
226: Effets de bord : néant
227: ================================================================================
228: */
229:
230: void
231: instruction_mclrin(struct_processus *s_etat_processus)
232: {
233: logical1 last_valide;
234:
235: struct_liste_chainee *l_liste;
236:
237: struct_objet *s_objet;
238:
239: (*s_etat_processus).erreur_execution = d_ex;
240:
241: if ((*s_etat_processus).affichage_arguments == 'Y')
242: {
243: printf("\n MCLRIN ");
244:
245: if ((*s_etat_processus).langue == 'F')
246: {
247: printf("(série de MacLaurin)\n\n");
248: }
249: else
250: {
251: printf("(MacLaurin serie)\n\n");
252: }
253:
254: printf(" 3: %s\n", d_ALG);
255: printf(" 2: %s\n", d_NOM);
256: printf(" 1: %s\n", d_INT);
257: printf("-> 1: %s\n", d_ALG);
258:
259: return;
260: }
261: else if ((*s_etat_processus).test_instruction == 'Y')
262: {
263: (*s_etat_processus).nombre_arguments = -1;
264: return;
265: }
266:
267: if ((last_valide = test_cfsf(s_etat_processus, 31)) == d_vrai)
268: {
269: if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
270: {
271: return;
272: }
273: }
274:
275: if ((*s_etat_processus).hauteur_pile_operationnelle < 3)
276: {
277: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
278: return;
279: }
280:
281: if ((s_objet = allocation(s_etat_processus, INT)) == NULL)
282: {
283: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
284: return;
285: }
286:
287: (*((integer8 *) (*s_objet).objet)) = 0;
288:
289: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
290: s_objet) == d_erreur)
291: {
292: return;
293: }
294:
295: l_liste = (*s_etat_processus).l_base_pile;
296: (*s_etat_processus).l_base_pile = (*l_liste).suivant;
297: (*l_liste).suivant = (*(*s_etat_processus).l_base_pile).suivant;
298: (*(*s_etat_processus).l_base_pile).suivant = l_liste;
299:
300: if (last_valide == d_vrai)
301: {
302: cf(s_etat_processus, 31);
303: }
304:
305: instruction_taylr(s_etat_processus);
306:
307: if (last_valide == d_vrai)
308: {
309: sf(s_etat_processus, 31);
310: }
311:
312: return;
313: }
314:
315:
316: /*
317: ================================================================================
318: Fonction 'mtxlock'
319: ================================================================================
320: Entrées :
321: --------------------------------------------------------------------------------
322: Sorties :
323: --------------------------------------------------------------------------------
324: Effets de bord : néant
325: ================================================================================
326: */
327:
328: void
329: instruction_mtxlock(struct_processus *s_etat_processus)
330: {
331: struct_liste_chainee *l_element_courant;
332:
333: struct_objet *s_objet_argument;
334:
335: unsigned char *tampon;
336:
337: (*s_etat_processus).erreur_execution = d_ex;
338:
339: if ((*s_etat_processus).affichage_arguments == 'Y')
340: {
341: printf("\n MTXLOCK ");
342:
343: if ((*s_etat_processus).langue == 'F')
344: {
345: printf("(verrouille un mutex)\n\n");
346: }
347: else
348: {
349: printf("(lock mutex)\n\n");
350: }
351:
352: printf(" 1: %s\n", d_MTX);
353:
354: return;
355: }
356: else if ((*s_etat_processus).test_instruction == 'Y')
357: {
358: (*s_etat_processus).nombre_arguments = -1;
359: return;
360: }
361:
362: if (test_cfsf(s_etat_processus, 31) == d_vrai)
363: {
364: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
365: {
366: return;
367: }
368: }
369:
370: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
371: &s_objet_argument) == d_erreur)
372: {
373: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
374: return;
375: }
376:
377: if ((*s_objet_argument).type == MTX)
378: {
379: l_element_courant = (*s_etat_processus).liste_mutexes;
380:
381: while(l_element_courant != NULL)
382: {
383: if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
384: .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
385: .mutex))
386: {
387: break;
388: }
389:
390: l_element_courant = (*l_element_courant).suivant;
391: }
392:
393: if (l_element_courant == NULL)
394: {
395: (*s_etat_processus).erreur_execution = d_ex_mutex;
396:
397: liberation(s_etat_processus, s_objet_argument);
398: return;
399: }
400:
401: if ((*s_etat_processus).profilage == d_vrai)
402: {
403: if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
404: == NULL)
405: {
406: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
407: return;
408: }
409:
410: profilage(s_etat_processus, tampon);
411: free(tampon);
412:
413: if ((*s_etat_processus).erreur_systeme != d_es)
414: {
415: return;
416: }
417: }
418:
1.31 ! bertrand 419: if (pthread_mutex_unlock(&((*s_etat_processus).mutex_fork)) != 0)
1.1 bertrand 420: {
421: (*s_etat_processus).erreur_systeme = d_es_processus;
422: return;
423: }
424:
425: if (pthread_mutex_lock(&((*((struct_mutex *) (*s_objet_argument).objet))
426: .mutex)) != 0)
427: {
1.31 ! bertrand 428: if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1 bertrand 429: {
1.31 ! bertrand 430: (*s_etat_processus).erreur_systeme = d_es_processus;
! 431: return;
1.1 bertrand 432: }
433:
434: liberation(s_etat_processus, s_objet_argument);
435:
436: if ((*s_etat_processus).profilage == d_vrai)
437: {
438: profilage(s_etat_processus, NULL);
439: }
440:
441: (*s_etat_processus).erreur_systeme = d_es_processus;
442: return;
443: }
444:
1.31 ! bertrand 445: if (pthread_mutex_lock(&((*s_etat_processus).mutex_fork)) != 0)
1.1 bertrand 446: {
1.31 ! bertrand 447: (*s_etat_processus).erreur_systeme = d_es_processus;
! 448: return;
1.1 bertrand 449: }
450:
451: if ((*s_etat_processus).profilage == d_vrai)
452: {
453: profilage(s_etat_processus, NULL);
454: }
455: }
456: else
457: {
458: liberation(s_etat_processus, s_objet_argument);
459:
460: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
461: return;
462: }
463:
464: liberation(s_etat_processus, s_objet_argument);
465:
466: return;
467: }
468:
469:
470: /*
471: ================================================================================
472: Fonction 'mtxtrylock'
473: ================================================================================
474: Entrées :
475: --------------------------------------------------------------------------------
476: Sorties :
477: --------------------------------------------------------------------------------
478: Effets de bord : néant
479: ================================================================================
480: */
481:
482: void
483: instruction_mtxtrylock(struct_processus *s_etat_processus)
484: {
485: int ios;
486:
487: struct_liste_chainee *l_element_courant;
488:
489: struct_objet *s_objet_argument;
490: struct_objet *s_objet_resultat;
491:
492: unsigned char *tampon;
493:
494: (*s_etat_processus).erreur_execution = d_ex;
495:
496: if ((*s_etat_processus).affichage_arguments == 'Y')
497: {
498: printf("\n MTXTRYLOCK ");
499:
500: if ((*s_etat_processus).langue == 'F')
501: {
502: printf("(essai de verrouillage du mutex)\n\n");
503: }
504: else
505: {
506: printf("(try to lock mutex)\n\n");
507: }
508:
509: printf(" 1: %s\n", d_MTX);
510: printf("-> 1: %s\n", d_INT);
511:
512: return;
513: }
514: else if ((*s_etat_processus).test_instruction == 'Y')
515: {
516: (*s_etat_processus).nombre_arguments = -1;
517: return;
518: }
519:
520: if (test_cfsf(s_etat_processus, 31) == d_vrai)
521: {
522: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
523: {
524: return;
525: }
526: }
527:
528: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
529: &s_objet_argument) == d_erreur)
530: {
531: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
532: return;
533: }
534:
535: if ((*s_objet_argument).type == MTX)
536: {
537: l_element_courant = (*s_etat_processus).liste_mutexes;
538:
539: while(l_element_courant != NULL)
540: {
541: if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
542: .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
543: .mutex))
544: {
545: break;
546: }
547:
548: l_element_courant = (*l_element_courant).suivant;
549: }
550:
551: if (l_element_courant == NULL)
552: {
553: (*s_etat_processus).erreur_execution = d_ex_mutex;
554:
555: liberation(s_etat_processus, s_objet_argument);
556: return;
557: }
558:
559: if ((*s_etat_processus).profilage == d_vrai)
560: {
561: if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
562: == NULL)
563: {
564: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
565: return;
566: }
567:
568: profilage(s_etat_processus, tampon);
569: free(tampon);
570:
571: if ((*s_etat_processus).erreur_systeme != d_es)
572: {
573: return;
574: }
575: }
576:
577: if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
578: (*s_objet_argument).objet)).mutex))) != 0)
579: {
580: if (ios != EBUSY)
581: {
582: liberation(s_etat_processus, s_objet_argument);
583:
584: if ((*s_etat_processus).profilage == d_vrai)
585: {
586: profilage(s_etat_processus, NULL);
587: }
588:
589: (*s_etat_processus).erreur_systeme = d_es_processus;
590: return;
591: }
592: }
593:
594: if ((*s_etat_processus).profilage == d_vrai)
595: {
596: profilage(s_etat_processus, NULL);
597: }
598: }
599: else
600: {
601: liberation(s_etat_processus, s_objet_argument);
602:
603: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
604: return;
605: }
606:
607: liberation(s_etat_processus, s_objet_argument);
608:
609: if ((s_objet_resultat = allocation(s_etat_processus, INT))
610: == NULL)
611: {
612: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
613: return;
614: }
615:
616: (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
617:
618: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
619: s_objet_resultat) == d_erreur)
620: {
621: return;
622: }
623:
624: return;
625: }
626:
627: /*
628: ================================================================================
629: Fonction 'mtxstatus'
630: ================================================================================
631: Entrées :
632: --------------------------------------------------------------------------------
633: Sorties :
634: --------------------------------------------------------------------------------
635: Effets de bord : néant
636: ================================================================================
637: */
638:
639: void
640: instruction_mtxstatus(struct_processus *s_etat_processus)
641: {
642: int ios;
643:
644: struct_liste_chainee *l_element_courant;
645:
646: struct_objet *s_objet_argument;
647: struct_objet *s_objet_resultat;
648:
649: unsigned char *tampon;
650:
651: (*s_etat_processus).erreur_execution = d_ex;
652:
653: if ((*s_etat_processus).affichage_arguments == 'Y')
654: {
655: printf("\n MTXSTATUS ");
656:
657: if ((*s_etat_processus).langue == 'F')
658: {
659: printf("(statut du mutex)\n\n");
660: }
661: else
662: {
663: printf("(mutex status)\n\n");
664: }
665:
666: printf(" 1: %s\n", d_MTX);
667: printf("-> 1: %s\n", d_INT);
668:
669: return;
670: }
671: else if ((*s_etat_processus).test_instruction == 'Y')
672: {
673: (*s_etat_processus).nombre_arguments = -1;
674: return;
675: }
676:
677: if (test_cfsf(s_etat_processus, 31) == d_vrai)
678: {
679: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
680: {
681: return;
682: }
683: }
684:
685: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
686: &s_objet_argument) == d_erreur)
687: {
688: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
689: return;
690: }
691:
692: if ((*s_objet_argument).type == MTX)
693: {
694: l_element_courant = (*s_etat_processus).liste_mutexes;
695:
696: while(l_element_courant != NULL)
697: {
698: if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
699: .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
700: .mutex))
701: {
702: break;
703: }
704:
705: l_element_courant = (*l_element_courant).suivant;
706: }
707:
708: if (l_element_courant == NULL)
709: {
710: (*s_etat_processus).erreur_execution = d_ex_mutex;
711:
712: liberation(s_etat_processus, s_objet_argument);
713: return;
714: }
715:
716: if ((*s_etat_processus).profilage == d_vrai)
717: {
718: if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
719: == NULL)
720: {
721: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
722: return;
723: }
724:
725: profilage(s_etat_processus, tampon);
726: free(tampon);
727:
728: if ((*s_etat_processus).erreur_systeme != d_es)
729: {
730: return;
731: }
732: }
733:
734: if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
735: (*s_objet_argument).objet)).mutex))) != 0)
736: {
737: if (ios != EBUSY)
738: {
739: liberation(s_etat_processus, s_objet_argument);
740:
741: if ((*s_etat_processus).profilage == d_vrai)
742: {
743: profilage(s_etat_processus, NULL);
744: }
745:
746: (*s_etat_processus).erreur_systeme = d_es_processus;
747: return;
748: }
749: }
750:
751: if (pthread_mutex_unlock(&((*((struct_mutex *)
752: (*s_objet_argument).objet)).mutex)) != 0)
753: {
754: liberation(s_etat_processus, s_objet_argument);
755:
756: if ((*s_etat_processus).profilage == d_vrai)
757: {
758: profilage(s_etat_processus, NULL);
759: }
760:
761: (*s_etat_processus).erreur_systeme = d_es_processus;
762: return;
763: }
764:
765: if ((*s_etat_processus).profilage == d_vrai)
766: {
767: profilage(s_etat_processus, NULL);
768: }
769: }
770: else
771: {
772: liberation(s_etat_processus, s_objet_argument);
773:
774: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
775: return;
776: }
777:
778: liberation(s_etat_processus, s_objet_argument);
779:
780: if ((s_objet_resultat = allocation(s_etat_processus, INT))
781: == NULL)
782: {
783: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
784: return;
785: }
786:
787: (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
788:
789: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
790: s_objet_resultat) == d_erreur)
791: {
792: return;
793: }
794:
795: return;
796: }
797:
798:
799: /*
800: ================================================================================
801: Fonction 'mtxunlock'
802: ================================================================================
803: Entrées :
804: --------------------------------------------------------------------------------
805: Sorties :
806: --------------------------------------------------------------------------------
807: Effets de bord : néant
808: ================================================================================
809: */
810:
811: void
812: instruction_mtxunlock(struct_processus *s_etat_processus)
813: {
814: struct_liste_chainee *l_element_courant;
815:
816: struct_objet *s_objet_argument;
817:
818: (*s_etat_processus).erreur_execution = d_ex;
819:
820: if ((*s_etat_processus).affichage_arguments == 'Y')
821: {
822: printf("\n MTXUNLOCK ");
823:
824: if ((*s_etat_processus).langue == 'F')
825: {
826: printf("(déverrouille un mutex)\n\n");
827: }
828: else
829: {
830: printf("(unlock mutex)\n\n");
831: }
832:
833: printf(" 1: %s\n", d_MTX);
834:
835: return;
836: }
837: else if ((*s_etat_processus).test_instruction == 'Y')
838: {
839: (*s_etat_processus).nombre_arguments = -1;
840: return;
841: }
842:
843: if (test_cfsf(s_etat_processus, 31) == d_vrai)
844: {
845: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
846: {
847: return;
848: }
849: }
850:
851: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
852: &s_objet_argument) == d_erreur)
853: {
854: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
855: return;
856: }
857:
858: if ((*s_objet_argument).type == MTX)
859: {
860: l_element_courant = (*s_etat_processus).liste_mutexes;
861:
862: while(l_element_courant != NULL)
863: {
864: if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
865: .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
866: .mutex))
867: {
868: break;
869: }
870:
871: l_element_courant = (*l_element_courant).suivant;
872: }
873:
874: if (l_element_courant == NULL)
875: {
876: (*s_etat_processus).erreur_execution = d_ex_mutex;
877:
878: liberation(s_etat_processus, s_objet_argument);
879: return;
880: }
881:
882: if (pthread_mutex_trylock(&((*((struct_mutex *)
883: (*s_objet_argument).objet)).mutex)) == EINVAL)
884: {
885: liberation(s_etat_processus, s_objet_argument);
886:
887: (*s_etat_processus).erreur_systeme = d_es_processus;
888: return;
889: }
890:
891: if (pthread_mutex_unlock(&((*((struct_mutex *)
892: (*s_objet_argument).objet)).mutex)) != 0)
893: {
894: liberation(s_etat_processus, s_objet_argument);
895:
896: (*s_etat_processus).erreur_systeme = d_es_processus;
897: return;
898: }
899: }
900: else
901: {
902: liberation(s_etat_processus, s_objet_argument);
903:
904: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
905: return;
906: }
907:
908: liberation(s_etat_processus, s_objet_argument);
909:
910: return;
911: }
912:
913:
914: /*
915: ================================================================================
916: Fonction 'mark'
917: ================================================================================
918: Entrées :
919: --------------------------------------------------------------------------------
920: Sorties :
921: --------------------------------------------------------------------------------
922: Effets de bord : néant
923: ================================================================================
924: */
925:
926: void
927: instruction_mark(struct_processus *s_etat_processus)
928: {
929: struct_marque *marque;
930:
931: struct_objet *s_objet_argument;
932: struct_objet *s_objet_label;
933:
934: (*s_etat_processus).erreur_execution = d_ex;
935:
936: if ((*s_etat_processus).affichage_arguments == 'Y')
937: {
938: printf("\n MARK ");
939:
940: if ((*s_etat_processus).langue == 'F')
941: {
942: printf("(ajoute une marque à un graphique)\n\n");
943: }
944: else
945: {
946: printf("(add mark to graph)\n\n");
947: }
948:
949: printf(" 2: %s\n", d_CHN);
950: printf(" 1: %s\n", d_CPL);
951:
952: return;
953: }
954: else if ((*s_etat_processus).test_instruction == 'Y')
955: {
956: (*s_etat_processus).nombre_arguments = -1;
957: return;
958: }
959:
960: if (test_cfsf(s_etat_processus, 31) == d_vrai)
961: {
962: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
963: {
964: return;
965: }
966: }
967:
968: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
969: &s_objet_argument) == d_erreur)
970: {
971: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
972: return;
973: }
974:
975: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
976: &s_objet_label) == d_erreur)
977: {
978: liberation(s_etat_processus, s_objet_argument);
979:
980: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
981: return;
982: }
983:
984: if (((*s_objet_argument).type == CPL) && ((*s_objet_label).type == CHN))
985: {
986: if ((marque = malloc(sizeof(struct_marque))) == NULL)
987: {
988: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
989: return;
990: }
991:
992: if (((*marque).label = malloc((strlen((unsigned char *)
993: (*s_objet_label).objet) + 1) * sizeof(unsigned char))) == NULL)
994: {
995: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
996: return;
997: }
998:
999: sprintf((*marque).label, "%s",
1000: (unsigned char *) (*s_objet_label).objet);
1001:
1002: if (((*marque).position = malloc(64 * sizeof(unsigned char))) == NULL)
1003: {
1004: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1005: return;
1006: }
1007:
1008: sprintf((*marque).position, "%f,%f",
1009: (*((complex16 *) (*s_objet_argument).objet)).partie_reelle,
1010: (*((complex16 *) (*s_objet_argument).objet)).partie_imaginaire);
1011:
1012: (*marque).suivant = (*s_etat_processus).s_marques;
1013: (*s_etat_processus).s_marques = marque;
1014:
1015: (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
1016: }
1017: else
1018: {
1019: liberation(s_etat_processus, s_objet_argument);
1020: liberation(s_etat_processus, s_objet_label);
1021:
1022: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1023: return;
1024: }
1025:
1026: liberation(s_etat_processus, s_objet_argument);
1027: liberation(s_etat_processus, s_objet_label);
1028:
1029: return;
1030: }
1031:
1032: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>