Annotation of rpl/src/instructions_s9.c, revision 1.37

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

CVSweb interface <joel.bertrand@systella.fr>