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