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