Annotation of rpl/src/instructions_s9.c, revision 1.19
1.1 bertrand 1: /*
2: ================================================================================
1.13 bertrand 3: RPL/2 (R) version 4.0.18
1.1 bertrand 4: Copyright (C) 1989-2010 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:
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: }
1.19 ! bertrand 1795:
! 1796: kill((*s_etat_processus).pid_processus_pere, SIGCONT);
1.1 bertrand 1797: }
1798: else
1799: {
1800: tid = -3;
1801:
1.8 bertrand 1802: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1803: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1804: {
1805: (*s_etat_processus).erreur_systeme = d_es_processus;
1806: return;
1807: }
1.8 bertrand 1808: # else
1809: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1810: {
1811: (*s_etat_processus).erreur_systeme = d_es_processus;
1812: return;
1813: }
1814: # endif
1.1 bertrand 1815:
1816: while((longueur_ecriture = write_atomic(s_etat_processus,
1817: (*s_etat_processus).pipe_nombre_interruptions_attente,
1818: &tid, sizeof(tid))) != sizeof(tid))
1819: {
1.8 bertrand 1820: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1821: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.8 bertrand 1822: # else
1823: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1824: # endif
1.1 bertrand 1825: {
1826: if (errno != EINTR)
1827: {
1828: (*s_etat_processus).erreur_systeme = d_es_processus;
1829: return;
1830: }
1831: }
1832:
1833: if (longueur_ecriture == -1)
1834: {
1835: if (registre == 0)
1836: {
1837: if ((*s_etat_processus)
1838: .var_volatile_traitement_retarde_stop == -1)
1839: {
1840: (*s_etat_processus).var_volatile_requete_arret = -1;
1841: }
1842:
1843: (*s_etat_processus)
1844: .var_volatile_traitement_retarde_stop
1845: = registre;
1846: }
1847:
1848: (*s_etat_processus).erreur_systeme = d_es_processus;
1849: return;
1850: }
1851:
1852: nanosleep(&attente, NULL);
1853: INCR_GRANULARITE(attente.tv_nsec);
1854:
1.8 bertrand 1855: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1856: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1857: {
1858: (*s_etat_processus).erreur_systeme = d_es_processus;
1859: return;
1860: }
1.8 bertrand 1861: # else
1862: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1863: {
1864: (*s_etat_processus).erreur_systeme = d_es_processus;
1865: return;
1866: }
1867: # endif
1.1 bertrand 1868: }
1869:
1870: tid = pthread_self();
1871:
1872: attente.tv_sec = 0;
1873: attente.tv_nsec = GRANULARITE_us * 1000;
1874:
1875: while((longueur_ecriture = write_atomic(s_etat_processus,
1876: (*s_etat_processus).pipe_nombre_interruptions_attente,
1877: &tid, sizeof(tid))) != sizeof(tid))
1878: {
1.8 bertrand 1879: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1880: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.8 bertrand 1881: # else
1882: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1883: # endif
1.1 bertrand 1884: {
1885: if (errno != EINTR)
1886: {
1887: (*s_etat_processus).erreur_systeme = d_es_processus;
1888: return;
1889: }
1890: }
1891:
1892: if (longueur_ecriture == -1)
1893:
1894: {
1895: if (registre == 0)
1896: {
1897: if ((*s_etat_processus)
1898: .var_volatile_traitement_retarde_stop == -1)
1899: {
1900: (*s_etat_processus).var_volatile_requete_arret = -1;
1901: }
1902:
1903: (*s_etat_processus)
1904: .var_volatile_traitement_retarde_stop
1905: = registre;
1906: }
1907:
1908: (*s_etat_processus).erreur_systeme = d_es_processus;
1909: return;
1910: }
1911:
1912: nanosleep(&attente, NULL);
1913: INCR_GRANULARITE(attente.tv_nsec);
1914:
1.8 bertrand 1915: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1916: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1917: {
1918: (*s_etat_processus).erreur_systeme = d_es_processus;
1919: return;
1920: }
1.8 bertrand 1921: # else
1922: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1923: {
1924: (*s_etat_processus).erreur_systeme = d_es_processus;
1925: return;
1926: }
1927: # endif
1.1 bertrand 1928: }
1929:
1.8 bertrand 1930: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1931: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.8 bertrand 1932: # else
1933: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1934: # endif
1.1 bertrand 1935: {
1936: if (errno != EINTR)
1937: {
1938: (*s_etat_processus).erreur_systeme = d_es_processus;
1939: return;
1940: }
1941: }
1.19 ! bertrand 1942:
! 1943: pthread_kill((*s_etat_processus).tid_processus_pere, SIGCONT);
1.1 bertrand 1944: }
1945:
1946: attente.tv_sec = 0;
1947: attente.tv_nsec = GRANULARITE_us * 1000;
1948:
1.8 bertrand 1949: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1950: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1951: {
1952: (*s_etat_processus).erreur_systeme = d_es_processus;
1953: return;
1954: }
1.8 bertrand 1955: # else
1956: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1957: {
1958: (*s_etat_processus).erreur_systeme = d_es_processus;
1959: return;
1960: }
1961: # endif
1.1 bertrand 1962:
1963: while(read_atomic(s_etat_processus,
1964: (*s_etat_processus).pipe_acquittement,
1965: &tampon, sizeof(unsigned char)) != sizeof(unsigned char))
1966: {
1.8 bertrand 1967: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1968: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.8 bertrand 1969: # else
1970: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1971: # endif
1.1 bertrand 1972: {
1973: if (errno != EINTR)
1974: {
1975: (*s_etat_processus).erreur_systeme = d_es_processus;
1976: return;
1977: }
1978: }
1979:
1980: nanosleep(&attente, NULL);
1981: INCR_GRANULARITE(attente.tv_nsec);
1982:
1.8 bertrand 1983: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1984: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.8 bertrand 1985: # else
1986: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1987: # endif
1.1 bertrand 1988: {
1989: (*s_etat_processus).erreur_systeme = d_es_processus;
1990: return;
1991: }
1992: }
1993:
1.8 bertrand 1994: # ifndef SEMAPHORES_NOMMES
1.1 bertrand 1995: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.8 bertrand 1996: # else
1997: while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
1998: # endif
1.1 bertrand 1999: {
2000: if (errno != EINTR)
2001: {
2002: (*s_etat_processus).erreur_systeme = d_es_processus;
2003: return;
2004: }
2005: }
2006:
2007: if (registre == 0)
2008: {
2009: if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1)
2010: {
2011: (*s_etat_processus).var_volatile_requete_arret = -1;
2012: }
2013:
2014: (*s_etat_processus).var_volatile_traitement_retarde_stop = registre;
2015: }
2016: }
2017: else
2018: {
2019: liberation(s_etat_processus, s_objet_argument);
2020:
2021: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2022: return;
2023: }
2024:
2025: liberation(s_etat_processus, s_objet_argument);
2026:
2027: return;
2028: }
2029:
2030:
2031: /*
2032: ================================================================================
2033: Fonction 'swilock'
2034: ================================================================================
2035: Entrées : structure processus
2036: --------------------------------------------------------------------------------
2037: Sorties :
2038: --------------------------------------------------------------------------------
2039: Effets de bord : néant
2040: ================================================================================
2041: */
2042:
2043: void
2044: instruction_swilock(struct_processus *s_etat_processus)
2045: {
2046: integer8 interruption;
2047:
2048: struct_liste_chainee *l_element_courant;
2049:
2050: struct_objet *s_objet_argument;
2051:
2052: (*s_etat_processus).erreur_execution = d_ex;
2053:
2054: if ((*s_etat_processus).affichage_arguments == 'Y')
2055: {
2056: printf("\n SWILOCK ");
2057:
2058: if ((*s_etat_processus).langue == 'F')
2059: {
2060: printf("(verrouillage des interruptions logicielles)\n\n");
2061: }
2062: else
2063: {
2064: printf("(software interrupt lock)\n\n");
2065: }
2066:
2067: printf(" 1: %s, %s\n", d_INT, d_LST);
2068:
2069: return;
2070: }
2071: else if ((*s_etat_processus).test_instruction == 'Y')
2072: {
2073: (*s_etat_processus).nombre_arguments = -1;
2074: return;
2075: }
2076:
2077: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2078: {
2079: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2080: {
2081: return;
2082: }
2083: }
2084:
2085: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2086: &s_objet_argument) == d_erreur)
2087: {
2088: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2089: return;
2090: }
2091:
2092: if ((*s_objet_argument).type == INT)
2093: {
2094: interruption = (*((integer8 *) (*s_objet_argument).objet));
2095:
2096: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2097: {
2098: liberation(s_etat_processus, s_objet_argument);
2099:
2100: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2101: return;
2102: }
2103:
2104: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
2105: }
2106: else if ((*s_objet_argument).type == LST)
2107: {
2108: l_element_courant = (*s_objet_argument).objet;
2109:
2110: while(l_element_courant)
2111: {
2112: if ((*(*l_element_courant).donnee).type != INT)
2113: {
2114: liberation(s_etat_processus, s_objet_argument);
2115:
2116: (*s_etat_processus).erreur_execution =
2117: d_ex_erreur_type_argument;
2118: return;
2119: }
2120:
2121: interruption = (*((integer8 *) (*(*l_element_courant)
2122: .donnee).objet));
2123:
2124: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2125: {
2126: liberation(s_etat_processus, s_objet_argument);
2127:
2128: (*s_etat_processus).erreur_execution =
2129: d_ex_interruption_invalide;
2130: return;
2131: }
2132:
2133: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I';
2134: l_element_courant = (*l_element_courant).suivant;
2135: }
2136: }
2137: else
2138: {
2139: liberation(s_etat_processus, s_objet_argument);
2140:
2141: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2142: return;
2143: }
2144:
2145: liberation(s_etat_processus, s_objet_argument);
2146:
2147: return;
2148: }
2149:
2150:
2151: /*
2152: ================================================================================
2153: Fonction 'swistatus'
2154: ================================================================================
2155: Entrées : structure processus
2156: --------------------------------------------------------------------------------
2157: Sorties :
2158: --------------------------------------------------------------------------------
2159: Effets de bord : néant
2160: ================================================================================
2161: */
2162:
2163: void
2164: instruction_swistatus(struct_processus *s_etat_processus)
2165: {
2166: int i;
2167:
2168: struct_liste_chainee *l_element_courant;
2169: struct_liste_chainee *l_element_futur;
2170: struct_liste_chainee *l_element_liste;
2171:
2172: struct_objet *s_objet_resultat;
2173:
2174: (*s_etat_processus).erreur_execution = d_ex;
2175:
2176: if ((*s_etat_processus).affichage_arguments == 'Y')
2177: {
2178: printf("\n SWISTATUS ");
2179:
2180: if ((*s_etat_processus).langue == 'F')
2181: {
2182: printf("(état des interruptions logicielles)\n\n");
2183: }
2184: else
2185: {
2186: printf("(software interrupts status)\n\n");
2187: }
2188:
2189: printf("-> 1: %s\n\n", d_LST);
2190:
2191: if ((*s_etat_processus).langue == 'F')
2192: {
2193: printf(" Utilisation :\n\n");
2194: }
2195: else
2196: {
2197: printf(" Usage:\n\n");
2198: }
2199:
2200: printf(" { { initialized interrupts }\n"
2201: " { unlocked interrupts }\n"
2202: " { queued interrupts }\n"
2203: " { locked interrupts } }\n");
2204: return;
2205: }
2206: else if ((*s_etat_processus).test_instruction == 'Y')
2207: {
2208: (*s_etat_processus).nombre_arguments = -1;
2209: return;
2210: }
2211:
2212: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2213: {
2214: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
2215: {
2216: return;
2217: }
2218: }
2219:
2220: if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL)
2221: {
2222: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2223: return;
2224: }
2225:
2226: if (((*s_objet_resultat).objet =
2227: allocation_maillon(s_etat_processus)) == NULL)
2228: {
2229: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2230: return;
2231: }
2232:
2233: l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet;
2234:
2235: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2236: == NULL)
2237: {
2238: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2239: return;
2240: }
2241:
2242: l_element_liste = NULL;
2243: l_element_futur = NULL;
2244:
2245: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2246: {
2247: if ((*s_etat_processus).corps_interruptions[i] != NULL)
2248: {
2249: if (l_element_liste == NULL)
2250: {
2251: if ((l_element_liste =
2252: allocation_maillon(s_etat_processus)) == NULL)
2253: {
2254: (*s_etat_processus).erreur_systeme =
2255: d_es_allocation_memoire;
2256: return;
2257: }
2258:
2259: l_element_futur = l_element_liste;
2260: }
2261: else
2262: {
2263: if (((*l_element_liste).suivant =
2264: allocation_maillon(s_etat_processus)) == NULL)
2265: {
2266: (*s_etat_processus).erreur_systeme =
2267: d_es_allocation_memoire;
2268: return;
2269: }
2270:
2271: l_element_liste = (*l_element_liste).suivant;
2272: }
2273:
2274: (*l_element_liste).suivant = NULL;
2275:
2276: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2277: INT)) == NULL)
2278: {
2279: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2280: return;
2281: }
2282:
2283: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2284: }
2285: }
2286:
2287: (*(*l_element_courant).donnee).objet = l_element_futur;
2288:
2289: if (((*l_element_courant).suivant =
2290: allocation_maillon(s_etat_processus)) == NULL)
2291: {
2292: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2293: return;
2294: }
2295:
2296: l_element_courant = (*l_element_courant).suivant;
2297:
2298: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2299: == NULL)
2300: {
2301: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2302: return;
2303: }
2304:
2305: l_element_liste = NULL;
2306: l_element_futur = NULL;
2307:
2308: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2309: {
2310: if ((*s_etat_processus).masque_interruptions[i] == 'N')
2311: {
2312: if (l_element_liste == NULL)
2313: {
2314: if ((l_element_liste =
2315: allocation_maillon(s_etat_processus)) == NULL)
2316: {
2317: (*s_etat_processus).erreur_systeme =
2318: d_es_allocation_memoire;
2319: return;
2320: }
2321:
2322: l_element_futur = l_element_liste;
2323: }
2324: else
2325: {
2326: if (((*l_element_liste).suivant =
2327: allocation_maillon(s_etat_processus)) == NULL)
2328: {
2329: (*s_etat_processus).erreur_systeme =
2330: d_es_allocation_memoire;
2331: return;
2332: }
2333:
2334: l_element_liste = (*l_element_liste).suivant;
2335: }
2336:
2337: (*l_element_liste).suivant = NULL;
2338:
2339: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2340: INT)) == NULL)
2341: {
2342: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2343: return;
2344: }
2345:
2346: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2347: }
2348: }
2349:
2350: (*(*l_element_courant).donnee).objet = l_element_futur;
2351:
2352: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2353: == NULL)
2354: {
2355: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2356: return;
2357: }
2358:
2359: l_element_courant = (*l_element_courant).suivant;
2360:
2361: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2362: == NULL)
2363: {
2364: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2365: return;
2366: }
2367:
2368: l_element_liste = NULL;
2369: l_element_futur = NULL;
2370:
2371: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2372: {
2373: if ((*s_etat_processus).masque_interruptions[i] == 'Q')
2374: {
2375: if (l_element_liste == NULL)
2376: {
2377: if ((l_element_liste =
2378: allocation_maillon(s_etat_processus)) == NULL)
2379: {
2380: (*s_etat_processus).erreur_systeme =
2381: d_es_allocation_memoire;
2382: return;
2383: }
2384:
2385: l_element_futur = l_element_liste;
2386: }
2387: else
2388: {
2389: if (((*l_element_liste).suivant =
2390: allocation_maillon(s_etat_processus)) == NULL)
2391: {
2392: (*s_etat_processus).erreur_systeme =
2393: d_es_allocation_memoire;
2394: return;
2395: }
2396:
2397: l_element_liste = (*l_element_liste).suivant;
2398: }
2399:
2400: (*l_element_liste).suivant = NULL;
2401:
2402: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2403: INT)) == NULL)
2404: {
2405: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2406: return;
2407: }
2408:
2409: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2410: }
2411: }
2412:
2413: (*(*l_element_courant).donnee).objet = l_element_futur;
2414:
2415: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus))
2416: == NULL)
2417: {
2418: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2419: return;
2420: }
2421:
2422: l_element_courant = (*l_element_courant).suivant;
2423:
2424: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST))
2425: == NULL)
2426: {
2427: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2428: return;
2429: }
2430:
2431: l_element_liste = NULL;
2432: l_element_futur = NULL;
2433:
2434: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
2435: {
2436: if ((*s_etat_processus).masque_interruptions[i] == 'I')
2437: {
2438: if (l_element_liste == NULL)
2439: {
2440: if ((l_element_liste =
2441: allocation_maillon(s_etat_processus)) == NULL)
2442: {
2443: (*s_etat_processus).erreur_systeme =
2444: d_es_allocation_memoire;
2445: return;
2446: }
2447:
2448: l_element_futur = l_element_liste;
2449: }
2450: else
2451: {
2452: if (((*l_element_liste).suivant =
2453: allocation_maillon(s_etat_processus)) == NULL)
2454: {
2455: (*s_etat_processus).erreur_systeme =
2456: d_es_allocation_memoire;
2457: return;
2458: }
2459:
2460: l_element_liste = (*l_element_liste).suivant;
2461: }
2462:
2463: (*l_element_liste).suivant = NULL;
2464:
2465: if (((*l_element_liste).donnee = allocation(s_etat_processus,
2466: INT)) == NULL)
2467: {
2468: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2469: return;
2470: }
2471:
2472: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1;
2473: }
2474: }
2475:
2476: (*(*l_element_courant).donnee).objet = l_element_futur;
2477:
2478: (*l_element_courant).suivant = NULL;
2479:
2480: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2481: s_objet_resultat) == d_erreur)
2482: {
2483: return;
2484: }
2485:
2486: return;
2487: }
2488:
2489:
2490: /*
2491: ================================================================================
2492: Fonction 'swiunlock'
2493: ================================================================================
2494: Entrées : structure processus
2495: --------------------------------------------------------------------------------
2496: Sorties :
2497: --------------------------------------------------------------------------------
2498: Effets de bord : néant
2499: ================================================================================
2500: */
2501:
2502: void
2503: instruction_swiunlock(struct_processus *s_etat_processus)
2504: {
2505: integer8 interruption;
2506:
2507: struct_liste_chainee *l_element_courant;
2508:
2509: struct_objet *s_objet_argument;
2510:
2511: (*s_etat_processus).erreur_execution = d_ex;
2512:
2513: if ((*s_etat_processus).affichage_arguments == 'Y')
2514: {
2515: printf("\n SWIUNLOCK ");
2516:
2517: if ((*s_etat_processus).langue == 'F')
2518: {
2519: printf("(déverrouillage des interruptions logicielles)\n\n");
2520: }
2521: else
2522: {
2523: printf("(software interrupt unlock)\n\n");
2524: }
2525:
2526: printf(" 1: %s, %s\n", d_INT, d_LST);
2527:
2528: return;
2529: }
2530: else if ((*s_etat_processus).test_instruction == 'Y')
2531: {
2532: (*s_etat_processus).nombre_arguments = -1;
2533: return;
2534: }
2535:
2536: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2537: {
2538: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2539: {
2540: return;
2541: }
2542: }
2543:
2544: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2545: &s_objet_argument) == d_erreur)
2546: {
2547: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2548: return;
2549: }
2550:
2551: if ((*s_objet_argument).type == INT)
2552: {
2553: interruption = (*((integer8 *) (*s_objet_argument).objet));
2554:
2555: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2556: {
2557: liberation(s_etat_processus, s_objet_argument);
2558:
2559: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2560: return;
2561: }
2562:
2563: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2564: }
2565: else if ((*s_objet_argument).type == LST)
2566: {
2567: l_element_courant = (*s_objet_argument).objet;
2568:
2569: while(l_element_courant)
2570: {
2571: if ((*(*l_element_courant).donnee).type != INT)
2572: {
2573: liberation(s_etat_processus, s_objet_argument);
2574:
2575: (*s_etat_processus).erreur_execution =
2576: d_ex_erreur_type_argument;
2577: return;
2578: }
2579:
2580: interruption = (*((integer8 *) (*(*l_element_courant)
2581: .donnee).objet));
2582:
2583: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2584: {
2585: liberation(s_etat_processus, s_objet_argument);
2586:
2587: (*s_etat_processus).erreur_execution =
2588: d_ex_interruption_invalide;
2589: return;
2590: }
2591:
2592: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N';
2593: l_element_courant = (*l_element_courant).suivant;
2594: }
2595: }
2596: else
2597: {
2598: liberation(s_etat_processus, s_objet_argument);
2599:
2600: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2601: return;
2602: }
2603:
2604: liberation(s_etat_processus, s_objet_argument);
2605:
2606: return;
2607: }
2608:
2609:
2610: /*
2611: ================================================================================
2612: Fonction 'swiqueue'
2613: ================================================================================
2614: Entrées : structure processus
2615: --------------------------------------------------------------------------------
2616: Sorties :
2617: --------------------------------------------------------------------------------
2618: Effets de bord : néant
2619: ================================================================================
2620: */
2621:
2622: void
2623: instruction_swiqueue(struct_processus *s_etat_processus)
2624: {
2625: integer8 interruption;
2626:
2627: struct_liste_chainee *l_element_courant;
2628:
2629: struct_objet *s_objet_argument;
2630:
2631: (*s_etat_processus).erreur_execution = d_ex;
2632:
2633: if ((*s_etat_processus).affichage_arguments == 'Y')
2634: {
2635: printf("\n SWIQUEUE ");
2636:
2637: if ((*s_etat_processus).langue == 'F')
2638: {
2639: printf("(enregistre des interruptions logicielles)\n\n");
2640: }
2641: else
2642: {
2643: printf("(software interrupt record)\n\n");
2644: }
2645:
2646: printf(" 1: %s, %s\n", d_INT, d_LST);
2647:
2648: return;
2649: }
2650: else if ((*s_etat_processus).test_instruction == 'Y')
2651: {
2652: (*s_etat_processus).nombre_arguments = -1;
2653: return;
2654: }
2655:
2656: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2657: {
2658: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2659: {
2660: return;
2661: }
2662: }
2663:
2664: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2665: &s_objet_argument) == d_erreur)
2666: {
2667: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2668: return;
2669: }
2670:
2671: if ((*s_objet_argument).type == INT)
2672: {
2673: interruption = (*((integer8 *) (*s_objet_argument).objet));
2674:
2675: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2676: {
2677: liberation(s_etat_processus, s_objet_argument);
2678:
2679: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide;
2680: return;
2681: }
2682:
2683: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2684: }
2685: else if ((*s_objet_argument).type == LST)
2686: {
2687: l_element_courant = (*s_objet_argument).objet;
2688:
2689: while(l_element_courant)
2690: {
2691: if ((*(*l_element_courant).donnee).type != INT)
2692: {
2693: liberation(s_etat_processus, s_objet_argument);
2694:
2695: (*s_etat_processus).erreur_execution =
2696: d_ex_erreur_type_argument;
2697: return;
2698: }
2699:
2700: interruption = (*((integer8 *) (*(*l_element_courant)
2701: .donnee).objet));
2702:
2703: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS))
2704: {
2705: liberation(s_etat_processus, s_objet_argument);
2706:
2707: (*s_etat_processus).erreur_execution =
2708: d_ex_interruption_invalide;
2709: return;
2710: }
2711:
2712: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q';
2713: l_element_courant = (*l_element_courant).suivant;
2714: }
2715: }
2716: else
2717: {
2718: liberation(s_etat_processus, s_objet_argument);
2719:
2720: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2721: return;
2722: }
2723:
2724: liberation(s_etat_processus, s_objet_argument);
2725:
2726: return;
2727: }
2728:
2729:
2730: /*
2731: ================================================================================
2732: Fonction 'sched'
2733: ================================================================================
2734: Entrées : structure processus
2735: --------------------------------------------------------------------------------
2736: Sorties :
2737: --------------------------------------------------------------------------------
2738: Effets de bord : néant
2739: ================================================================================
2740: */
2741:
2742: void
2743: instruction_sched(struct_processus *s_etat_processus)
2744: {
2745: real8 pourcentage;
2746:
2747: struct_objet *s_objet_argument;
2748:
2749: (*s_etat_processus).erreur_execution = d_ex;
2750:
2751: if ((*s_etat_processus).affichage_arguments == 'Y')
2752: {
2753: printf("\n SCHED ");
2754:
2755: if ((*s_etat_processus).langue == 'F')
2756: {
2757: printf("(limitation des ressources de calcul)\n\n");
2758: }
2759: else
2760: {
2761: printf("(CPU ressources limitation)\n\n");
2762: }
2763:
2764: printf(" 1: %s, %s\n", d_INT, d_REL);
2765:
2766: return;
2767: }
2768: else if ((*s_etat_processus).test_instruction == 'Y')
2769: {
2770: (*s_etat_processus).nombre_arguments = -1;
2771: return;
2772: }
2773:
2774: if (test_cfsf(s_etat_processus, 31) == d_vrai)
2775: {
2776: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
2777: {
2778: return;
2779: }
2780: }
2781:
2782: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2783: &s_objet_argument) == d_erreur)
2784: {
2785: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
2786: return;
2787: }
2788:
2789: if ((*s_objet_argument).type == INT)
2790: {
2791: pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet));
2792: }
2793: else if ((*s_objet_argument).type == REL)
2794: {
2795: pourcentage = (*((real8 *) (*s_objet_argument).objet));
2796: }
2797: else
2798: {
2799: liberation(s_etat_processus, s_objet_argument);
2800:
2801: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2802: return;
2803: }
2804:
2805: liberation(s_etat_processus, s_objet_argument);
2806:
2807: if ((pourcentage <= 0) || (pourcentage > 100))
2808: {
2809: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
2810: return;
2811: }
2812:
2813: (*s_etat_processus).pourcentage_maximal_cpu = pourcentage;
2814:
2815: return;
2816: }
2817:
2818: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>