Annotation of rpl/src/instructions_s9.c, revision 1.41
1.1 bertrand 1: /*
2: ================================================================================
1.36 bertrand 3: RPL/2 (R) version 4.1.3
1.23 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.17 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Fonction 'sort'
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_sort(struct_processus *s_etat_processus)
40: {
41: integer8 i;
42: integer8 j;
43: integer8 nombre_elements;
44:
45: logical1 condition;
46: logical1 inversion;
47: logical1 presence_nom;
48: logical1 terminaison_boucle_1;
49: logical1 terminaison_boucle_2;
50: logical1 terminaison_boucle_3;
51: logical1 variable_partagee;
52:
53: struct_liste_chainee *l_element_courant;
54: struct_liste_chainee *l_element_precedent;
55: struct_liste_chainee *l_element_tampon;
56:
57: struct_objet *s_objet_copie;
58: struct_objet *s_objet_critere;
59: struct_objet *s_objet_liste;
1.16 bertrand 60: struct_objet *s_objet_registre;
1.1 bertrand 61: struct_objet *s_objet_test;
62:
63: signed long indice_i;
64: signed long indice_j;
65: signed long indice_k;
66: signed long indice_l;
67:
68: unsigned long ecartement;
69:
70: (*s_etat_processus).erreur_execution = d_ex;
71:
72: if ((*s_etat_processus).affichage_arguments == 'Y')
73: {
74: printf("\n SORT ");
75:
76: if ((*s_etat_processus).langue == 'F')
77: {
78: printf("(trie une liste selon un critère paramétrable)\n\n");
79: }
80: else
81: {
82: printf("(sort a list)\n\n");
83: }
84:
85: printf(" 2: %s\n", d_LST);
86: printf(" 1: %s\n", d_RPN);
87: printf("-> 1: %s\n\n", d_LST);
88:
89: printf(" 2: %s\n", d_TAB);
90: printf(" 1: %s\n", d_RPN);
91: printf("-> 1: %s\n\n", d_LST);
92:
93: printf(" 2: %s\n", d_NOM);
94: printf(" 1: %s\n", d_RPN);
95:
96: return;
97: }
98: else if ((*s_etat_processus).test_instruction == 'Y')
99: {
100: (*s_etat_processus).nombre_arguments = -1;
101: return;
102: }
103:
104: if (test_cfsf(s_etat_processus, 31) == d_vrai)
105: {
106: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
107: {
108: return;
109: }
110: }
111:
112: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
113: &s_objet_critere) == d_erreur)
114: {
115: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
116: return;
117: }
118:
119: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
120: &s_objet_liste) == d_erreur)
121: {
122: liberation(s_etat_processus, s_objet_critere);
123:
124: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
125: return;
126: }
127:
128: variable_partagee = d_faux;
129:
130: if ((*s_objet_liste).type == NOM)
131: {
132: if (recherche_variable(s_etat_processus, (*((struct_nom *)
133: (*s_objet_liste).objet)).nom) == d_faux)
134: {
135: (*s_etat_processus).erreur_systeme = d_es;
136: (*s_etat_processus).erreur_execution = d_ex_variable_non_definie;
137:
138: liberation(s_etat_processus, s_objet_critere);
139: liberation(s_etat_processus, s_objet_liste);
140:
141: return;
142: }
143:
1.27 bertrand 144: if ((*(*s_etat_processus).pointeur_variable_courante)
145: .variable_verrouillee == d_vrai)
1.1 bertrand 146: {
147: (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
148:
149: liberation(s_etat_processus, s_objet_critere);
150: liberation(s_etat_processus, s_objet_liste);
151:
152: return;
153: }
154:
1.27 bertrand 155: if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
1.1 bertrand 156: {
157: if (pthread_mutex_lock(&((*(*s_etat_processus)
158: .s_liste_variables_partagees).mutex)) != 0)
159: {
160: (*s_etat_processus).erreur_systeme = d_es_processus;
161: return;
162: }
163:
164: if (recherche_variable_partagee(s_etat_processus,
1.27 bertrand 165: (*(*s_etat_processus).pointeur_variable_courante).nom,
166: (*(*s_etat_processus).pointeur_variable_courante)
167: .variable_partagee, (*(*s_etat_processus)
168: .pointeur_variable_courante).origine) == d_faux)
1.1 bertrand 169: {
170: if (pthread_mutex_unlock(&((*(*s_etat_processus)
171: .s_liste_variables_partagees).mutex)) != 0)
172: {
173: (*s_etat_processus).erreur_systeme = d_es_processus;
174: return;
175: }
176:
177: (*s_etat_processus).erreur_execution =
178: d_ex_erreur_type_argument;
179:
180: liberation(s_etat_processus, s_objet_critere);
181: liberation(s_etat_processus, s_objet_liste);
182:
183: return;
184: }
185:
1.6 bertrand 186: if (((*(*(*s_etat_processus).s_liste_variables_partagees)
1.1 bertrand 187: .table[(*(*s_etat_processus).s_liste_variables_partagees)
1.6 bertrand 188: .position_variable].objet).type != LST) &&
189: ((*(*(*s_etat_processus).s_liste_variables_partagees)
190: .table[(*(*s_etat_processus).s_liste_variables_partagees)
191: .position_variable].objet).type != TBL))
1.1 bertrand 192: {
193: if (pthread_mutex_unlock(&((*(*s_etat_processus)
194: .s_liste_variables_partagees).mutex)) != 0)
195: {
196: (*s_etat_processus).erreur_systeme = d_es_processus;
197: return;
198: }
199:
200: (*s_etat_processus).erreur_execution =
201: d_ex_erreur_type_argument;
202:
203: liberation(s_etat_processus, s_objet_critere);
204: liberation(s_etat_processus, s_objet_liste);
205:
206: return;
207: }
208:
209: liberation(s_etat_processus, s_objet_liste);
210:
211: s_objet_liste = (*(*s_etat_processus).s_liste_variables_partagees)
212: .table[(*(*s_etat_processus).s_liste_variables_partagees)
213: .position_variable].objet;
214:
215: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
216: 'N')) == NULL)
217: {
218: if (pthread_mutex_unlock(&((*(*s_etat_processus)
219: .s_liste_variables_partagees).mutex)) != 0)
220: {
221: (*s_etat_processus).erreur_systeme = d_es_processus;
222: return;
223: }
224:
225: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
226: return;
227: }
228:
229: variable_partagee = d_vrai;
230: }
231: else
232: {
1.27 bertrand 233: if (((*(*(*s_etat_processus).pointeur_variable_courante).objet)
234: .type != LST) && ((*(*(*s_etat_processus)
235: .pointeur_variable_courante).objet).type != TBL))
1.1 bertrand 236: {
237: (*s_etat_processus).erreur_execution =
238: d_ex_erreur_type_argument;
239:
240: liberation(s_etat_processus, s_objet_critere);
241: liberation(s_etat_processus, s_objet_liste);
242:
243: return;
244: }
245:
246: liberation(s_etat_processus, s_objet_liste);
247:
1.27 bertrand 248: s_objet_liste = (*(*s_etat_processus).pointeur_variable_courante)
249: .objet;
1.1 bertrand 250:
251: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste,
252: 'N')) == NULL)
253: {
254: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
255: return;
256: }
257: }
258:
259: liberation(s_etat_processus, s_objet_liste);
260: s_objet_liste = s_objet_copie;
1.27 bertrand 261: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_liste;
1.1 bertrand 262: presence_nom = d_vrai;
263: }
264: else
265: {
266: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 'N'))
267: == NULL)
268: {
269: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
270: return;
271: }
272:
273: liberation(s_etat_processus, s_objet_liste);
274: s_objet_liste = s_objet_copie;
275: presence_nom = d_faux;
276: }
277:
278: if (((*s_objet_liste).type == LST) &&
279: ((*s_objet_critere).type == RPN))
280: {
281: /*
282: * Tri bulle de la liste chaînée. On se contente d'un tri bulle
283: * car on travaille sur une liste chaînée et non sur un tableau
284: * sur lequel on pourrait accéder directement aux données grâce à
285: * leur indice.
286: */
287:
288: nombre_elements = 0;
289: l_element_courant = (*s_objet_liste).objet;
290:
291: while(l_element_courant != NULL)
292: {
293: l_element_courant = (*l_element_courant).suivant;
294: nombre_elements++;
295: }
296:
297: // Si la liste est vide, on considère qu'elle est triée.
298: // De la même manière, on considère qu'une liste d'un
299: // seul élément est toujours triée.
300:
301: if (nombre_elements > 1)
302: {
303: j = nombre_elements;
304:
305: do
306: {
307: inversion = d_faux;
308:
309: l_element_courant = (*s_objet_liste).objet;
310: l_element_precedent = NULL;
311:
312: for(i = 0; i < j - 1; i++)
313: {
314: // Test des éléments adjacents. Pour cela, on
315: // empile les deux éléments adjacents dans la pile dans
316: // l'ordre [i] [i+1] et on évalue le critère d'ordre.
317:
318: if ((s_objet_copie = copie_objet(s_etat_processus,
319: (*l_element_courant).donnee, 'P')) == NULL)
320: {
321: (*s_etat_processus).erreur_systeme =
322: d_es_allocation_memoire;
323: return;
324: }
325:
326: if (empilement(s_etat_processus,
327: &((*s_etat_processus).l_base_pile),
328: s_objet_copie) == d_erreur)
329: {
330: return;
331: }
332:
333: if ((s_objet_copie = copie_objet(s_etat_processus,
334: (*(*l_element_courant)
335: .suivant).donnee, 'P')) == NULL)
336: {
337: (*s_etat_processus).erreur_systeme =
338: d_es_allocation_memoire;
339: return;
340: }
341:
342: if (empilement(s_etat_processus,
343: &((*s_etat_processus).l_base_pile),
344: s_objet_copie) == d_erreur)
345: {
346: return;
347: }
348:
349: if (evaluation(s_etat_processus, s_objet_critere, 'N')
350: == d_erreur)
351: {
352: liberation(s_etat_processus, s_objet_critere);
353: liberation(s_etat_processus, s_objet_liste);
354:
355: return;
356: }
357:
358: if (depilement(s_etat_processus,
359: &((*s_etat_processus).l_base_pile), &s_objet_test)
360: == d_erreur)
361: {
362: liberation(s_etat_processus, s_objet_critere);
363: liberation(s_etat_processus, s_objet_liste);
364:
365: (*s_etat_processus).erreur_execution =
366: d_ex_manque_argument;
367: return;
368: }
369:
370: if ((*s_objet_test).type == INT)
371: {
372: condition = ((*((integer8 *) (*s_objet_test).objet))
373: == 0) ? d_faux : d_vrai;
374: }
375: else if ((*s_objet_test).type == REL)
376: {
377: condition = ((*((real8 *) (*s_objet_test).objet))
378: == 0) ? d_faux : d_vrai;
379: }
380: else
381: {
382: liberation(s_etat_processus, s_objet_critere);
383: liberation(s_etat_processus, s_objet_liste);
384: liberation(s_etat_processus, s_objet_test);
385:
386: (*s_etat_processus).erreur_execution =
387: d_ex_erreur_type_argument;
388: return;
389: }
390:
391: liberation(s_etat_processus, s_objet_test);
392:
393: if (condition == d_faux)
394: {
395: // On échange les deux éléments adjacents
396:
397: inversion = d_vrai;
398:
399: if (l_element_precedent == NULL)
400: {
401: // Échange des deux premiers éléments
402: // de la liste.
403:
404: l_element_tampon = (*(*l_element_courant)
405: .suivant).suivant;
406: (*s_objet_liste).objet = (*l_element_courant)
407: .suivant;
408: (*((struct_liste_chainee *) (*s_objet_liste)
409: .objet)).suivant = l_element_courant;
410: (*l_element_courant).suivant =
411: l_element_tampon;
412: l_element_courant = (*s_objet_liste).objet;
413: }
414: else
415: {
416: // Échange de deux éléments quelconques de la
417: // liste.
418:
419: l_element_tampon = (*l_element_courant).suivant;
420: (*l_element_courant).suivant =
421: (*(*l_element_courant).suivant).suivant;
422: (*l_element_precedent).suivant = l_element_tampon;
423: (*l_element_tampon).suivant = l_element_courant;
424:
425: l_element_courant = l_element_tampon;
426: }
427: }
428:
429: l_element_precedent = l_element_courant;
430: l_element_courant = (*l_element_courant).suivant;
431: }
432:
433: j--;
434: } while(inversion != d_faux);
435: }
436: }
437: else if (((*s_objet_liste).type == TBL) &&
438: ((*s_objet_critere).type == RPN))
439: {
440: /*
441: * Tri Shell-Metzner d'une table
442: */
443:
444: ecartement = (*((struct_tableau *) (*s_objet_liste).objet))
445: .nombre_elements;
446: terminaison_boucle_1 = d_faux;
447:
448: do
449: {
450: ecartement = ecartement / 2;
451:
452: if (ecartement >= 1)
453: {
454: indice_j = 0;
455: indice_k = (*((struct_tableau *) (*s_objet_liste).objet))
456: .nombre_elements - ecartement;
457: terminaison_boucle_2 = d_faux;
458:
459: do
460: {
461: indice_i = indice_j;
462: terminaison_boucle_3 = d_faux;
463:
464: do
465: {
466: indice_l = indice_i + ecartement;
467:
468: if ((indice_i > 0) && (indice_l > 0))
469: {
470: if ((s_objet_copie = copie_objet(s_etat_processus,
471: (*((struct_tableau *) (*s_objet_liste)
472: .objet)).elements[indice_i - 1], 'P'))
473: == NULL)
474: {
475: (*s_etat_processus).erreur_systeme =
476: d_es_allocation_memoire;
477: return;
478: }
479:
480: if (empilement(s_etat_processus,
481: &((*s_etat_processus).l_base_pile),
482: s_objet_copie) == d_erreur)
483: {
484: return;
485: }
486:
487: if ((s_objet_copie = copie_objet(s_etat_processus,
488: (*((struct_tableau *) (*s_objet_liste)
489: .objet)).elements[indice_l - 1], 'P'))
490: == NULL)
491: {
492: (*s_etat_processus).erreur_systeme =
493: d_es_allocation_memoire;
494: return;
495: }
496:
497: if (empilement(s_etat_processus,
498: &((*s_etat_processus).l_base_pile),
499: s_objet_copie) == d_erreur)
500: {
501: return;
502: }
503:
504: if (evaluation(s_etat_processus, s_objet_critere,
505: 'N') == d_erreur)
506: {
507: liberation(s_etat_processus, s_objet_critere);
508: liberation(s_etat_processus, s_objet_liste);
509:
510: return;
511: }
512:
513: if (depilement(s_etat_processus,
514: &((*s_etat_processus).l_base_pile),
515: &s_objet_test) == d_erreur)
516: {
517: liberation(s_etat_processus, s_objet_critere);
518: liberation(s_etat_processus, s_objet_liste);
519:
520: (*s_etat_processus).erreur_execution =
521: d_ex_manque_argument;
522: return;
523: }
524:
525: if ((*s_objet_test).type == INT)
526: {
527: condition = ((*((integer8 *) (*s_objet_test)
528: .objet)) == 0) ? d_faux : d_vrai;
529: }
530: else if ((*s_objet_test).type == REL)
531: {
532: condition = ((*((real8 *) (*s_objet_test)
533: .objet)) == 0) ? d_faux : d_vrai;
534: }
535: else
536: {
537: liberation(s_etat_processus, s_objet_critere);
538: liberation(s_etat_processus, s_objet_liste);
539: liberation(s_etat_processus, s_objet_test);
540:
541: (*s_etat_processus).erreur_execution =
542: d_ex_erreur_type_argument;
543: return;
544: }
545:
546: liberation(s_etat_processus, s_objet_test);
547:
548: if (condition == d_faux)
549: {
1.16 bertrand 550: s_objet_registre =
551: (*((struct_tableau *)
1.14 bertrand 552: (*s_objet_liste).objet)).elements
1.16 bertrand 553: [indice_i - 1];
554: (*((struct_tableau *) (*s_objet_liste).objet))
555: .elements[indice_i - 1] =
556: (*((struct_tableau *) (*s_objet_liste)
557: .objet)).elements[indice_l - 1];
558: (*((struct_tableau *) (*s_objet_liste)
559: .objet)).elements[indice_l - 1] =
560: s_objet_registre;
1.1 bertrand 561:
562: indice_i -= ecartement;
563:
564: if (indice_i < 1)
565: {
566: terminaison_boucle_3 = d_vrai;
567: }
568: }
569: else
570: {
571: terminaison_boucle_3 = d_vrai;
572: }
573: }
574: else
575: {
576: terminaison_boucle_3 = d_vrai;
577: }
578: } while(terminaison_boucle_3 == d_faux);
579:
580: indice_j++;
581:
582: if (indice_j > indice_k)
583: {
584: terminaison_boucle_2 = d_vrai;
585: }
586: } while(terminaison_boucle_2 == d_faux);
587: }
588: else
589: {
590: terminaison_boucle_1 = d_vrai;
591: }
592: } while(terminaison_boucle_1 == d_faux);
593: }
594: else
595: {
596: if (pthread_mutex_unlock(&((*(*s_etat_processus)
597: .s_liste_variables_partagees).mutex)) != 0)
598: {
599: (*s_etat_processus).erreur_systeme = d_es_processus;
600: return;
601: }
602:
603: liberation(s_etat_processus, s_objet_liste);
604: liberation(s_etat_processus, s_objet_critere);
605:
606: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
607: return;
608: }
609:
610: if (presence_nom == d_faux)
611: {
612: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
613: s_objet_liste) == d_erreur)
614: {
615: return;
616: }
617: }
618: else
619: {
620: if (variable_partagee == d_vrai)
621: {
622: (*(*s_etat_processus).s_liste_variables_partagees)
623: .table[(*(*s_etat_processus).s_liste_variables_partagees)
624: .position_variable].objet = s_objet_liste;
625:
626: if (pthread_mutex_unlock(&((*(*s_etat_processus)
627: .s_liste_variables_partagees).mutex)) != 0)
628: {
629: (*s_etat_processus).erreur_systeme = d_es_processus;
630: return;
631: }
632: }
633: }
634:
635: liberation(s_etat_processus, s_objet_critere);
636:
637: return;
638: }
639:
640:
641: /*
642: ================================================================================
643: Fonction 'save'
644: ================================================================================
645: Entrées : structure processus
646: --------------------------------------------------------------------------------
647: Sorties :
648: --------------------------------------------------------------------------------
649: Effets de bord : néant
650: ================================================================================
651: */
652:
653: void
654: instruction_save(struct_processus *s_etat_processus)
655: {
656: struct_objet *s_objet_1;
657: struct_objet *s_objet_2;
658:
659: struct_variable s_variable;
660:
661: (*s_etat_processus).erreur_execution = d_ex;
662:
663: if ((*s_etat_processus).affichage_arguments == 'Y')
664: {
665: printf("\n SAVE ");
666:
667: if ((*s_etat_processus).langue == 'F')
668: {
669: printf("(affecte un objet à une variable globale)\n\n");
670: }
671: else
672: {
673: printf("(store an object in a global variable)\n\n");
674: }
675:
676: printf(" 2: %s, %s, %s, %s, %s, %s,\n"
677: " %s, %s, %s, %s, %s,\n"
678: " %s, %s, %s, %s, %s,\n"
679: " %s, %s, %s, %s,\n"
680: " %s, %s\n",
681: d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX,
682: d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK,
683: d_SQL, d_SLB, d_PRC, d_MTX);
684: printf(" 1: %s\n", d_NOM);
685:
686: return;
687: }
688: else if ((*s_etat_processus).test_instruction == 'Y')
689: {
690: (*s_etat_processus).nombre_arguments = -1;
691: return;
692: }
693:
694: if (test_cfsf(s_etat_processus, 31) == d_vrai)
695: {
696: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
697: {
698: return;
699: }
700: }
701:
702: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
703: &s_objet_1) == d_erreur)
704: {
705: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
706: return;
707: }
708:
709: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
710: &s_objet_2) == d_erreur)
711: {
712: liberation(s_etat_processus, s_objet_1);
713:
714: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
715: return;
716: }
717:
718: if ((*s_objet_1).type != NOM)
719: {
720: liberation(s_etat_processus, s_objet_1);
721: liberation(s_etat_processus, s_objet_2);
722:
723: (*s_etat_processus).erreur_execution = d_ex_nom_invalide;
724: return;
725: }
726:
1.27 bertrand 727: if (recherche_variable_globale(s_etat_processus, (*((struct_nom *)
1.1 bertrand 728: (*s_objet_1).objet)).nom) == d_vrai)
729: {
730: /*
1.27 bertrand 731: * Une variable est accessible.
1.1 bertrand 732: */
733:
1.27 bertrand 734: if ((*(*s_etat_processus).pointeur_variable_courante)
735: .variable_verrouillee == d_vrai)
1.1 bertrand 736: {
1.27 bertrand 737: liberation(s_etat_processus, s_objet_1);
738: liberation(s_etat_processus, s_objet_2);
1.1 bertrand 739:
1.27 bertrand 740: (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
741: return;
742: }
1.1 bertrand 743:
1.27 bertrand 744: if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
745: {
746: liberation(s_etat_processus, s_objet_1);
747: liberation(s_etat_processus, s_objet_2);
1.1 bertrand 748:
1.27 bertrand 749: (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
750: return;
1.1 bertrand 751: }
752:
1.27 bertrand 753: liberation(s_etat_processus,
754: (*(*s_etat_processus).pointeur_variable_courante).objet);
755: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_2;
1.1 bertrand 756: }
757: else
758: {
759: /*
760: * Aucune variable n'est accessible (ni locale, ni globale).
761: */
762:
763: if ((s_variable.nom = malloc((strlen((*((struct_nom *)
764: (*s_objet_1).objet)).nom) + 1) * sizeof(unsigned char)))
765: == NULL)
766: {
767: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
768: return;
769: }
770:
771: strcpy(s_variable.nom, (*((struct_nom *) (*s_objet_1).objet)).nom);
772: s_variable.niveau = 1;
773:
774: /*
775: * Le niveau 0 correspond aux définitions. Les variables
776: * commencent à 1 car elles sont toujours incluses dans
777: * une définition.
778: */
779:
780: s_variable.objet = s_objet_2;
781:
782: if (creation_variable(s_etat_processus, &s_variable, 'V', 'P')
783: == d_erreur)
784: {
785: return;
786: }
787:
788: (*s_etat_processus).erreur_systeme = d_es;
789: }
790:
791: liberation(s_etat_processus, s_objet_1);
792:
793: return;
794: }
795:
796:
797: /*
798: ================================================================================
799: Fonction 'suspend'
800: ================================================================================
801: Entrées : structure processus
802: --------------------------------------------------------------------------------
803: Sorties :
804: --------------------------------------------------------------------------------
805: Effets de bord : néant
806: ================================================================================
807: */
808:
809: void
810: instruction_suspend(struct_processus *s_etat_processus)
811: {
1.37 bertrand 812: struct timespec attente;
1.1 bertrand 813:
814: (*s_etat_processus).erreur_execution = d_ex;
815:
816: if ((*s_etat_processus).affichage_arguments == 'Y')
817: {
818: printf("\n SUSPEND ");
819:
820: if ((*s_etat_processus).langue == 'F')
821: {
1.37 bertrand 822: printf("(attend un signal RPL/SIGCONT)\n\n");
1.1 bertrand 823: printf(" Aucun argument\n");
824: }
825: else
826: {
1.37 bertrand 827: printf("(wait for RPL/SIGCONT signal)\n\n");
1.1 bertrand 828: printf(" No argument\n");
829: }
830:
831: return;
832: }
833: else if ((*s_etat_processus).test_instruction == 'Y')
834: {
835: (*s_etat_processus).nombre_arguments = -1;
836: return;
837: }
838:
839: if (test_cfsf(s_etat_processus, 31) == d_vrai)
840: {
841: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
842: {
843: return;
844: }
845: }
846:
847: if ((*s_etat_processus).profilage == d_vrai)
848: {
849: profilage(s_etat_processus, "Suspend");
850:
851: if ((*s_etat_processus).erreur_systeme != d_es)
852: {
853: return;
854: }
855: }
856:
1.40 bertrand 857: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 858: {
859: (*s_etat_processus).erreur_systeme = d_es_processus;
860: return;
861: }
862:
1.37 bertrand 863: for((*s_etat_processus).redemarrage_processus = d_faux;;)
864: {
865: scrutation_interruptions(s_etat_processus);
866:
867: if ((*s_etat_processus).redemarrage_processus == d_vrai)
868: {
869: break;
870: }
871:
872: nanosleep(&attente, NULL);
873: INCR_GRANULARITE(attente.tv_nsec);
874: }
1.1 bertrand 875:
1.41 ! bertrand 876: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 877: {
1.41 ! bertrand 878: if (errno != EINTR)
! 879: {
! 880: (*s_etat_processus).erreur_systeme = d_es_processus;
! 881: return;
! 882: }
1.1 bertrand 883: }
884:
885: if ((*s_etat_processus).profilage == d_vrai)
886: {
887: profilage(s_etat_processus, NULL);
888: }
889:
890: return;
891: }
892:
893:
894: /*
895: ================================================================================
896: Fonction 'static'
897: ================================================================================
898: Entrées : structure processus
899: --------------------------------------------------------------------------------
900: Sorties :
901: --------------------------------------------------------------------------------
902: Effets de bord : néant
903: ================================================================================
904: */
905:
906: void
907: instruction_static(struct_processus *s_etat_processus)
908: {
909: (*s_etat_processus).erreur_execution = d_ex;
910:
911: if ((*s_etat_processus).affichage_arguments == 'Y')
912: {
913: printf("\n STATIC ");
914:
915: if ((*s_etat_processus).langue == 'F')
916: {
917: printf("(déclaration de variables statiques)\n\n");
918: printf(" Aucun argument\n");
919: }
920: else
921: {
922: printf("(static variables declaration)\n\n");
923: printf(" No argument\n");
924: }
925:
926: return;
927: }
928: else if ((*s_etat_processus).test_instruction == 'Y')
929: {
930: (*s_etat_processus).nombre_arguments = -1;
931: return;
932: }
933:
934: if (test_cfsf(s_etat_processus, 31) == d_vrai)
935: {
936: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
937: {
938: return;
939: }
940: }
941:
942: if ((*s_etat_processus).creation_variables_partagees == d_vrai)
943: {
944: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
945: return;
946: }
947:
948: (*s_etat_processus).creation_variables_statiques = d_vrai;
949:
950: return;
951: }
952:
953:
954: /*
955: ================================================================================
956: Fonction 'shared'
957: ================================================================================
958: Entrées : structure processus
959: --------------------------------------------------------------------------------
960: Sorties :
961: --------------------------------------------------------------------------------
962: Effets de bord : néant
963: ================================================================================
964: */
965:
966: void
967: instruction_shared(struct_processus *s_etat_processus)
968: {
969: (*s_etat_processus).erreur_execution = d_ex;
970:
971: if ((*s_etat_processus).affichage_arguments == 'Y')
972: {
973: printf("\n SHARED ");
974:
975: if ((*s_etat_processus).langue == 'F')
976: {
977: printf("(déclaration de variables partagées)\n\n");
978: printf(" Aucun argument\n");
979: }
980: else
981: {
982: printf("(shared variables declaration)\n\n");
983: printf(" No argument\n");
984: }
985:
986: return;
987: }
988: else if ((*s_etat_processus).test_instruction == 'Y')
989: {
990: (*s_etat_processus).nombre_arguments = -1;
991: return;
992: }
993:
994: if (test_cfsf(s_etat_processus, 31) == d_vrai)
995: {
996: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
997: {
998: return;
999: }
1000: }
1001:
1002: if ((*s_etat_processus).creation_variables_partagees == d_vrai)
1003: {
1004: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
1005: return;
1006: }
1007:
1008: (*s_etat_processus).creation_variables_partagees = d_vrai;
1009:
1010: return;
1011: }
1012:
1013:
1014: /*
1015: ================================================================================
1016: Fonction 'stoswi'
1017: ================================================================================
1018: Entrées : structure processus
1019: --------------------------------------------------------------------------------
1020: Sorties :
1021: --------------------------------------------------------------------------------
1022: Effets de bord : néant
1023: ================================================================================
1024: */
1025:
1026: void
1027: instruction_stoswi(struct_processus *s_etat_processus)
1028: {
1029: integer8 interruption;
1030:
1031: struct_objet *s_objet_argument_1;
1032: struct_objet *s_objet_argument_2;
1033:
1034: (*s_etat_processus).erreur_execution = d_ex;
1035:
1036: if ((*s_etat_processus).affichage_arguments == 'Y')
1037: {
1038: printf("\n STOSWI ");
1039:
1040: if ((*s_etat_processus).langue == 'F')
1041: {
1042: printf("(définition d'une interruption logicielle)\n\n");
1043: }
1044: else
1045: {
1046: printf("(software interrupt definition)\n\n");
1047: }
1048:
1049: printf(" 2: %s, %s\n", d_NOM, d_RPN);
1050: printf(" 1: %s\n", d_INT);
1051:
1052: return;
1053: }
1054: else if ((*s_etat_processus).test_instruction == 'Y')
1055: {
1056: (*s_etat_processus).nombre_arguments = -1;
1057: return;
1058: }
1059:
1060: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1061: {
1062: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
1063: {
1064: return;
1065: }
1066: }
1067:
1068: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1069: &s_objet_argument_1) == d_erreur)
1070: {
1071: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1072: return;
1073: }
1074:
1075: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1076: &s_objet_argument_2) == d_erreur)
1077: {
1078: liberation(s_etat_processus, s_objet_argument_1);
1079:
1080: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1081: return;
1082: }
1083:
1084: if ((*s_objet_argument_1).type == INT)
1085: {
1086: interruption = (*((integer8 *) (*s_objet_argument_1).objet));
1087:
1088: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1089: {
1090: liberation(s_etat_processus, s_objet_argument_1);
1091: liberation(s_etat_processus, s_objet_argument_2);
1092:
1093: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1094: return;
1095: }
1096:
1097: if ((*s_objet_argument_2).type == NOM)
1098: {
1099: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
1100: [interruption - 1]);
1101: (*s_etat_processus).corps_interruptions[interruption - 1] =
1102: s_objet_argument_2;
1103: }
1104: else if((*s_objet_argument_2).type == RPN)
1105: {
1106: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
1107: [interruption - 1]);
1108: (*s_etat_processus).corps_interruptions[interruption - 1] =
1109: s_objet_argument_2;
1110: }
1111: else
1112: {
1113: liberation(s_etat_processus, s_objet_argument_1);
1114: liberation(s_etat_processus, s_objet_argument_2);
1115:
1116: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1117: return;
1118: }
1119: }
1120: else
1121: {
1122: liberation(s_etat_processus, s_objet_argument_1);
1123: liberation(s_etat_processus, s_objet_argument_2);
1124:
1125: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1126: return;
1127: }
1128:
1129: liberation(s_etat_processus, s_objet_argument_1);
1130:
1131: return;
1132: }
1133:
1134:
1135: /*
1136: ================================================================================
1137: Fonction 'swi'
1138: ================================================================================
1139: Entrées : structure processus
1140: --------------------------------------------------------------------------------
1141: Sorties :
1142: --------------------------------------------------------------------------------
1143: Effets de bord : néant
1144: ================================================================================
1145: */
1146:
1147: void
1148: instruction_swi(struct_processus *s_etat_processus)
1149: {
1150: int interruption_reduite;
1151:
1152: integer8 interruption;
1153:
1154: pid_t pid;
1155:
1156: pthread_t tid;
1157:
1158: sig_atomic_t registre;
1159:
1160: ssize_t longueur_ecriture;
1161:
1162: struct_objet *s_objet_argument;
1163:
1164: struct timespec attente;
1165:
1166: unsigned char tampon;
1167:
1168: (*s_etat_processus).erreur_execution = d_ex;
1169:
1170: if ((*s_etat_processus).affichage_arguments == 'Y')
1171: {
1172: printf("\n SWI ");
1173:
1174: if ((*s_etat_processus).langue == 'F')
1175: {
1176: printf("(interruption logicielle)\n\n");
1177: }
1178: else
1179: {
1180: printf("(software interrupt)\n\n");
1181: }
1182:
1183: printf(" 1: %s\n", d_INT);
1184:
1185: return;
1186: }
1187: else if ((*s_etat_processus).test_instruction == 'Y')
1188: {
1189: (*s_etat_processus).nombre_arguments = -1;
1190: return;
1191: }
1192:
1193: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1194: {
1195: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
1196: {
1197: return;
1198: }
1199: }
1200:
1201: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1202: &s_objet_argument) == d_erreur)
1203: {
1204: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1205: return;
1206: }
1207:
1208: if ((*s_objet_argument).type == INT)
1209: {
1210: interruption = (*((integer8 *) (*s_objet_argument).objet));
1211:
1212: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1213: {
1214: liberation(s_etat_processus, s_objet_argument);
1215:
1216: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1217: return;
1218: }
1219:
1220: if ((*s_etat_processus).presence_pipes == d_faux)
1221: {
1222: liberation(s_etat_processus, s_objet_argument);
1223:
1224: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
1225: return;
1226: }
1227:
1228: // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
1229: // de surveillance.
1230:
1231: registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
1232: (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
1233:
1234: if ((*s_etat_processus).processus_detache == d_vrai)
1235: {
1236: pid = -1;
1237:
1238: attente.tv_sec = 0;
1239: attente.tv_nsec = GRANULARITE_us * 1000;
1240:
1.40 bertrand 1241: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1242: {
1243: (*s_etat_processus).erreur_systeme = d_es_processus;
1244: return;
1245: }
1.1 bertrand 1246:
1247: while((longueur_ecriture = write_atomic(s_etat_processus,
1248: (*s_etat_processus).pipe_nombre_objets_attente,
1249: &pid, sizeof(pid))) != sizeof(pid))
1250: {
1.41 ! bertrand 1251: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1252: {
1.41 ! bertrand 1253: if (errno != EINTR)
! 1254: {
! 1255: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1256: return;
! 1257: }
1.1 bertrand 1258: }
1259:
1260: if (longueur_ecriture == -1)
1261: {
1262: if (registre == 0)
1263: {
1264: if ((*s_etat_processus)
1265: .var_volatile_traitement_retarde_stop == -1)
1266: {
1267: (*s_etat_processus).var_volatile_requete_arret = -1;
1268: }
1269:
1270: (*s_etat_processus)
1271: .var_volatile_traitement_retarde_stop
1272: = registre;
1273: }
1274:
1275: (*s_etat_processus).erreur_systeme = d_es_processus;
1276: return;
1277: }
1278:
1279: nanosleep(&attente, NULL);
1280: INCR_GRANULARITE(attente.tv_nsec);
1281:
1.40 bertrand 1282: if (sem_post(&((*s_etat_processus).semaphore_fork))
1.38 bertrand 1283: != 0)
1.1 bertrand 1284: {
1285: (*s_etat_processus).erreur_systeme = d_es_processus;
1286: return;
1287: }
1288: }
1289:
1.39 bertrand 1290: scrutation_interruptions(s_etat_processus);
1291:
1.41 ! bertrand 1292: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1293: {
1.41 ! bertrand 1294: if (errno != EINTR)
! 1295: {
! 1296: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1297: return;
! 1298: }
1.1 bertrand 1299: }
1300: }
1301: else
1302: {
1303: tid = -1;
1304:
1305: attente.tv_sec = 0;
1306: attente.tv_nsec = GRANULARITE_us * 1000;
1307:
1.40 bertrand 1308: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1309: {
1310: (*s_etat_processus).erreur_systeme = d_es_processus;
1311: return;
1312: }
1313:
1314: while((longueur_ecriture = write_atomic(s_etat_processus,
1315: (*s_etat_processus).pipe_nombre_objets_attente,
1316: &tid, sizeof(tid))) != sizeof(tid))
1317: {
1.41 ! bertrand 1318: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1319: {
1.41 ! bertrand 1320: if (errno != EINTR)
! 1321: {
! 1322: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1323: return;
! 1324: }
1.1 bertrand 1325: }
1326:
1327: if (longueur_ecriture == -1)
1328: {
1329: if (registre == 0)
1330: {
1331: if ((*s_etat_processus)
1332: .var_volatile_traitement_retarde_stop == -1)
1333: {
1334: (*s_etat_processus).var_volatile_requete_arret = -1;
1335: }
1336:
1337: (*s_etat_processus)
1338: .var_volatile_traitement_retarde_stop
1339: = registre;
1340: }
1341:
1342: (*s_etat_processus).erreur_systeme = d_es_processus;
1343: return;
1344: }
1345:
1346: nanosleep(&attente, NULL);
1347: INCR_GRANULARITE(attente.tv_nsec);
1348:
1.40 bertrand 1349: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1350: {
1351: (*s_etat_processus).erreur_systeme = d_es_processus;
1352: return;
1353: }
1354: }
1355:
1.39 bertrand 1356: scrutation_interruptions(s_etat_processus);
1357:
1.41 ! bertrand 1358: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1359: {
1.41 ! bertrand 1360: if (errno != EINTR)
! 1361: {
! 1362: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1363: return;
! 1364: }
1.1 bertrand 1365: }
1366: }
1367:
1368: interruption_reduite = interruption;
1369:
1370: attente.tv_sec = 0;
1371: attente.tv_nsec = GRANULARITE_us * 1000;
1372:
1.40 bertrand 1373: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1374: {
1375: (*s_etat_processus).erreur_systeme = d_es_processus;
1376: return;
1377: }
1.1 bertrand 1378:
1379: while((longueur_ecriture = write_atomic(s_etat_processus,
1380: (*s_etat_processus).pipe_interruptions,
1381: &interruption_reduite, sizeof(interruption_reduite)))
1382: != sizeof(interruption_reduite))
1383: {
1.41 ! bertrand 1384: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1385: {
1.41 ! bertrand 1386: if (errno != EINTR)
! 1387: {
! 1388: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1389: return;
! 1390: }
1.1 bertrand 1391: }
1392:
1393: if (longueur_ecriture == -1)
1394: {
1395: if (registre == 0)
1396: {
1397: if ((*s_etat_processus)
1398: .var_volatile_traitement_retarde_stop == -1)
1399: {
1400: (*s_etat_processus).var_volatile_requete_arret = -1;
1401: }
1402:
1403: (*s_etat_processus)
1404: .var_volatile_traitement_retarde_stop
1405: = registre;
1406: }
1407:
1408: (*s_etat_processus).erreur_systeme = d_es_processus;
1409: return;
1410: }
1411:
1412: nanosleep(&attente, NULL);
1413: INCR_GRANULARITE(attente.tv_nsec);
1414:
1.40 bertrand 1415: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1416: {
1417: (*s_etat_processus).erreur_systeme = d_es_processus;
1418: return;
1419: }
1.39 bertrand 1420:
1421: scrutation_interruptions(s_etat_processus);
1.1 bertrand 1422: }
1423:
1.41 ! bertrand 1424: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1425: {
1.41 ! bertrand 1426: if (errno != EINTR)
! 1427: {
! 1428: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1429: return;
! 1430: }
1.1 bertrand 1431: }
1432:
1433: if ((*s_etat_processus).processus_detache == d_vrai)
1434: {
1435: pid = -3;
1436:
1437: attente.tv_sec = 0;
1438: attente.tv_nsec = GRANULARITE_us * 1000;
1439:
1.40 bertrand 1440: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1441: {
1442: (*s_etat_processus).erreur_systeme = d_es_processus;
1443: return;
1444: }
1.1 bertrand 1445:
1446: while((longueur_ecriture = write_atomic(s_etat_processus,
1447: (*s_etat_processus).pipe_nombre_interruptions_attente,
1448: &pid, sizeof(pid))) != sizeof(pid))
1449: {
1.41 ! bertrand 1450: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1451: {
1.41 ! bertrand 1452: if (errno != EINTR)
! 1453: {
! 1454: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1455: return;
! 1456: }
1.1 bertrand 1457: }
1458:
1459: if (longueur_ecriture == -1)
1460: {
1461: if (registre == 0)
1462: {
1463: if ((*s_etat_processus)
1464: .var_volatile_traitement_retarde_stop == -1)
1465: {
1466: (*s_etat_processus).var_volatile_requete_arret = -1;
1467: }
1468:
1469: (*s_etat_processus)
1470: .var_volatile_traitement_retarde_stop
1471: = registre;
1472: }
1473:
1474: (*s_etat_processus).erreur_systeme = d_es_processus;
1475: return;
1476: }
1477:
1478: nanosleep(&attente, NULL);
1479: INCR_GRANULARITE(attente.tv_nsec);
1480:
1.40 bertrand 1481: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1482: {
1483: (*s_etat_processus).erreur_systeme = d_es_processus;
1484: return;
1485: }
1.39 bertrand 1486:
1487: scrutation_interruptions(s_etat_processus);
1.1 bertrand 1488: }
1489:
1490: pid = getpid();
1491:
1492: attente.tv_sec = 0;
1493: attente.tv_nsec = GRANULARITE_us * 1000;
1494:
1495: while((longueur_ecriture = write_atomic(s_etat_processus,
1496: (*s_etat_processus).pipe_nombre_interruptions_attente,
1497: &pid, sizeof(pid))) != sizeof(pid))
1498: {
1.41 ! bertrand 1499: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1500: {
1.41 ! bertrand 1501: if (errno != EINTR)
! 1502: {
! 1503: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1504: return;
! 1505: }
1.1 bertrand 1506: }
1507:
1508: if (longueur_ecriture == -1)
1509: {
1510: if (registre == 0)
1511: {
1512: if ((*s_etat_processus)
1513: .var_volatile_traitement_retarde_stop == -1)
1514: {
1515: (*s_etat_processus).var_volatile_requete_arret = -1;
1516: }
1517:
1518: (*s_etat_processus)
1519: .var_volatile_traitement_retarde_stop
1520: = registre;
1521: }
1522:
1523: (*s_etat_processus).erreur_systeme = d_es_processus;
1524: return;
1525: }
1526:
1527: nanosleep(&attente, NULL);
1528: INCR_GRANULARITE(attente.tv_nsec);
1529:
1.40 bertrand 1530: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1531: {
1532: (*s_etat_processus).erreur_systeme = d_es_processus;
1533: return;
1534: }
1.1 bertrand 1535: }
1536:
1.41 ! bertrand 1537: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1538: {
1.41 ! bertrand 1539: if (errno != EINTR)
! 1540: {
! 1541: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1542: return;
! 1543: }
1.1 bertrand 1544: }
1545: }
1546: else
1547: {
1548: tid = -3;
1549:
1.40 bertrand 1550: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1551: {
1552: (*s_etat_processus).erreur_systeme = d_es_processus;
1553: return;
1554: }
1.1 bertrand 1555:
1556: while((longueur_ecriture = write_atomic(s_etat_processus,
1557: (*s_etat_processus).pipe_nombre_interruptions_attente,
1558: &tid, sizeof(tid))) != sizeof(tid))
1559: {
1.41 ! bertrand 1560: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1561: {
1.41 ! bertrand 1562: if (errno != EINTR)
! 1563: {
! 1564: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1565: return;
! 1566: }
1.1 bertrand 1567: }
1568:
1569: if (longueur_ecriture == -1)
1570: {
1571: if (registre == 0)
1572: {
1573: if ((*s_etat_processus)
1574: .var_volatile_traitement_retarde_stop == -1)
1575: {
1576: (*s_etat_processus).var_volatile_requete_arret = -1;
1577: }
1578:
1579: (*s_etat_processus)
1580: .var_volatile_traitement_retarde_stop
1581: = registre;
1582: }
1583:
1584: (*s_etat_processus).erreur_systeme = d_es_processus;
1585: return;
1586: }
1587:
1588: nanosleep(&attente, NULL);
1589: INCR_GRANULARITE(attente.tv_nsec);
1590:
1.40 bertrand 1591: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1592: {
1593: (*s_etat_processus).erreur_systeme = d_es_processus;
1594: return;
1595: }
1.39 bertrand 1596:
1597: scrutation_interruptions(s_etat_processus);
1.1 bertrand 1598: }
1599:
1600: tid = pthread_self();
1601:
1602: attente.tv_sec = 0;
1603: attente.tv_nsec = GRANULARITE_us * 1000;
1604:
1605: while((longueur_ecriture = write_atomic(s_etat_processus,
1606: (*s_etat_processus).pipe_nombre_interruptions_attente,
1607: &tid, sizeof(tid))) != sizeof(tid))
1608: {
1.41 ! bertrand 1609: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1610: {
1.41 ! bertrand 1611: if (errno != EINTR)
! 1612: {
! 1613: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1614: return;
! 1615: }
1.1 bertrand 1616: }
1617:
1618: if (longueur_ecriture == -1)
1619:
1620: {
1621: if (registre == 0)
1622: {
1623: if ((*s_etat_processus)
1624: .var_volatile_traitement_retarde_stop == -1)
1625: {
1626: (*s_etat_processus).var_volatile_requete_arret = -1;
1627: }
1628:
1629: (*s_etat_processus)
1630: .var_volatile_traitement_retarde_stop
1631: = registre;
1632: }
1633:
1634: (*s_etat_processus).erreur_systeme = d_es_processus;
1635: return;
1636: }
1637:
1638: nanosleep(&attente, NULL);
1639: INCR_GRANULARITE(attente.tv_nsec);
1640:
1.40 bertrand 1641: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1642: {
1643: (*s_etat_processus).erreur_systeme = d_es_processus;
1644: return;
1645: }
1.39 bertrand 1646:
1647: scrutation_interruptions(s_etat_processus);
1.1 bertrand 1648: }
1649:
1.41 ! bertrand 1650: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1651: {
1.41 ! bertrand 1652: if (errno != EINTR)
! 1653: {
! 1654: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1655: return;
! 1656: }
1.1 bertrand 1657: }
1658: }
1659:
1660: attente.tv_sec = 0;
1661: attente.tv_nsec = GRANULARITE_us * 1000;
1662:
1.40 bertrand 1663: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1664: {
1665: (*s_etat_processus).erreur_systeme = d_es_processus;
1666: return;
1667: }
1668:
1669: while(read_atomic(s_etat_processus,
1670: (*s_etat_processus).pipe_acquittement,
1671: &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
1672: {
1.41 ! bertrand 1673: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1674: {
1.41 ! bertrand 1675: if (errno != EINTR)
! 1676: {
! 1677: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1678: return;
! 1679: }
1.1 bertrand 1680: }
1681:
1682: nanosleep(&attente, NULL);
1683: INCR_GRANULARITE(attente.tv_nsec);
1684:
1.40 bertrand 1685: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1686: {
1687: (*s_etat_processus).erreur_systeme = d_es_processus;
1688: return;
1689: }
1.39 bertrand 1690:
1691: scrutation_interruptions(s_etat_processus);
1.1 bertrand 1692: }
1693:
1.41 ! bertrand 1694: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1 bertrand 1695: {
1.41 ! bertrand 1696: if (errno != EINTR)
! 1697: {
! 1698: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1699: return;
! 1700: }
1.1 bertrand 1701: }
1702:
1703: if (registre == 0)
1704: {
1705: if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
1706: {
1707: (*s_etat_processus).var_volatile_requete_arret = -1;
1708: }
1709:
1710: (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
1711: }
1712: }
1713: else
1714: {
1715: liberation(s_etat_processus, s_objet_argument);
1716:
1717: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1718: return;
1719: }
1720:
1721: liberation(s_etat_processus, s_objet_argument);
1722:
1723: return;
1724: }
1725:
1726:
1727: /*
1728: ================================================================================
1729: Fonction 'swilock'
1730: ================================================================================
1731: Entrées : structure processus
1732: --------------------------------------------------------------------------------
1733: Sorties :
1734: --------------------------------------------------------------------------------
1735: Effets de bord : néant
1736: ================================================================================
1737: */
1738:
1739: void
1740: instruction_swilock(struct_processus *s_etat_processus)
1741: {
1742: integer8 interruption;
1743:
1744: struct_liste_chainee *l_element_courant;
1745:
1746: struct_objet *s_objet_argument;
1747:
1748: (*s_etat_processus).erreur_execution = d_ex;
1749:
1750: if ((*s_etat_processus).affichage_arguments == 'Y')
1751: {
1752: printf("\n SWILOCK ");
1753:
1754: if ((*s_etat_processus).langue == 'F')
1755: {
1756: printf("(verrouillage des interruptions logicielles)\n\n");
1757: }
1758: else
1759: {
1760: printf("(software interrupt lock)\n\n");
1761: }
1762:
1763: printf(" 1: %s, %s\n", d_INT, d_LST);
1764:
1765: return;
1766: }
1767: else if ((*s_etat_processus).test_instruction == 'Y')
1768: {
1769: (*s_etat_processus).nombre_arguments = -1;
1770: return;
1771: }
1772:
1773: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1774: {
1775: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
1776: {
1777: return;
1778: }
1779: }
1780:
1781: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1782: &s_objet_argument) == d_erreur)
1783: {
1784: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1785: return;
1786: }
1787:
1788: if ((*s_objet_argument).type == INT)
1789: {
1790: interruption = (*((integer8 *) (*s_objet_argument).objet));
1791:
1792: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1793: {
1794: liberation(s_etat_processus, s_objet_argument);
1795:
1796: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1797: return;
1798: }
1799:
1800: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
1801: }
1802: else if ((*s_objet_argument).type == LST)
1803: {
1804: l_element_courant = (*s_objet_argument).objet;
1805:
1806: while(l_element_courant)
1807: {
1808: if ((*(*l_element_courant).donnee).type != INT)
1809: {
1810: liberation(s_etat_processus, s_objet_argument);
1811:
1812: (*s_etat_processus).erreur_execution =
1813: d_ex_erreur_type_argument;
1814: return;
1815: }
1816:
1817: interruption = (*((integer8 *) (*(*l_element_courant)
1818: .donnee).objet));
1819:
1820: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1821: {
1822: liberation(s_etat_processus, s_objet_argument);
1823:
1824: (*s_etat_processus).erreur_execution =
1825: d_ex_interruption_invalide;
1826: return;
1827: }
1828:
1829: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
1830: l_element_courant = (*l_element_courant).suivant;
1831: }
1832: }
1833: else
1834: {
1835: liberation(s_etat_processus, s_objet_argument);
1836:
1837: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1838: return;
1839: }
1840:
1841: liberation(s_etat_processus, s_objet_argument);
1842:
1843: return;
1844: }
1845:
1846:
1847: /*
1848: ================================================================================
1849: Fonction 'swistatus'
1850: ================================================================================
1851: Entrées : structure processus
1852: --------------------------------------------------------------------------------
1853: Sorties :
1854: --------------------------------------------------------------------------------
1855: Effets de bord : néant
1856: ================================================================================
1857: */
1858:
1859: void
1860: instruction_swistatus(struct_processus *s_etat_processus)
1861: {
1862: int i;
1863:
1864: struct_liste_chainee *l_element_courant;
1865: struct_liste_chainee *l_element_futur;
1866: struct_liste_chainee *l_element_liste;
1867:
1868: struct_objet *s_objet_resultat;
1869:
1870: (*s_etat_processus).erreur_execution = d_ex;
1871:
1872: if ((*s_etat_processus).affichage_arguments == 'Y')
1873: {
1874: printf("\n SWISTATUS ");
1875:
1876: if ((*s_etat_processus).langue == 'F')
1877: {
1878: printf("(état des interruptions logicielles)\n\n");
1879: }
1880: else
1881: {
1882: printf("(software interrupts status)\n\n");
1883: }
1884:
1885: printf("-> 1: %s\n\n", d_LST);
1886:
1887: if ((*s_etat_processus).langue == 'F')
1888: {
1889: printf(" Utilisation :\n\n");
1890: }
1891: else
1892: {
1893: printf(" Usage:\n\n");
1894: }
1895:
1896: printf(" { { initialized interrupts }\n"
1897: " { unlocked interrupts }\n"
1898: " { queued interrupts }\n"
1899: " { locked interrupts } }\n");
1900: return;
1901: }
1902: else if ((*s_etat_processus).test_instruction == 'Y')
1903: {
1904: (*s_etat_processus).nombre_arguments = -1;
1905: return;
1906: }
1907:
1908: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1909: {
1910: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
1911: {
1912: return;
1913: }
1914: }
1915:
1916: if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
1917: {
1918: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1919: return;
1920: }
1921:
1922: if (((*s_objet_resultat).objet =
1923: allocation_maillon(s_etat_processus)) == NULL)
1924: {
1925: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1926: return;
1927: }
1928:
1929: l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
1930:
1931: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
1932: == NULL)
1933: {
1934: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1935: return;
1936: }
1937:
1938: l_element_liste = NULL;
1939: l_element_futur = NULL;
1940:
1941: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
1942: {
1943: if ((*s_etat_processus).corps_interruptions[i] != NULL)
1944: {
1945: if (l_element_liste == NULL)
1946: {
1947: if ((l_element_liste =
1948: allocation_maillon(s_etat_processus)) == NULL)
1949: {
1950: (*s_etat_processus).erreur_systeme =
1951: d_es_allocation_memoire;
1952: return;
1953: }
1954:
1955: l_element_futur = l_element_liste;
1956: }
1957: else
1958: {
1959: if (((*l_element_liste).suivant =
1960: allocation_maillon(s_etat_processus)) == NULL)
1961: {
1962: (*s_etat_processus).erreur_systeme =
1963: d_es_allocation_memoire;
1964: return;
1965: }
1966:
1967: l_element_liste = (*l_element_liste).suivant;
1968: }
1969:
1970: (*l_element_liste).suivant = NULL;
1971:
1972: if (((*l_element_liste).donnee = allocation(s_etat_processus,
1973: INT)) == NULL)
1974: {
1975: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1976: return;
1977: }
1978:
1979: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
1980: }
1981: }
1982:
1983: (*(*l_element_courant).donnee).objet = l_element_futur;
1984:
1985: if (((*l_element_courant).suivant =
1986: allocation_maillon(s_etat_processus)) == NULL)
1987: {
1988: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1989: return;
1990: }
1991:
1992: l_element_courant = (*l_element_courant).suivant;
1993:
1994: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
1995: == NULL)
1996: {
1997: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1998: return;
1999: }
2000:
2001: l_element_liste = NULL;
2002: l_element_futur = NULL;
2003:
2004: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2005: {
2006: if ((*s_etat_processus).masque_interruptions[i] == 'N')
2007: {
2008: if (l_element_liste == NULL)
2009: {
2010: if ((l_element_liste =
2011: allocation_maillon(s_etat_processus)) == NULL)
2012: {
2013: (*s_etat_processus).erreur_systeme =
2014: d_es_allocation_memoire;
2015: return;
2016: }
2017:
2018: l_element_futur = l_element_liste;
2019: }
2020: else
2021: {
2022: if (((*l_element_liste).suivant =
2023: allocation_maillon(s_etat_processus)) == NULL)
2024: {
2025: (*s_etat_processus).erreur_systeme =
2026: d_es_allocation_memoire;
2027: return;
2028: }
2029:
2030: l_element_liste = (*l_element_liste).suivant;
2031: }
2032:
2033: (*l_element_liste).suivant = NULL;
2034:
2035: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2036: INT)) == NULL)
2037: {
2038: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2039: return;
2040: }
2041:
2042: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2043: }
2044: }
2045:
2046: (*(*l_element_courant).donnee).objet = l_element_futur;
2047:
2048: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2049: == NULL)
2050: {
2051: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2052: return;
2053: }
2054:
2055: l_element_courant = (*l_element_courant).suivant;
2056:
2057: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2058: == NULL)
2059: {
2060: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2061: return;
2062: }
2063:
2064: l_element_liste = NULL;
2065: l_element_futur = NULL;
2066:
2067: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2068: {
2069: if ((*s_etat_processus).masque_interruptions[i] == 'Q')
2070: {
2071: if (l_element_liste == NULL)
2072: {
2073: if ((l_element_liste =
2074: allocation_maillon(s_etat_processus)) == NULL)
2075: {
2076: (*s_etat_processus).erreur_systeme =
2077: d_es_allocation_memoire;
2078: return;
2079: }
2080:
2081: l_element_futur = l_element_liste;
2082: }
2083: else
2084: {
2085: if (((*l_element_liste).suivant =
2086: allocation_maillon(s_etat_processus)) == NULL)
2087: {
2088: (*s_etat_processus).erreur_systeme =
2089: d_es_allocation_memoire;
2090: return;
2091: }
2092:
2093: l_element_liste = (*l_element_liste).suivant;
2094: }
2095:
2096: (*l_element_liste).suivant = NULL;
2097:
2098: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2099: INT)) == NULL)
2100: {
2101: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2102: return;
2103: }
2104:
2105: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2106: }
2107: }
2108:
2109: (*(*l_element_courant).donnee).objet = l_element_futur;
2110:
2111: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2112: == NULL)
2113: {
2114: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2115: return;
2116: }
2117:
2118: l_element_courant = (*l_element_courant).suivant;
2119:
2120: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2121: == NULL)
2122: {
2123: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2124: return;
2125: }
2126:
2127: l_element_liste = NULL;
2128: l_element_futur = NULL;
2129:
2130: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2131: {
2132: if ((*s_etat_processus).masque_interruptions[i] == 'I')
2133: {
2134: if (l_element_liste == NULL)
2135: {
2136: if ((l_element_liste =
2137: allocation_maillon(s_etat_processus)) == NULL)
2138: {
2139: (*s_etat_processus).erreur_systeme =
2140: d_es_allocation_memoire;
2141: return;
2142: }
2143:
2144: l_element_futur = l_element_liste;
2145: }
2146: else
2147: {
2148: if (((*l_element_liste).suivant =
2149: allocation_maillon(s_etat_processus)) == NULL)
2150: {
2151: (*s_etat_processus).erreur_systeme =
2152: d_es_allocation_memoire;
2153: return;
2154: }
2155:
2156: l_element_liste = (*l_element_liste).suivant;
2157: }
2158:
2159: (*l_element_liste).suivant = NULL;
2160:
2161: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2162: INT)) == NULL)
2163: {
2164: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2165: return;
2166: }
2167:
2168: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2169: }
2170: }
2171:
2172: (*(*l_element_courant).donnee).objet = l_element_futur;
2173:
2174: (*l_element_courant).suivant = NULL;
2175:
2176: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2177: s_objet_resultat) == d_erreur)
2178: {
2179: return;
2180: }
2181:
2182: return;
2183: }
2184:
2185:
2186: /*
2187: ================================================================================
2188: Fonction 'swiunlock'
2189: ================================================================================
2190: Entrées : structure processus
2191: --------------------------------------------------------------------------------
2192: Sorties :
2193: --------------------------------------------------------------------------------
2194: Effets de bord : néant
2195: ================================================================================
2196: */
2197:
2198: void
2199: instruction_swiunlock(struct_processus *s_etat_processus)
2200: {
2201: integer8 interruption;
2202:
2203: struct_liste_chainee *l_element_courant;
2204:
2205: struct_objet *s_objet_argument;
2206:
2207: (*s_etat_processus).erreur_execution = d_ex;
2208:
2209: if ((*s_etat_processus).affichage_arguments == 'Y')
2210: {
2211: printf("\n SWIUNLOCK ");
2212:
2213: if ((*s_etat_processus).langue == 'F')
2214: {
2215: printf("(déverrouillage des interruptions logicielles)\n\n");
2216: }
2217: else
2218: {
2219: printf("(software interrupt unlock)\n\n");
2220: }
2221:
2222: printf(" 1: %s, %s\n", d_INT, d_LST);
2223:
2224: return;
2225: }
2226: else if ((*s_etat_processus).test_instruction == 'Y')
2227: {
2228: (*s_etat_processus).nombre_arguments = -1;
2229: return;
2230: }
2231:
2232: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2233: {
2234: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2235: {
2236: return;
2237: }
2238: }
2239:
2240: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2241: &s_objet_argument) == d_erreur)
2242: {
2243: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2244: return;
2245: }
2246:
2247: if ((*s_objet_argument).type == INT)
2248: {
2249: interruption = (*((integer8 *) (*s_objet_argument).objet));
2250:
2251: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2252: {
2253: liberation(s_etat_processus, s_objet_argument);
2254:
2255: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2256: return;
2257: }
2258:
2259: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2260: }
2261: else if ((*s_objet_argument).type == LST)
2262: {
2263: l_element_courant = (*s_objet_argument).objet;
2264:
2265: while(l_element_courant)
2266: {
2267: if ((*(*l_element_courant).donnee).type != INT)
2268: {
2269: liberation(s_etat_processus, s_objet_argument);
2270:
2271: (*s_etat_processus).erreur_execution =
2272: d_ex_erreur_type_argument;
2273: return;
2274: }
2275:
2276: interruption = (*((integer8 *) (*(*l_element_courant)
2277: .donnee).objet));
2278:
2279: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2280: {
2281: liberation(s_etat_processus, s_objet_argument);
2282:
2283: (*s_etat_processus).erreur_execution =
2284: d_ex_interruption_invalide;
2285: return;
2286: }
2287:
2288: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2289: l_element_courant = (*l_element_courant).suivant;
2290: }
2291: }
2292: else
2293: {
2294: liberation(s_etat_processus, s_objet_argument);
2295:
2296: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2297: return;
2298: }
2299:
2300: liberation(s_etat_processus, s_objet_argument);
2301:
2302: return;
2303: }
2304:
2305:
2306: /*
2307: ================================================================================
2308: Fonction 'swiqueue'
2309: ================================================================================
2310: Entrées : structure processus
2311: --------------------------------------------------------------------------------
2312: Sorties :
2313: --------------------------------------------------------------------------------
2314: Effets de bord : néant
2315: ================================================================================
2316: */
2317:
2318: void
2319: instruction_swiqueue(struct_processus *s_etat_processus)
2320: {
2321: integer8 interruption;
2322:
2323: struct_liste_chainee *l_element_courant;
2324:
2325: struct_objet *s_objet_argument;
2326:
2327: (*s_etat_processus).erreur_execution = d_ex;
2328:
2329: if ((*s_etat_processus).affichage_arguments == 'Y')
2330: {
2331: printf("\n SWIQUEUE ");
2332:
2333: if ((*s_etat_processus).langue == 'F')
2334: {
2335: printf("(enregistre des interruptions logicielles)\n\n");
2336: }
2337: else
2338: {
2339: printf("(software interrupt record)\n\n");
2340: }
2341:
2342: printf(" 1: %s, %s\n", d_INT, d_LST);
2343:
2344: return;
2345: }
2346: else if ((*s_etat_processus).test_instruction == 'Y')
2347: {
2348: (*s_etat_processus).nombre_arguments = -1;
2349: return;
2350: }
2351:
2352: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2353: {
2354: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2355: {
2356: return;
2357: }
2358: }
2359:
2360: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2361: &s_objet_argument) == d_erreur)
2362: {
2363: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2364: return;
2365: }
2366:
2367: if ((*s_objet_argument).type == INT)
2368: {
2369: interruption = (*((integer8 *) (*s_objet_argument).objet));
2370:
2371: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2372: {
2373: liberation(s_etat_processus, s_objet_argument);
2374:
2375: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2376: return;
2377: }
2378:
2379: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2380: }
2381: else if ((*s_objet_argument).type == LST)
2382: {
2383: l_element_courant = (*s_objet_argument).objet;
2384:
2385: while(l_element_courant)
2386: {
2387: if ((*(*l_element_courant).donnee).type != INT)
2388: {
2389: liberation(s_etat_processus, s_objet_argument);
2390:
2391: (*s_etat_processus).erreur_execution =
2392: d_ex_erreur_type_argument;
2393: return;
2394: }
2395:
2396: interruption = (*((integer8 *) (*(*l_element_courant)
2397: .donnee).objet));
2398:
2399: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2400: {
2401: liberation(s_etat_processus, s_objet_argument);
2402:
2403: (*s_etat_processus).erreur_execution =
2404: d_ex_interruption_invalide;
2405: return;
2406: }
2407:
2408: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2409: l_element_courant = (*l_element_courant).suivant;
2410: }
2411: }
2412: else
2413: {
2414: liberation(s_etat_processus, s_objet_argument);
2415:
2416: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2417: return;
2418: }
2419:
2420: liberation(s_etat_processus, s_objet_argument);
2421:
2422: return;
2423: }
2424:
2425:
2426: /*
2427: ================================================================================
2428: Fonction 'sched'
2429: ================================================================================
2430: Entrées : structure processus
2431: --------------------------------------------------------------------------------
2432: Sorties :
2433: --------------------------------------------------------------------------------
2434: Effets de bord : néant
2435: ================================================================================
2436: */
2437:
2438: void
2439: instruction_sched(struct_processus *s_etat_processus)
2440: {
2441: real8 pourcentage;
2442:
2443: struct_objet *s_objet_argument;
2444:
2445: (*s_etat_processus).erreur_execution = d_ex;
2446:
2447: if ((*s_etat_processus).affichage_arguments == 'Y')
2448: {
2449: printf("\n SCHED ");
2450:
2451: if ((*s_etat_processus).langue == 'F')
2452: {
2453: printf("(limitation des ressources de calcul)\n\n");
2454: }
2455: else
2456: {
2457: printf("(CPU ressources limitation)\n\n");
2458: }
2459:
2460: printf(" 1: %s, %s\n", d_INT, d_REL);
2461:
2462: return;
2463: }
2464: else if ((*s_etat_processus).test_instruction == 'Y')
2465: {
2466: (*s_etat_processus).nombre_arguments = -1;
2467: return;
2468: }
2469:
2470: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2471: {
2472: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2473: {
2474: return;
2475: }
2476: }
2477:
2478: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2479: &s_objet_argument) == d_erreur)
2480: {
2481: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2482: return;
2483: }
2484:
2485: if ((*s_objet_argument).type == INT)
2486: {
2487: pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
2488: }
2489: else if ((*s_objet_argument).type == REL)
2490: {
2491: pourcentage = (*((real8 *) (*s_objet_argument).objet));
2492: }
2493: else
2494: {
2495: liberation(s_etat_processus, s_objet_argument);
2496:
2497: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2498: return;
2499: }
2500:
2501: liberation(s_etat_processus, s_objet_argument);
2502:
2503: if ((pourcentage <= 0) || (pourcentage > 100))
2504: {
2505: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
2506: return;
2507: }
2508:
2509: (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
2510:
2511: return;
2512: }
2513:
2514: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>