1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.4
4: Copyright (C) 1989-2011 Dr. BERTRAND Joël
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:
23: #include "rpl-conv.h"
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;
60: struct_objet *s_objet_registre;
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:
144: if ((*(*s_etat_processus).pointeur_variable_courante)
145: .variable_verrouillee == d_vrai)
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:
155: if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL)
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,
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)
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:
186: if (((*(*(*s_etat_processus).s_liste_variables_partagees)
187: .table[(*(*s_etat_processus).s_liste_variables_partagees)
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))
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: {
233: if (((*(*(*s_etat_processus).pointeur_variable_courante).objet)
234: .type != LST) && ((*(*(*s_etat_processus)
235: .pointeur_variable_courante).objet).type != TBL))
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:
248: s_objet_liste = (*(*s_etat_processus).pointeur_variable_courante)
249: .objet;
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;
261: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_liste;
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: {
550: s_objet_registre =
551: (*((struct_tableau *)
552: (*s_objet_liste).objet)).elements
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;
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:
727: if (recherche_variable_globale(s_etat_processus, (*((struct_nom *)
728: (*s_objet_1).objet)).nom) == d_vrai)
729: {
730: /*
731: * Une variable est accessible.
732: */
733:
734: if ((*(*s_etat_processus).pointeur_variable_courante)
735: .variable_verrouillee == d_vrai)
736: {
737: liberation(s_etat_processus, s_objet_1);
738: liberation(s_etat_processus, s_objet_2);
739:
740: (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee;
741: return;
742: }
743:
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);
748:
749: (*s_etat_processus).erreur_execution = d_ex_variable_partagee;
750: return;
751: }
752:
753: liberation(s_etat_processus,
754: (*(*s_etat_processus).pointeur_variable_courante).objet);
755: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_2;
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: {
812: struct timespec attente;
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: {
822: printf("(attend un signal RPL/SIGCONT)\n\n");
823: printf(" Aucun argument\n");
824: }
825: else
826: {
827: printf("(wait for RPL/SIGCONT signal)\n\n");
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:
857: # ifndef SEMAPHORES_NOMMES
858: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
859: # else
860: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
861: # endif
862: {
863: (*s_etat_processus).erreur_systeme = d_es_processus;
864: return;
865: }
866:
867: for((*s_etat_processus).redemarrage_processus = d_faux;;)
868: {
869: scrutation_interruptions(s_etat_processus);
870:
871: if ((*s_etat_processus).redemarrage_processus == d_vrai)
872: {
873: break;
874: }
875:
876: nanosleep(&attente, NULL);
877: INCR_GRANULARITE(attente.tv_nsec);
878: }
879:
880: # ifndef SEMAPHORES_NOMMES
881: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
882: # else
883: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
884: # endif
885: {
886: if (errno != EINTR)
887: {
888: (*s_etat_processus).erreur_systeme = d_es_processus;
889: return;
890: }
891: }
892:
893: if ((*s_etat_processus).profilage == d_vrai)
894: {
895: profilage(s_etat_processus, NULL);
896: }
897:
898: return;
899: }
900:
901:
902: /*
903: ================================================================================
904: Fonction 'static'
905: ================================================================================
906: Entrées : structure processus
907: --------------------------------------------------------------------------------
908: Sorties :
909: --------------------------------------------------------------------------------
910: Effets de bord : néant
911: ================================================================================
912: */
913:
914: void
915: instruction_static(struct_processus *s_etat_processus)
916: {
917: (*s_etat_processus).erreur_execution = d_ex;
918:
919: if ((*s_etat_processus).affichage_arguments == 'Y')
920: {
921: printf("\n STATIC ");
922:
923: if ((*s_etat_processus).langue == 'F')
924: {
925: printf("(déclaration de variables statiques)\n\n");
926: printf(" Aucun argument\n");
927: }
928: else
929: {
930: printf("(static variables declaration)\n\n");
931: printf(" No argument\n");
932: }
933:
934: return;
935: }
936: else if ((*s_etat_processus).test_instruction == 'Y')
937: {
938: (*s_etat_processus).nombre_arguments = -1;
939: return;
940: }
941:
942: if (test_cfsf(s_etat_processus, 31) == d_vrai)
943: {
944: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
945: {
946: return;
947: }
948: }
949:
950: if ((*s_etat_processus).creation_variables_partagees == d_vrai)
951: {
952: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
953: return;
954: }
955:
956: (*s_etat_processus).creation_variables_statiques = d_vrai;
957:
958: return;
959: }
960:
961:
962: /*
963: ================================================================================
964: Fonction 'shared'
965: ================================================================================
966: Entrées : structure processus
967: --------------------------------------------------------------------------------
968: Sorties :
969: --------------------------------------------------------------------------------
970: Effets de bord : néant
971: ================================================================================
972: */
973:
974: void
975: instruction_shared(struct_processus *s_etat_processus)
976: {
977: (*s_etat_processus).erreur_execution = d_ex;
978:
979: if ((*s_etat_processus).affichage_arguments == 'Y')
980: {
981: printf("\n SHARED ");
982:
983: if ((*s_etat_processus).langue == 'F')
984: {
985: printf("(déclaration de variables partagées)\n\n");
986: printf(" Aucun argument\n");
987: }
988: else
989: {
990: printf("(shared variables declaration)\n\n");
991: printf(" No argument\n");
992: }
993:
994: return;
995: }
996: else if ((*s_etat_processus).test_instruction == 'Y')
997: {
998: (*s_etat_processus).nombre_arguments = -1;
999: return;
1000: }
1001:
1002: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1003: {
1004: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
1005: {
1006: return;
1007: }
1008: }
1009:
1010: if ((*s_etat_processus).creation_variables_partagees == d_vrai)
1011: {
1012: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee;
1013: return;
1014: }
1015:
1016: (*s_etat_processus).creation_variables_partagees = d_vrai;
1017:
1018: return;
1019: }
1020:
1021:
1022: /*
1023: ================================================================================
1024: Fonction 'stoswi'
1025: ================================================================================
1026: Entrées : structure processus
1027: --------------------------------------------------------------------------------
1028: Sorties :
1029: --------------------------------------------------------------------------------
1030: Effets de bord : néant
1031: ================================================================================
1032: */
1033:
1034: void
1035: instruction_stoswi(struct_processus *s_etat_processus)
1036: {
1037: integer8 interruption;
1038:
1039: struct_objet *s_objet_argument_1;
1040: struct_objet *s_objet_argument_2;
1041:
1042: (*s_etat_processus).erreur_execution = d_ex;
1043:
1044: if ((*s_etat_processus).affichage_arguments == 'Y')
1045: {
1046: printf("\n STOSWI ");
1047:
1048: if ((*s_etat_processus).langue == 'F')
1049: {
1050: printf("(définition d'une interruption logicielle)\n\n");
1051: }
1052: else
1053: {
1054: printf("(software interrupt definition)\n\n");
1055: }
1056:
1057: printf(" 2: %s, %s\n", d_NOM, d_RPN);
1058: printf(" 1: %s\n", d_INT);
1059:
1060: return;
1061: }
1062: else if ((*s_etat_processus).test_instruction == 'Y')
1063: {
1064: (*s_etat_processus).nombre_arguments = -1;
1065: return;
1066: }
1067:
1068: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1069: {
1070: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
1071: {
1072: return;
1073: }
1074: }
1075:
1076: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1077: &s_objet_argument_1) == d_erreur)
1078: {
1079: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1080: return;
1081: }
1082:
1083: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1084: &s_objet_argument_2) == d_erreur)
1085: {
1086: liberation(s_etat_processus, s_objet_argument_1);
1087:
1088: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1089: return;
1090: }
1091:
1092: if ((*s_objet_argument_1).type == INT)
1093: {
1094: interruption = (*((integer8 *) (*s_objet_argument_1).objet));
1095:
1096: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1097: {
1098: liberation(s_etat_processus, s_objet_argument_1);
1099: liberation(s_etat_processus, s_objet_argument_2);
1100:
1101: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1102: return;
1103: }
1104:
1105: if ((*s_objet_argument_2).type == NOM)
1106: {
1107: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
1108: [interruption - 1]);
1109: (*s_etat_processus).corps_interruptions[interruption - 1] =
1110: s_objet_argument_2;
1111: }
1112: else if((*s_objet_argument_2).type == RPN)
1113: {
1114: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions
1115: [interruption - 1]);
1116: (*s_etat_processus).corps_interruptions[interruption - 1] =
1117: s_objet_argument_2;
1118: }
1119: else
1120: {
1121: liberation(s_etat_processus, s_objet_argument_1);
1122: liberation(s_etat_processus, s_objet_argument_2);
1123:
1124: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1125: return;
1126: }
1127: }
1128: else
1129: {
1130: liberation(s_etat_processus, s_objet_argument_1);
1131: liberation(s_etat_processus, s_objet_argument_2);
1132:
1133: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1134: return;
1135: }
1136:
1137: liberation(s_etat_processus, s_objet_argument_1);
1138:
1139: return;
1140: }
1141:
1142:
1143: /*
1144: ================================================================================
1145: Fonction 'swi'
1146: ================================================================================
1147: Entrées : structure processus
1148: --------------------------------------------------------------------------------
1149: Sorties :
1150: --------------------------------------------------------------------------------
1151: Effets de bord : néant
1152: ================================================================================
1153: */
1154:
1155: void
1156: instruction_swi(struct_processus *s_etat_processus)
1157: {
1158: int interruption_reduite;
1159:
1160: integer8 interruption;
1161:
1162: pid_t pid;
1163:
1164: pthread_t tid;
1165:
1166: sig_atomic_t registre;
1167:
1168: ssize_t longueur_ecriture;
1169:
1170: struct_objet *s_objet_argument;
1171:
1172: struct timespec attente;
1173:
1174: unsigned char tampon;
1175:
1176: (*s_etat_processus).erreur_execution = d_ex;
1177:
1178: if ((*s_etat_processus).affichage_arguments == 'Y')
1179: {
1180: printf("\n SWI ");
1181:
1182: if ((*s_etat_processus).langue == 'F')
1183: {
1184: printf("(interruption logicielle)\n\n");
1185: }
1186: else
1187: {
1188: printf("(software interrupt)\n\n");
1189: }
1190:
1191: printf(" 1: %s\n", d_INT);
1192:
1193: return;
1194: }
1195: else if ((*s_etat_processus).test_instruction == 'Y')
1196: {
1197: (*s_etat_processus).nombre_arguments = -1;
1198: return;
1199: }
1200:
1201: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1202: {
1203: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
1204: {
1205: return;
1206: }
1207: }
1208:
1209: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1210: &s_objet_argument) == d_erreur)
1211: {
1212: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1213: return;
1214: }
1215:
1216: if ((*s_objet_argument).type == INT)
1217: {
1218: interruption = (*((integer8 *) (*s_objet_argument).objet));
1219:
1220: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1221: {
1222: liberation(s_etat_processus, s_objet_argument);
1223:
1224: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1225: return;
1226: }
1227:
1228: if ((*s_etat_processus).presence_pipes == d_faux)
1229: {
1230: liberation(s_etat_processus, s_objet_argument);
1231:
1232: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere;
1233: return;
1234: }
1235:
1236: // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread
1237: // de surveillance.
1238:
1239: registre = (*s_etat_processus).var_volatile_traitement_retarde_stop;
1240: (*s_etat_processus).var_volatile_traitement_retarde_stop = 1;
1241:
1242: if ((*s_etat_processus).processus_detache == d_vrai)
1243: {
1244: pid = -1;
1245:
1246: attente.tv_sec = 0;
1247: attente.tv_nsec = GRANULARITE_us * 1000;
1248:
1249: # ifndef SEMAPHORES_NOMMES
1250: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1251: # else
1252: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1253: # endif
1254: {
1255: (*s_etat_processus).erreur_systeme = d_es_processus;
1256: return;
1257: }
1258:
1259: while((longueur_ecriture = write_atomic(s_etat_processus,
1260: (*s_etat_processus).pipe_nombre_objets_attente,
1261: &pid, sizeof(pid))) != sizeof(pid))
1262: {
1263: # ifndef SEMAPHORES_NOMMES
1264: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1265: # else
1266: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1267: # endif
1268: {
1269: if (errno != EINTR)
1270: {
1271: (*s_etat_processus).erreur_systeme = d_es_processus;
1272: return;
1273: }
1274: }
1275:
1276: if (longueur_ecriture == -1)
1277: {
1278: if (registre == 0)
1279: {
1280: if ((*s_etat_processus)
1281: .var_volatile_traitement_retarde_stop == -1)
1282: {
1283: (*s_etat_processus).var_volatile_requete_arret = -1;
1284: }
1285:
1286: (*s_etat_processus)
1287: .var_volatile_traitement_retarde_stop
1288: = registre;
1289: }
1290:
1291: (*s_etat_processus).erreur_systeme = d_es_processus;
1292: return;
1293: }
1294:
1295: nanosleep(&attente, NULL);
1296: INCR_GRANULARITE(attente.tv_nsec);
1297:
1298: # ifndef SEMAPHORES_NOMMES
1299: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1300: # else
1301: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1302: # endif
1303: {
1304: (*s_etat_processus).erreur_systeme = d_es_processus;
1305: return;
1306: }
1307: }
1308:
1309: scrutation_interruptions(s_etat_processus);
1310:
1311: # ifndef SEMAPHORES_NOMMES
1312: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1313: # else
1314: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1315: # endif
1316: {
1317: if (errno != EINTR)
1318: {
1319: (*s_etat_processus).erreur_systeme = d_es_processus;
1320: return;
1321: }
1322: }
1323: }
1324: else
1325: {
1326: tid = -1;
1327:
1328: attente.tv_sec = 0;
1329: attente.tv_nsec = GRANULARITE_us * 1000;
1330:
1331: # ifndef SEMAPHORES_NOMMES
1332: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1333: # else
1334: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1335: # endif
1336: {
1337: (*s_etat_processus).erreur_systeme = d_es_processus;
1338: return;
1339: }
1340:
1341: while((longueur_ecriture = write_atomic(s_etat_processus,
1342: (*s_etat_processus).pipe_nombre_objets_attente,
1343: &tid, sizeof(tid))) != sizeof(tid))
1344: {
1345: # ifndef SEMAPHORES_NOMMES
1346: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1347: # else
1348: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1349: # endif
1350: {
1351: if (errno != EINTR)
1352: {
1353: (*s_etat_processus).erreur_systeme = d_es_processus;
1354: return;
1355: }
1356: }
1357:
1358: if (longueur_ecriture == -1)
1359: {
1360: if (registre == 0)
1361: {
1362: if ((*s_etat_processus)
1363: .var_volatile_traitement_retarde_stop == -1)
1364: {
1365: (*s_etat_processus).var_volatile_requete_arret = -1;
1366: }
1367:
1368: (*s_etat_processus)
1369: .var_volatile_traitement_retarde_stop
1370: = registre;
1371: }
1372:
1373: (*s_etat_processus).erreur_systeme = d_es_processus;
1374: return;
1375: }
1376:
1377: nanosleep(&attente, NULL);
1378: INCR_GRANULARITE(attente.tv_nsec);
1379:
1380: # ifndef SEMAPHORES_NOMMES
1381: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1382: # else
1383: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1384: # endif
1385: {
1386: (*s_etat_processus).erreur_systeme = d_es_processus;
1387: return;
1388: }
1389: }
1390:
1391: scrutation_interruptions(s_etat_processus);
1392:
1393: # ifndef SEMAPHORES_NOMMES
1394: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1395: # else
1396: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1397: # endif
1398: {
1399: if (errno != EINTR)
1400: {
1401: (*s_etat_processus).erreur_systeme = d_es_processus;
1402: return;
1403: }
1404: }
1405: }
1406:
1407: interruption_reduite = interruption;
1408:
1409: attente.tv_sec = 0;
1410: attente.tv_nsec = GRANULARITE_us * 1000;
1411:
1412: # ifndef SEMAPHORES_NOMMES
1413: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1414: # else
1415: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1416: # endif
1417: {
1418: (*s_etat_processus).erreur_systeme = d_es_processus;
1419: return;
1420: }
1421:
1422: while((longueur_ecriture = write_atomic(s_etat_processus,
1423: (*s_etat_processus).pipe_interruptions,
1424: &interruption_reduite, sizeof(interruption_reduite)))
1425: != sizeof(interruption_reduite))
1426: {
1427: # ifndef SEMAPHORES_NOMMES
1428: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1429: # else
1430: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1431: # endif
1432: {
1433: if (errno != EINTR)
1434: {
1435: (*s_etat_processus).erreur_systeme = d_es_processus;
1436: return;
1437: }
1438: }
1439:
1440: if (longueur_ecriture == -1)
1441: {
1442: if (registre == 0)
1443: {
1444: if ((*s_etat_processus)
1445: .var_volatile_traitement_retarde_stop == -1)
1446: {
1447: (*s_etat_processus).var_volatile_requete_arret = -1;
1448: }
1449:
1450: (*s_etat_processus)
1451: .var_volatile_traitement_retarde_stop
1452: = registre;
1453: }
1454:
1455: (*s_etat_processus).erreur_systeme = d_es_processus;
1456: return;
1457: }
1458:
1459: nanosleep(&attente, NULL);
1460: INCR_GRANULARITE(attente.tv_nsec);
1461:
1462: # ifndef SEMAPHORES_NOMMES
1463: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1464: # else
1465: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1466: # endif
1467: {
1468: (*s_etat_processus).erreur_systeme = d_es_processus;
1469: return;
1470: }
1471:
1472: scrutation_interruptions(s_etat_processus);
1473: }
1474:
1475: # ifndef SEMAPHORES_NOMMES
1476: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1477: # else
1478: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1479: # endif
1480: {
1481: if (errno != EINTR)
1482: {
1483: (*s_etat_processus).erreur_systeme = d_es_processus;
1484: return;
1485: }
1486: }
1487:
1488: if ((*s_etat_processus).processus_detache == d_vrai)
1489: {
1490: pid = -3;
1491:
1492: attente.tv_sec = 0;
1493: attente.tv_nsec = GRANULARITE_us * 1000;
1494:
1495: # ifndef SEMAPHORES_NOMMES
1496: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1497: # else
1498: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1499: # endif
1500: {
1501: (*s_etat_processus).erreur_systeme = d_es_processus;
1502: return;
1503: }
1504:
1505: while((longueur_ecriture = write_atomic(s_etat_processus,
1506: (*s_etat_processus).pipe_nombre_interruptions_attente,
1507: &pid, sizeof(pid))) != sizeof(pid))
1508: {
1509: # ifndef SEMAPHORES_NOMMES
1510: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1511: # else
1512: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1513: # endif
1514: {
1515: if (errno != EINTR)
1516: {
1517: (*s_etat_processus).erreur_systeme = d_es_processus;
1518: return;
1519: }
1520: }
1521:
1522: if (longueur_ecriture == -1)
1523: {
1524: if (registre == 0)
1525: {
1526: if ((*s_etat_processus)
1527: .var_volatile_traitement_retarde_stop == -1)
1528: {
1529: (*s_etat_processus).var_volatile_requete_arret = -1;
1530: }
1531:
1532: (*s_etat_processus)
1533: .var_volatile_traitement_retarde_stop
1534: = registre;
1535: }
1536:
1537: (*s_etat_processus).erreur_systeme = d_es_processus;
1538: return;
1539: }
1540:
1541: nanosleep(&attente, NULL);
1542: INCR_GRANULARITE(attente.tv_nsec);
1543:
1544: # ifndef SEMAPHORES_NOMMES
1545: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1546: # else
1547: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1548: # endif
1549: {
1550: (*s_etat_processus).erreur_systeme = d_es_processus;
1551: return;
1552: }
1553:
1554: scrutation_interruptions(s_etat_processus);
1555: }
1556:
1557: pid = getpid();
1558:
1559: attente.tv_sec = 0;
1560: attente.tv_nsec = GRANULARITE_us * 1000;
1561:
1562: while((longueur_ecriture = write_atomic(s_etat_processus,
1563: (*s_etat_processus).pipe_nombre_interruptions_attente,
1564: &pid, sizeof(pid))) != sizeof(pid))
1565: {
1566: # ifndef SEMAPHORES_NOMMES
1567: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1568: # else
1569: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1570: # endif
1571: {
1572: if (errno != EINTR)
1573: {
1574: (*s_etat_processus).erreur_systeme = d_es_processus;
1575: return;
1576: }
1577: }
1578:
1579: if (longueur_ecriture == -1)
1580: {
1581: if (registre == 0)
1582: {
1583: if ((*s_etat_processus)
1584: .var_volatile_traitement_retarde_stop == -1)
1585: {
1586: (*s_etat_processus).var_volatile_requete_arret = -1;
1587: }
1588:
1589: (*s_etat_processus)
1590: .var_volatile_traitement_retarde_stop
1591: = registre;
1592: }
1593:
1594: (*s_etat_processus).erreur_systeme = d_es_processus;
1595: return;
1596: }
1597:
1598: nanosleep(&attente, NULL);
1599: INCR_GRANULARITE(attente.tv_nsec);
1600:
1601: # ifndef SEMAPHORES_NOMMES
1602: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1603: # else
1604: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1605: # endif
1606: {
1607: (*s_etat_processus).erreur_systeme = d_es_processus;
1608: return;
1609: }
1610: }
1611:
1612: # ifndef SEMAPHORES_NOMMES
1613: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1614: # else
1615: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1616: # endif
1617: {
1618: if (errno != EINTR)
1619: {
1620: (*s_etat_processus).erreur_systeme = d_es_processus;
1621: return;
1622: }
1623: }
1624: }
1625: else
1626: {
1627: tid = -3;
1628:
1629: # ifndef SEMAPHORES_NOMMES
1630: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1631: # else
1632: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1633: # endif
1634: {
1635: (*s_etat_processus).erreur_systeme = d_es_processus;
1636: return;
1637: }
1638:
1639: while((longueur_ecriture = write_atomic(s_etat_processus,
1640: (*s_etat_processus).pipe_nombre_interruptions_attente,
1641: &tid, sizeof(tid))) != sizeof(tid))
1642: {
1643: # ifndef SEMAPHORES_NOMMES
1644: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1645: # else
1646: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1647: # endif
1648: {
1649: if (errno != EINTR)
1650: {
1651: (*s_etat_processus).erreur_systeme = d_es_processus;
1652: return;
1653: }
1654: }
1655:
1656: if (longueur_ecriture == -1)
1657: {
1658: if (registre == 0)
1659: {
1660: if ((*s_etat_processus)
1661: .var_volatile_traitement_retarde_stop == -1)
1662: {
1663: (*s_etat_processus).var_volatile_requete_arret = -1;
1664: }
1665:
1666: (*s_etat_processus)
1667: .var_volatile_traitement_retarde_stop
1668: = registre;
1669: }
1670:
1671: (*s_etat_processus).erreur_systeme = d_es_processus;
1672: return;
1673: }
1674:
1675: nanosleep(&attente, NULL);
1676: INCR_GRANULARITE(attente.tv_nsec);
1677:
1678: # ifndef SEMAPHORES_NOMMES
1679: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1680: # else
1681: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1682: # endif
1683: {
1684: (*s_etat_processus).erreur_systeme = d_es_processus;
1685: return;
1686: }
1687:
1688: scrutation_interruptions(s_etat_processus);
1689: }
1690:
1691: tid = pthread_self();
1692:
1693: attente.tv_sec = 0;
1694: attente.tv_nsec = GRANULARITE_us * 1000;
1695:
1696: while((longueur_ecriture = write_atomic(s_etat_processus,
1697: (*s_etat_processus).pipe_nombre_interruptions_attente,
1698: &tid, sizeof(tid))) != sizeof(tid))
1699: {
1700: # ifndef SEMAPHORES_NOMMES
1701: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1702: # else
1703: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1704: # endif
1705: {
1706: if (errno != EINTR)
1707: {
1708: (*s_etat_processus).erreur_systeme = d_es_processus;
1709: return;
1710: }
1711: }
1712:
1713: if (longueur_ecriture == -1)
1714:
1715: {
1716: if (registre == 0)
1717: {
1718: if ((*s_etat_processus)
1719: .var_volatile_traitement_retarde_stop == -1)
1720: {
1721: (*s_etat_processus).var_volatile_requete_arret = -1;
1722: }
1723:
1724: (*s_etat_processus)
1725: .var_volatile_traitement_retarde_stop
1726: = registre;
1727: }
1728:
1729: (*s_etat_processus).erreur_systeme = d_es_processus;
1730: return;
1731: }
1732:
1733: nanosleep(&attente, NULL);
1734: INCR_GRANULARITE(attente.tv_nsec);
1735:
1736: # ifndef SEMAPHORES_NOMMES
1737: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1738: # else
1739: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1740: # endif
1741: {
1742: (*s_etat_processus).erreur_systeme = d_es_processus;
1743: return;
1744: }
1745:
1746: scrutation_interruptions(s_etat_processus);
1747: }
1748:
1749: # ifndef SEMAPHORES_NOMMES
1750: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1751: # else
1752: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1753: # endif
1754: {
1755: if (errno != EINTR)
1756: {
1757: (*s_etat_processus).erreur_systeme = d_es_processus;
1758: return;
1759: }
1760: }
1761: }
1762:
1763: attente.tv_sec = 0;
1764: attente.tv_nsec = GRANULARITE_us * 1000;
1765:
1766: # ifndef SEMAPHORES_NOMMES
1767: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1768: # else
1769: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1770: # endif
1771: {
1772: (*s_etat_processus).erreur_systeme = d_es_processus;
1773: return;
1774: }
1775:
1776: while(read_atomic(s_etat_processus,
1777: (*s_etat_processus).pipe_acquittement,
1778: &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
1779: {
1780: # ifndef SEMAPHORES_NOMMES
1781: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1782: # else
1783: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1784: # endif
1785: {
1786: if (errno != EINTR)
1787: {
1788: (*s_etat_processus).erreur_systeme = d_es_processus;
1789: return;
1790: }
1791: }
1792:
1793: nanosleep(&attente, NULL);
1794: INCR_GRANULARITE(attente.tv_nsec);
1795:
1796: # ifndef SEMAPHORES_NOMMES
1797: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1798: # else
1799: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1800: # endif
1801: {
1802: (*s_etat_processus).erreur_systeme = d_es_processus;
1803: return;
1804: }
1805:
1806: scrutation_interruptions(s_etat_processus);
1807: }
1808:
1809: # ifndef SEMAPHORES_NOMMES
1810: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1811: # else
1812: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1813: # endif
1814: {
1815: if (errno != EINTR)
1816: {
1817: (*s_etat_processus).erreur_systeme = d_es_processus;
1818: return;
1819: }
1820: }
1821:
1822: if (registre == 0)
1823: {
1824: if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
1825: {
1826: (*s_etat_processus).var_volatile_requete_arret = -1;
1827: }
1828:
1829: (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
1830: }
1831: }
1832: else
1833: {
1834: liberation(s_etat_processus, s_objet_argument);
1835:
1836: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1837: return;
1838: }
1839:
1840: liberation(s_etat_processus, s_objet_argument);
1841:
1842: return;
1843: }
1844:
1845:
1846: /*
1847: ================================================================================
1848: Fonction 'swilock'
1849: ================================================================================
1850: Entrées : structure processus
1851: --------------------------------------------------------------------------------
1852: Sorties :
1853: --------------------------------------------------------------------------------
1854: Effets de bord : néant
1855: ================================================================================
1856: */
1857:
1858: void
1859: instruction_swilock(struct_processus *s_etat_processus)
1860: {
1861: integer8 interruption;
1862:
1863: struct_liste_chainee *l_element_courant;
1864:
1865: struct_objet *s_objet_argument;
1866:
1867: (*s_etat_processus).erreur_execution = d_ex;
1868:
1869: if ((*s_etat_processus).affichage_arguments == 'Y')
1870: {
1871: printf("\n SWILOCK ");
1872:
1873: if ((*s_etat_processus).langue == 'F')
1874: {
1875: printf("(verrouillage des interruptions logicielles)\n\n");
1876: }
1877: else
1878: {
1879: printf("(software interrupt lock)\n\n");
1880: }
1881:
1882: printf(" 1: %s, %s\n", d_INT, d_LST);
1883:
1884: return;
1885: }
1886: else if ((*s_etat_processus).test_instruction == 'Y')
1887: {
1888: (*s_etat_processus).nombre_arguments = -1;
1889: return;
1890: }
1891:
1892: if (test_cfsf(s_etat_processus, 31) == d_vrai)
1893: {
1894: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
1895: {
1896: return;
1897: }
1898: }
1899:
1900: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1901: &s_objet_argument) == d_erreur)
1902: {
1903: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1904: return;
1905: }
1906:
1907: if ((*s_objet_argument).type == INT)
1908: {
1909: interruption = (*((integer8 *) (*s_objet_argument).objet));
1910:
1911: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1912: {
1913: liberation(s_etat_processus, s_objet_argument);
1914:
1915: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
1916: return;
1917: }
1918:
1919: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
1920: }
1921: else if ((*s_objet_argument).type == LST)
1922: {
1923: l_element_courant = (*s_objet_argument).objet;
1924:
1925: while(l_element_courant)
1926: {
1927: if ((*(*l_element_courant).donnee).type != INT)
1928: {
1929: liberation(s_etat_processus, s_objet_argument);
1930:
1931: (*s_etat_processus).erreur_execution =
1932: d_ex_erreur_type_argument;
1933: return;
1934: }
1935:
1936: interruption = (*((integer8 *) (*(*l_element_courant)
1937: .donnee).objet));
1938:
1939: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
1940: {
1941: liberation(s_etat_processus, s_objet_argument);
1942:
1943: (*s_etat_processus).erreur_execution =
1944: d_ex_interruption_invalide;
1945: return;
1946: }
1947:
1948: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
1949: l_element_courant = (*l_element_courant).suivant;
1950: }
1951: }
1952: else
1953: {
1954: liberation(s_etat_processus, s_objet_argument);
1955:
1956: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1957: return;
1958: }
1959:
1960: liberation(s_etat_processus, s_objet_argument);
1961:
1962: return;
1963: }
1964:
1965:
1966: /*
1967: ================================================================================
1968: Fonction 'swistatus'
1969: ================================================================================
1970: Entrées : structure processus
1971: --------------------------------------------------------------------------------
1972: Sorties :
1973: --------------------------------------------------------------------------------
1974: Effets de bord : néant
1975: ================================================================================
1976: */
1977:
1978: void
1979: instruction_swistatus(struct_processus *s_etat_processus)
1980: {
1981: int i;
1982:
1983: struct_liste_chainee *l_element_courant;
1984: struct_liste_chainee *l_element_futur;
1985: struct_liste_chainee *l_element_liste;
1986:
1987: struct_objet *s_objet_resultat;
1988:
1989: (*s_etat_processus).erreur_execution = d_ex;
1990:
1991: if ((*s_etat_processus).affichage_arguments == 'Y')
1992: {
1993: printf("\n SWISTATUS ");
1994:
1995: if ((*s_etat_processus).langue == 'F')
1996: {
1997: printf("(état des interruptions logicielles)\n\n");
1998: }
1999: else
2000: {
2001: printf("(software interrupts status)\n\n");
2002: }
2003:
2004: printf("-> 1: %s\n\n", d_LST);
2005:
2006: if ((*s_etat_processus).langue == 'F')
2007: {
2008: printf(" Utilisation :\n\n");
2009: }
2010: else
2011: {
2012: printf(" Usage:\n\n");
2013: }
2014:
2015: printf(" { { initialized interrupts }\n"
2016: " { unlocked interrupts }\n"
2017: " { queued interrupts }\n"
2018: " { locked interrupts } }\n");
2019: return;
2020: }
2021: else if ((*s_etat_processus).test_instruction == 'Y')
2022: {
2023: (*s_etat_processus).nombre_arguments = -1;
2024: return;
2025: }
2026:
2027: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2028: {
2029: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
2030: {
2031: return;
2032: }
2033: }
2034:
2035: if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
2036: {
2037: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2038: return;
2039: }
2040:
2041: if (((*s_objet_resultat).objet =
2042: allocation_maillon(s_etat_processus)) == NULL)
2043: {
2044: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2045: return;
2046: }
2047:
2048: l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
2049:
2050: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2051: == NULL)
2052: {
2053: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2054: return;
2055: }
2056:
2057: l_element_liste = NULL;
2058: l_element_futur = NULL;
2059:
2060: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2061: {
2062: if ((*s_etat_processus).corps_interruptions[i] != NULL)
2063: {
2064: if (l_element_liste == NULL)
2065: {
2066: if ((l_element_liste =
2067: allocation_maillon(s_etat_processus)) == NULL)
2068: {
2069: (*s_etat_processus).erreur_systeme =
2070: d_es_allocation_memoire;
2071: return;
2072: }
2073:
2074: l_element_futur = l_element_liste;
2075: }
2076: else
2077: {
2078: if (((*l_element_liste).suivant =
2079: allocation_maillon(s_etat_processus)) == NULL)
2080: {
2081: (*s_etat_processus).erreur_systeme =
2082: d_es_allocation_memoire;
2083: return;
2084: }
2085:
2086: l_element_liste = (*l_element_liste).suivant;
2087: }
2088:
2089: (*l_element_liste).suivant = NULL;
2090:
2091: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2092: INT)) == NULL)
2093: {
2094: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2095: return;
2096: }
2097:
2098: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2099: }
2100: }
2101:
2102: (*(*l_element_courant).donnee).objet = l_element_futur;
2103:
2104: if (((*l_element_courant).suivant =
2105: allocation_maillon(s_etat_processus)) == NULL)
2106: {
2107: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2108: return;
2109: }
2110:
2111: l_element_courant = (*l_element_courant).suivant;
2112:
2113: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2114: == NULL)
2115: {
2116: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2117: return;
2118: }
2119:
2120: l_element_liste = NULL;
2121: l_element_futur = NULL;
2122:
2123: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2124: {
2125: if ((*s_etat_processus).masque_interruptions[i] == 'N')
2126: {
2127: if (l_element_liste == NULL)
2128: {
2129: if ((l_element_liste =
2130: allocation_maillon(s_etat_processus)) == NULL)
2131: {
2132: (*s_etat_processus).erreur_systeme =
2133: d_es_allocation_memoire;
2134: return;
2135: }
2136:
2137: l_element_futur = l_element_liste;
2138: }
2139: else
2140: {
2141: if (((*l_element_liste).suivant =
2142: allocation_maillon(s_etat_processus)) == NULL)
2143: {
2144: (*s_etat_processus).erreur_systeme =
2145: d_es_allocation_memoire;
2146: return;
2147: }
2148:
2149: l_element_liste = (*l_element_liste).suivant;
2150: }
2151:
2152: (*l_element_liste).suivant = NULL;
2153:
2154: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2155: INT)) == NULL)
2156: {
2157: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2158: return;
2159: }
2160:
2161: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2162: }
2163: }
2164:
2165: (*(*l_element_courant).donnee).objet = l_element_futur;
2166:
2167: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2168: == NULL)
2169: {
2170: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2171: return;
2172: }
2173:
2174: l_element_courant = (*l_element_courant).suivant;
2175:
2176: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2177: == NULL)
2178: {
2179: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2180: return;
2181: }
2182:
2183: l_element_liste = NULL;
2184: l_element_futur = NULL;
2185:
2186: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2187: {
2188: if ((*s_etat_processus).masque_interruptions[i] == 'Q')
2189: {
2190: if (l_element_liste == NULL)
2191: {
2192: if ((l_element_liste =
2193: allocation_maillon(s_etat_processus)) == NULL)
2194: {
2195: (*s_etat_processus).erreur_systeme =
2196: d_es_allocation_memoire;
2197: return;
2198: }
2199:
2200: l_element_futur = l_element_liste;
2201: }
2202: else
2203: {
2204: if (((*l_element_liste).suivant =
2205: allocation_maillon(s_etat_processus)) == NULL)
2206: {
2207: (*s_etat_processus).erreur_systeme =
2208: d_es_allocation_memoire;
2209: return;
2210: }
2211:
2212: l_element_liste = (*l_element_liste).suivant;
2213: }
2214:
2215: (*l_element_liste).suivant = NULL;
2216:
2217: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2218: INT)) == NULL)
2219: {
2220: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2221: return;
2222: }
2223:
2224: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2225: }
2226: }
2227:
2228: (*(*l_element_courant).donnee).objet = l_element_futur;
2229:
2230: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2231: == NULL)
2232: {
2233: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2234: return;
2235: }
2236:
2237: l_element_courant = (*l_element_courant).suivant;
2238:
2239: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2240: == NULL)
2241: {
2242: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2243: return;
2244: }
2245:
2246: l_element_liste = NULL;
2247: l_element_futur = NULL;
2248:
2249: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2250: {
2251: if ((*s_etat_processus).masque_interruptions[i] == 'I')
2252: {
2253: if (l_element_liste == NULL)
2254: {
2255: if ((l_element_liste =
2256: allocation_maillon(s_etat_processus)) == NULL)
2257: {
2258: (*s_etat_processus).erreur_systeme =
2259: d_es_allocation_memoire;
2260: return;
2261: }
2262:
2263: l_element_futur = l_element_liste;
2264: }
2265: else
2266: {
2267: if (((*l_element_liste).suivant =
2268: allocation_maillon(s_etat_processus)) == NULL)
2269: {
2270: (*s_etat_processus).erreur_systeme =
2271: d_es_allocation_memoire;
2272: return;
2273: }
2274:
2275: l_element_liste = (*l_element_liste).suivant;
2276: }
2277:
2278: (*l_element_liste).suivant = NULL;
2279:
2280: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2281: INT)) == NULL)
2282: {
2283: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2284: return;
2285: }
2286:
2287: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2288: }
2289: }
2290:
2291: (*(*l_element_courant).donnee).objet = l_element_futur;
2292:
2293: (*l_element_courant).suivant = NULL;
2294:
2295: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2296: s_objet_resultat) == d_erreur)
2297: {
2298: return;
2299: }
2300:
2301: return;
2302: }
2303:
2304:
2305: /*
2306: ================================================================================
2307: Fonction 'swiunlock'
2308: ================================================================================
2309: Entrées : structure processus
2310: --------------------------------------------------------------------------------
2311: Sorties :
2312: --------------------------------------------------------------------------------
2313: Effets de bord : néant
2314: ================================================================================
2315: */
2316:
2317: void
2318: instruction_swiunlock(struct_processus *s_etat_processus)
2319: {
2320: integer8 interruption;
2321:
2322: struct_liste_chainee *l_element_courant;
2323:
2324: struct_objet *s_objet_argument;
2325:
2326: (*s_etat_processus).erreur_execution = d_ex;
2327:
2328: if ((*s_etat_processus).affichage_arguments == 'Y')
2329: {
2330: printf("\n SWIUNLOCK ");
2331:
2332: if ((*s_etat_processus).langue == 'F')
2333: {
2334: printf("(déverrouillage des interruptions logicielles)\n\n");
2335: }
2336: else
2337: {
2338: printf("(software interrupt unlock)\n\n");
2339: }
2340:
2341: printf(" 1: %s, %s\n", d_INT, d_LST);
2342:
2343: return;
2344: }
2345: else if ((*s_etat_processus).test_instruction == 'Y')
2346: {
2347: (*s_etat_processus).nombre_arguments = -1;
2348: return;
2349: }
2350:
2351: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2352: {
2353: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2354: {
2355: return;
2356: }
2357: }
2358:
2359: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2360: &s_objet_argument) == d_erreur)
2361: {
2362: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2363: return;
2364: }
2365:
2366: if ((*s_objet_argument).type == INT)
2367: {
2368: interruption = (*((integer8 *) (*s_objet_argument).objet));
2369:
2370: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2371: {
2372: liberation(s_etat_processus, s_objet_argument);
2373:
2374: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2375: return;
2376: }
2377:
2378: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2379: }
2380: else if ((*s_objet_argument).type == LST)
2381: {
2382: l_element_courant = (*s_objet_argument).objet;
2383:
2384: while(l_element_courant)
2385: {
2386: if ((*(*l_element_courant).donnee).type != INT)
2387: {
2388: liberation(s_etat_processus, s_objet_argument);
2389:
2390: (*s_etat_processus).erreur_execution =
2391: d_ex_erreur_type_argument;
2392: return;
2393: }
2394:
2395: interruption = (*((integer8 *) (*(*l_element_courant)
2396: .donnee).objet));
2397:
2398: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2399: {
2400: liberation(s_etat_processus, s_objet_argument);
2401:
2402: (*s_etat_processus).erreur_execution =
2403: d_ex_interruption_invalide;
2404: return;
2405: }
2406:
2407: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2408: l_element_courant = (*l_element_courant).suivant;
2409: }
2410: }
2411: else
2412: {
2413: liberation(s_etat_processus, s_objet_argument);
2414:
2415: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2416: return;
2417: }
2418:
2419: liberation(s_etat_processus, s_objet_argument);
2420:
2421: return;
2422: }
2423:
2424:
2425: /*
2426: ================================================================================
2427: Fonction 'swiqueue'
2428: ================================================================================
2429: Entrées : structure processus
2430: --------------------------------------------------------------------------------
2431: Sorties :
2432: --------------------------------------------------------------------------------
2433: Effets de bord : néant
2434: ================================================================================
2435: */
2436:
2437: void
2438: instruction_swiqueue(struct_processus *s_etat_processus)
2439: {
2440: integer8 interruption;
2441:
2442: struct_liste_chainee *l_element_courant;
2443:
2444: struct_objet *s_objet_argument;
2445:
2446: (*s_etat_processus).erreur_execution = d_ex;
2447:
2448: if ((*s_etat_processus).affichage_arguments == 'Y')
2449: {
2450: printf("\n SWIQUEUE ");
2451:
2452: if ((*s_etat_processus).langue == 'F')
2453: {
2454: printf("(enregistre des interruptions logicielles)\n\n");
2455: }
2456: else
2457: {
2458: printf("(software interrupt record)\n\n");
2459: }
2460:
2461: printf(" 1: %s, %s\n", d_INT, d_LST);
2462:
2463: return;
2464: }
2465: else if ((*s_etat_processus).test_instruction == 'Y')
2466: {
2467: (*s_etat_processus).nombre_arguments = -1;
2468: return;
2469: }
2470:
2471: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2472: {
2473: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2474: {
2475: return;
2476: }
2477: }
2478:
2479: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2480: &s_objet_argument) == d_erreur)
2481: {
2482: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2483: return;
2484: }
2485:
2486: if ((*s_objet_argument).type == INT)
2487: {
2488: interruption = (*((integer8 *) (*s_objet_argument).objet));
2489:
2490: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2491: {
2492: liberation(s_etat_processus, s_objet_argument);
2493:
2494: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2495: return;
2496: }
2497:
2498: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2499: }
2500: else if ((*s_objet_argument).type == LST)
2501: {
2502: l_element_courant = (*s_objet_argument).objet;
2503:
2504: while(l_element_courant)
2505: {
2506: if ((*(*l_element_courant).donnee).type != INT)
2507: {
2508: liberation(s_etat_processus, s_objet_argument);
2509:
2510: (*s_etat_processus).erreur_execution =
2511: d_ex_erreur_type_argument;
2512: return;
2513: }
2514:
2515: interruption = (*((integer8 *) (*(*l_element_courant)
2516: .donnee).objet));
2517:
2518: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2519: {
2520: liberation(s_etat_processus, s_objet_argument);
2521:
2522: (*s_etat_processus).erreur_execution =
2523: d_ex_interruption_invalide;
2524: return;
2525: }
2526:
2527: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2528: l_element_courant = (*l_element_courant).suivant;
2529: }
2530: }
2531: else
2532: {
2533: liberation(s_etat_processus, s_objet_argument);
2534:
2535: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2536: return;
2537: }
2538:
2539: liberation(s_etat_processus, s_objet_argument);
2540:
2541: return;
2542: }
2543:
2544:
2545: /*
2546: ================================================================================
2547: Fonction 'sched'
2548: ================================================================================
2549: Entrées : structure processus
2550: --------------------------------------------------------------------------------
2551: Sorties :
2552: --------------------------------------------------------------------------------
2553: Effets de bord : néant
2554: ================================================================================
2555: */
2556:
2557: void
2558: instruction_sched(struct_processus *s_etat_processus)
2559: {
2560: real8 pourcentage;
2561:
2562: struct_objet *s_objet_argument;
2563:
2564: (*s_etat_processus).erreur_execution = d_ex;
2565:
2566: if ((*s_etat_processus).affichage_arguments == 'Y')
2567: {
2568: printf("\n SCHED ");
2569:
2570: if ((*s_etat_processus).langue == 'F')
2571: {
2572: printf("(limitation des ressources de calcul)\n\n");
2573: }
2574: else
2575: {
2576: printf("(CPU ressources limitation)\n\n");
2577: }
2578:
2579: printf(" 1: %s, %s\n", d_INT, d_REL);
2580:
2581: return;
2582: }
2583: else if ((*s_etat_processus).test_instruction == 'Y')
2584: {
2585: (*s_etat_processus).nombre_arguments = -1;
2586: return;
2587: }
2588:
2589: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2590: {
2591: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2592: {
2593: return;
2594: }
2595: }
2596:
2597: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2598: &s_objet_argument) == d_erreur)
2599: {
2600: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2601: return;
2602: }
2603:
2604: if ((*s_objet_argument).type == INT)
2605: {
2606: pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
2607: }
2608: else if ((*s_objet_argument).type == REL)
2609: {
2610: pourcentage = (*((real8 *) (*s_objet_argument).objet));
2611: }
2612: else
2613: {
2614: liberation(s_etat_processus, s_objet_argument);
2615:
2616: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2617: return;
2618: }
2619:
2620: liberation(s_etat_processus, s_objet_argument);
2621:
2622: if ((pourcentage <= 0) || (pourcentage > 100))
2623: {
2624: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
2625: return;
2626: }
2627:
2628: (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
2629:
2630: return;
2631: }
2632:
2633: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>