File:  [local] / rpl / src / instructions_s9.c
Revision 1.39: download - view: text, annotated - select for diffs - revision graph
Thu Sep 15 17:51:43 2011 UTC (12 years, 7 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Suite des patches. Attention, il reste une 'race condition' quelque part...

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

CVSweb interface <joel.bertrand@systella.fr>