Annotation of rpl/src/instructions_m4.c, revision 1.33

1.1       bertrand    1: /*
                      2: ================================================================================
1.30      bertrand    3:   RPL/2 (R) version 4.1.3
1.16      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.12      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'mem'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_mem(struct_processus *s_etat_processus)
                     40: {
1.23      bertrand   41:    int                         j;
                     42:    int                         nb_variables;
1.1       bertrand   43: 
1.23      bertrand   44:    struct_liste_chainee        *l_element_courant;
                     45: 
                     46:    struct_objet                *s_objet_resultat;
                     47: 
                     48:    struct_tableau_variables    *tableau;
1.1       bertrand   49: 
1.23      bertrand   50:    unsigned long               i;
1.1       bertrand   51: 
                     52:    (*s_etat_processus).erreur_execution = d_ex;
                     53: 
                     54:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     55:    {
                     56:        printf("\n  MEM ");
                     57: 
                     58:        if ((*s_etat_processus).langue == 'F')
                     59:        {
                     60:            printf("(mémoire occupée)\n\n");
                     61:        }
                     62:        else
                     63:        {
                     64:            printf("(used memory)\n\n");
                     65:        }
                     66: 
                     67:        printf("->  1: %s\n", d_LST);
                     68: 
                     69:        return;
                     70:    }
                     71:    else if ((*s_etat_processus).test_instruction == 'Y')
                     72:    {
                     73:        (*s_etat_processus).nombre_arguments = -1;
                     74:        return;
                     75:    }
                     76: 
                     77:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                     78:    {
                     79:        if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
                     80:        {
                     81:            return;
                     82:        }
                     83:    }
                     84: 
                     85:    if ((s_objet_resultat = allocation(s_etat_processus, LST))
                     86:            == NULL)
                     87:    {
                     88:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                     89:        return;
                     90:    }
                     91: 
                     92:    if (((*s_objet_resultat).objet =
                     93:                allocation_maillon(s_etat_processus)) == NULL)
                     94:    {
                     95:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                     96:        return;
                     97:    }
                     98: 
                     99:    if (((*((struct_liste_chainee *) (*s_objet_resultat).objet)).donnee =
                    100:            allocation(s_etat_processus, INT)) == NULL)
                    101:    {
                    102:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    103:        return;
                    104:    }
                    105: 
                    106:    /*
                    107:     * Décompte de la mémoire utilisée dans la pile
                    108:     */
                    109: 
                    110:    (*((integer8 *) (*((*((struct_liste_chainee *) (*s_objet_resultat).objet))
                    111:            .donnee)).objet)) = 0;
                    112: 
                    113:    l_element_courant = (*s_etat_processus).l_base_pile;
                    114: 
                    115:    while(l_element_courant != NULL)
                    116:    {
                    117:        (*((integer8 *) (*((*((struct_liste_chainee *) (*s_objet_resultat)
                    118:                .objet)).donnee)).objet)) += occupation_memoire(
                    119:                (*l_element_courant).donnee);
                    120:        l_element_courant = (*l_element_courant).suivant;
                    121:    }
                    122: 
                    123:    /*
                    124:     * Décompte de la mémoire utilisée pour les différentes variables
                    125:     */
                    126: 
                    127:    if (((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant
                    128:            = allocation_maillon(s_etat_processus)) == NULL)
                    129:    {
                    130:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    131:        return;
                    132:    }
                    133: 
                    134:    if (((*((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant))
                    135:            .donnee = allocation(s_etat_processus, INT)) == NULL)
                    136:    {
                    137:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    138:        return;
                    139:    }
                    140: 
                    141:    (*((*((struct_liste_chainee *) (*s_objet_resultat).objet)).suivant))
                    142:            .suivant = NULL;
                    143: 
                    144:    (*((integer8 *) (*((*((*((struct_liste_chainee *)
                    145:            (*s_objet_resultat).objet)).suivant)).donnee)).objet)) = 0;
                    146: 
1.23      bertrand  147:    nb_variables = nombre_variables(s_etat_processus,
                    148:            (*s_etat_processus).s_arbre_variables);
                    149: 
                    150:    if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables)))
                    151:            == NULL)
                    152:    {
                    153:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    154:        return;
                    155:    }
                    156: 
                    157:    liste_variables(s_etat_processus, tableau, 0,
                    158:            (*s_etat_processus).s_arbre_variables);
                    159: 
                    160:    for(j = 0; j < nb_variables; j++)
1.1       bertrand  161:    {
                    162:        (*((integer8 *) (*((*((*((struct_liste_chainee *) (*s_objet_resultat)
                    163:                .objet)).suivant)).donnee)).objet)) += sizeof(unsigned char) *
1.23      bertrand  164:                strlen(tableau[j].nom);
1.1       bertrand  165:        (*((integer8 *) (*((*((*((struct_liste_chainee *) (*s_objet_resultat)
                    166:                .objet)).suivant)).donnee)).objet)) += occupation_memoire(
1.23      bertrand  167:                tableau[j].objet);
1.1       bertrand  168:    }
1.23      bertrand  169: 
                    170:    free(tableau);
1.1       bertrand  171: 
                    172:    for(i = 0; i < (*s_etat_processus).nombre_variables_statiques; i++)
                    173:    {
                    174:        // Comptabilisation des empreintes mémoire des variables
                    175:        // statiques qui ne sont pas accessibles, les variables statiques
                    176:        // accessibles étant déjà comptabilitées par la boucle précédente.
                    177: 
                    178:        if ((*s_etat_processus).s_liste_variables_statiques[i].objet != NULL)
                    179:        {
                    180:            (*((integer8 *) (*((*((*((struct_liste_chainee *)
                    181:                    (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
                    182:                    sizeof(unsigned char) * strlen((*s_etat_processus)
                    183:                    .s_liste_variables_statiques[i].nom);
                    184:            (*((integer8 *) (*((*((*((struct_liste_chainee *)
                    185:                    (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
                    186:                    occupation_memoire((*s_etat_processus)
                    187:                    .s_liste_variables_statiques[i].objet);
                    188:        }
                    189:    }
                    190: 
                    191:    for(i = 0; i < (*(*s_etat_processus).s_liste_variables_partagees)
                    192:            .nombre_variables; i++)
                    193:    {
                    194:        (*((integer8 *) (*((*((*((struct_liste_chainee *)
                    195:                (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
                    196:                sizeof(unsigned char) * strlen((*(*s_etat_processus)
                    197:                .s_liste_variables_partagees).table[i].nom);
                    198:        (*((integer8 *) (*((*((*((struct_liste_chainee *)
                    199:                (*s_objet_resultat).objet)).suivant)).donnee)).objet)) +=
                    200:                occupation_memoire((*(*s_etat_processus)
                    201:                .s_liste_variables_partagees).table[i].objet);
                    202:    }
                    203: 
                    204:    /*
                    205:     * Empilement du résultat
                    206:     */
                    207: 
                    208:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    209:            s_objet_resultat) == d_erreur)
                    210:    {
                    211:        return;
                    212:    }
                    213: 
                    214:    return;
                    215: }
                    216: 
                    217: 
                    218: /*
                    219: ================================================================================
                    220:   Fonction 'mclrin'
                    221: ================================================================================
                    222:   Entrées :
                    223: --------------------------------------------------------------------------------
                    224:   Sorties :
                    225: --------------------------------------------------------------------------------
                    226:   Effets de bord : néant
                    227: ================================================================================
                    228: */
                    229: 
                    230: void
                    231: instruction_mclrin(struct_processus *s_etat_processus)
                    232: {
                    233:    logical1                    last_valide;
                    234: 
                    235:    struct_liste_chainee        *l_liste;
                    236: 
                    237:    struct_objet                *s_objet;
                    238: 
                    239:    (*s_etat_processus).erreur_execution = d_ex;
                    240: 
                    241:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    242:    {
                    243:        printf("\n  MCLRIN ");
                    244: 
                    245:        if ((*s_etat_processus).langue == 'F')
                    246:        {
                    247:            printf("(série de MacLaurin)\n\n");
                    248:        }
                    249:        else
                    250:        {
                    251:            printf("(MacLaurin serie)\n\n");
                    252:        }
                    253: 
                    254:        printf("    3: %s\n", d_ALG);
                    255:        printf("    2: %s\n", d_NOM);
                    256:        printf("    1: %s\n", d_INT);
                    257:        printf("->  1: %s\n", d_ALG);
                    258: 
                    259:        return;
                    260:    }
                    261:    else if ((*s_etat_processus).test_instruction == 'Y')
                    262:    {
                    263:        (*s_etat_processus).nombre_arguments = -1;
                    264:        return;
                    265:    }
                    266: 
                    267:    if ((last_valide = test_cfsf(s_etat_processus, 31)) == d_vrai)
                    268:    {
                    269:        if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
                    270:        {
                    271:            return;
                    272:        }
                    273:    }
                    274: 
                    275:    if ((*s_etat_processus).hauteur_pile_operationnelle < 3)
                    276:    {
                    277:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    278:        return;
                    279:    }
                    280: 
                    281:    if ((s_objet = allocation(s_etat_processus, INT)) == NULL)
                    282:    {
                    283:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    284:        return;
                    285:    }
                    286: 
                    287:    (*((integer8 *) (*s_objet).objet)) = 0;
                    288: 
                    289:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    290:            s_objet) == d_erreur)
                    291:    {
                    292:        return;
                    293:    }
                    294: 
                    295:    l_liste = (*s_etat_processus).l_base_pile;
                    296:    (*s_etat_processus).l_base_pile = (*l_liste).suivant;
                    297:    (*l_liste).suivant = (*(*s_etat_processus).l_base_pile).suivant;
                    298:    (*(*s_etat_processus).l_base_pile).suivant = l_liste;
                    299: 
                    300:    if (last_valide == d_vrai)
                    301:    {
                    302:        cf(s_etat_processus, 31);
                    303:    }
                    304: 
                    305:    instruction_taylr(s_etat_processus);
                    306: 
                    307:    if (last_valide == d_vrai)
                    308:    {
                    309:        sf(s_etat_processus, 31);
                    310:    }
                    311: 
                    312:    return;
                    313: }
                    314: 
                    315: 
                    316: /*
                    317: ================================================================================
                    318:   Fonction 'mtxlock'
                    319: ================================================================================
                    320:   Entrées :
                    321: --------------------------------------------------------------------------------
                    322:   Sorties :
                    323: --------------------------------------------------------------------------------
                    324:   Effets de bord : néant
                    325: ================================================================================
                    326: */
                    327: 
                    328: void
                    329: instruction_mtxlock(struct_processus *s_etat_processus)
                    330: {
                    331:    struct_liste_chainee        *l_element_courant;
                    332: 
                    333:    struct_objet                *s_objet_argument;
                    334: 
                    335:    unsigned char               *tampon;
                    336: 
                    337:    (*s_etat_processus).erreur_execution = d_ex;
                    338: 
                    339:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    340:    {
                    341:        printf("\n  MTXLOCK ");
                    342: 
                    343:        if ((*s_etat_processus).langue == 'F')
                    344:        {
                    345:            printf("(verrouille un mutex)\n\n");
                    346:        }
                    347:        else
                    348:        {
                    349:            printf("(lock mutex)\n\n");
                    350:        }
                    351: 
                    352:        printf("    1: %s\n", d_MTX);
                    353: 
                    354:        return;
                    355:    }
                    356:    else if ((*s_etat_processus).test_instruction == 'Y')
                    357:    {
                    358:        (*s_etat_processus).nombre_arguments = -1;
                    359:        return;
                    360:    }
                    361: 
                    362:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    363:    {
                    364:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    365:        {
                    366:            return;
                    367:        }
                    368:    }
                    369: 
                    370:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    371:            &s_objet_argument) == d_erreur)
                    372:    {
                    373:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    374:        return;
                    375:    }
                    376: 
                    377:    if ((*s_objet_argument).type == MTX)
                    378:    {
                    379:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    380: 
                    381:        while(l_element_courant != NULL)
                    382:        {
                    383:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    384:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    385:                    .mutex))
                    386:            {
                    387:                break;
                    388:            }
                    389: 
                    390:            l_element_courant = (*l_element_courant).suivant;
                    391:        }
                    392: 
                    393:        if (l_element_courant == NULL)
                    394:        {
                    395:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    396: 
                    397:            liberation(s_etat_processus, s_objet_argument);
                    398:            return;
                    399:        }
                    400: 
                    401:        if ((*s_etat_processus).profilage == d_vrai)
                    402:        {
                    403:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    404:                    == NULL)
                    405:            {
                    406:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    407:                return;
                    408:            }
                    409: 
                    410:            profilage(s_etat_processus, tampon);
                    411:            free(tampon);
                    412: 
                    413:            if ((*s_etat_processus).erreur_systeme != d_es)
                    414:            {
                    415:                return;
                    416:            }
                    417:        }
                    418: 
1.32      bertrand  419:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1.1       bertrand  420:        {
                    421:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    422:            return;
                    423:        }
                    424: 
                    425:        if (pthread_mutex_lock(&((*((struct_mutex *) (*s_objet_argument).objet))
                    426:                .mutex)) != 0)
                    427:        {
1.33    ! bertrand  428:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1       bertrand  429:            {
1.33    ! bertrand  430:                if (errno != EINTR)
        !           431:                {
        !           432:                    (*s_etat_processus).erreur_systeme = d_es_processus;
        !           433:                    return;
        !           434:                }
1.1       bertrand  435:            }
                    436: 
                    437:            liberation(s_etat_processus, s_objet_argument);
                    438: 
                    439:            if ((*s_etat_processus).profilage == d_vrai)
                    440:            {
                    441:                profilage(s_etat_processus, NULL);
                    442:            }
                    443: 
                    444:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    445:            return;
                    446:        }
                    447: 
1.33    ! bertrand  448:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1.1       bertrand  449:        {
1.33    ! bertrand  450:            if (errno != EINTR)
        !           451:            {
        !           452:                (*s_etat_processus).erreur_systeme = d_es_processus;
        !           453:                return;
        !           454:            }
1.1       bertrand  455:        }
                    456: 
                    457:        if ((*s_etat_processus).profilage == d_vrai)
                    458:        {
                    459:            profilage(s_etat_processus, NULL);
                    460:        }
                    461:    }
                    462:    else
                    463:    {
                    464:        liberation(s_etat_processus, s_objet_argument);
                    465: 
                    466:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    467:        return;
                    468:    }
                    469: 
                    470:    liberation(s_etat_processus, s_objet_argument);
                    471: 
                    472:    return;
                    473: }
                    474: 
                    475: 
                    476: /*
                    477: ================================================================================
                    478:   Fonction 'mtxtrylock'
                    479: ================================================================================
                    480:   Entrées :
                    481: --------------------------------------------------------------------------------
                    482:   Sorties :
                    483: --------------------------------------------------------------------------------
                    484:   Effets de bord : néant
                    485: ================================================================================
                    486: */
                    487: 
                    488: void
                    489: instruction_mtxtrylock(struct_processus *s_etat_processus)
                    490: {
                    491:    int                         ios;
                    492: 
                    493:    struct_liste_chainee        *l_element_courant;
                    494: 
                    495:    struct_objet                *s_objet_argument;
                    496:    struct_objet                *s_objet_resultat;
                    497: 
                    498:    unsigned char               *tampon;
                    499: 
                    500:    (*s_etat_processus).erreur_execution = d_ex;
                    501: 
                    502:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    503:    {
                    504:        printf("\n  MTXTRYLOCK ");
                    505: 
                    506:        if ((*s_etat_processus).langue == 'F')
                    507:        {
                    508:            printf("(essai de verrouillage du mutex)\n\n");
                    509:        }
                    510:        else
                    511:        {
                    512:            printf("(try to lock mutex)\n\n");
                    513:        }
                    514: 
                    515:        printf("    1: %s\n", d_MTX);
                    516:        printf("->  1: %s\n", d_INT);
                    517: 
                    518:        return;
                    519:    }
                    520:    else if ((*s_etat_processus).test_instruction == 'Y')
                    521:    {
                    522:        (*s_etat_processus).nombre_arguments = -1;
                    523:        return;
                    524:    }
                    525: 
                    526:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    527:    {
                    528:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    529:        {
                    530:            return;
                    531:        }
                    532:    }
                    533: 
                    534:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    535:            &s_objet_argument) == d_erreur)
                    536:    {
                    537:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    538:        return;
                    539:    }
                    540: 
                    541:    if ((*s_objet_argument).type == MTX)
                    542:    {
                    543:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    544: 
                    545:        while(l_element_courant != NULL)
                    546:        {
                    547:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    548:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    549:                    .mutex))
                    550:            {
                    551:                break;
                    552:            }
                    553: 
                    554:            l_element_courant = (*l_element_courant).suivant;
                    555:        }
                    556: 
                    557:        if (l_element_courant == NULL)
                    558:        {
                    559:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    560: 
                    561:            liberation(s_etat_processus, s_objet_argument);
                    562:            return;
                    563:        }
                    564: 
                    565:        if ((*s_etat_processus).profilage == d_vrai)
                    566:        {
                    567:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    568:                    == NULL)
                    569:            {
                    570:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    571:                return;
                    572:            }
                    573: 
                    574:            profilage(s_etat_processus, tampon);
                    575:            free(tampon);
                    576: 
                    577:            if ((*s_etat_processus).erreur_systeme != d_es)
                    578:            {
                    579:                return;
                    580:            }
                    581:        }
                    582: 
                    583:        if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
                    584:                (*s_objet_argument).objet)).mutex))) != 0)
                    585:        {
                    586:            if (ios != EBUSY)
                    587:            {
                    588:                liberation(s_etat_processus, s_objet_argument);
                    589: 
                    590:                if ((*s_etat_processus).profilage == d_vrai)
                    591:                {
                    592:                    profilage(s_etat_processus, NULL);
                    593:                }
                    594: 
                    595:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    596:                return;
                    597:            }
                    598:        }
                    599: 
                    600:        if ((*s_etat_processus).profilage == d_vrai)
                    601:        {
                    602:            profilage(s_etat_processus, NULL);
                    603:        }
                    604:    }
                    605:    else
                    606:    {
                    607:        liberation(s_etat_processus, s_objet_argument);
                    608: 
                    609:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    610:        return;
                    611:    }
                    612: 
                    613:    liberation(s_etat_processus, s_objet_argument);
                    614: 
                    615:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    616:            == NULL)
                    617:    {
                    618:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    619:        return;
                    620:    }
                    621: 
                    622:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    623: 
                    624:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    625:            s_objet_resultat) == d_erreur)
                    626:    {
                    627:        return;
                    628:    }
                    629: 
                    630:    return;
                    631: }
                    632: 
                    633: /*
                    634: ================================================================================
                    635:   Fonction 'mtxstatus'
                    636: ================================================================================
                    637:   Entrées :
                    638: --------------------------------------------------------------------------------
                    639:   Sorties :
                    640: --------------------------------------------------------------------------------
                    641:   Effets de bord : néant
                    642: ================================================================================
                    643: */
                    644: 
                    645: void
                    646: instruction_mtxstatus(struct_processus *s_etat_processus)
                    647: {
                    648:    int                         ios;
                    649: 
                    650:    struct_liste_chainee        *l_element_courant;
                    651: 
                    652:    struct_objet                *s_objet_argument;
                    653:    struct_objet                *s_objet_resultat;
                    654: 
                    655:    unsigned char               *tampon;
                    656: 
                    657:    (*s_etat_processus).erreur_execution = d_ex;
                    658: 
                    659:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    660:    {
                    661:        printf("\n  MTXSTATUS ");
                    662: 
                    663:        if ((*s_etat_processus).langue == 'F')
                    664:        {
                    665:            printf("(statut du mutex)\n\n");
                    666:        }
                    667:        else
                    668:        {
                    669:            printf("(mutex status)\n\n");
                    670:        }
                    671: 
                    672:        printf("    1: %s\n", d_MTX);
                    673:        printf("->  1: %s\n", d_INT);
                    674: 
                    675:        return;
                    676:    }
                    677:    else if ((*s_etat_processus).test_instruction == 'Y')
                    678:    {
                    679:        (*s_etat_processus).nombre_arguments = -1;
                    680:        return;
                    681:    }
                    682: 
                    683:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    684:    {
                    685:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    686:        {
                    687:            return;
                    688:        }
                    689:    }
                    690: 
                    691:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    692:            &s_objet_argument) == d_erreur)
                    693:    {
                    694:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    695:        return;
                    696:    }
                    697: 
                    698:    if ((*s_objet_argument).type == MTX)
                    699:    {
                    700:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    701: 
                    702:        while(l_element_courant != NULL)
                    703:        {
                    704:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    705:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    706:                    .mutex))
                    707:            {
                    708:                break;
                    709:            }
                    710: 
                    711:            l_element_courant = (*l_element_courant).suivant;
                    712:        }
                    713: 
                    714:        if (l_element_courant == NULL)
                    715:        {
                    716:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    717: 
                    718:            liberation(s_etat_processus, s_objet_argument);
                    719:            return;
                    720:        }
                    721: 
                    722:        if ((*s_etat_processus).profilage == d_vrai)
                    723:        {
                    724:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    725:                    == NULL)
                    726:            {
                    727:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    728:                return;
                    729:            }
                    730: 
                    731:            profilage(s_etat_processus, tampon);
                    732:            free(tampon);
                    733: 
                    734:            if ((*s_etat_processus).erreur_systeme != d_es)
                    735:            {
                    736:                return;
                    737:            }
                    738:        }
                    739: 
                    740:        if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
                    741:                (*s_objet_argument).objet)).mutex))) != 0)
                    742:        {
                    743:            if (ios != EBUSY)
                    744:            {
                    745:                liberation(s_etat_processus, s_objet_argument);
                    746: 
                    747:                if ((*s_etat_processus).profilage == d_vrai)
                    748:                {
                    749:                    profilage(s_etat_processus, NULL);
                    750:                }
                    751: 
                    752:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    753:                return;
                    754:            }
                    755:        }
                    756: 
                    757:        if (pthread_mutex_unlock(&((*((struct_mutex *)
                    758:                (*s_objet_argument).objet)).mutex)) != 0)
                    759:        {
                    760:            liberation(s_etat_processus, s_objet_argument);
                    761: 
                    762:            if ((*s_etat_processus).profilage == d_vrai)
                    763:            {
                    764:                profilage(s_etat_processus, NULL);
                    765:            }
                    766: 
                    767:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    768:            return;
                    769:        }
                    770: 
                    771:        if ((*s_etat_processus).profilage == d_vrai)
                    772:        {
                    773:            profilage(s_etat_processus, NULL);
                    774:        }
                    775:    }
                    776:    else
                    777:    {
                    778:        liberation(s_etat_processus, s_objet_argument);
                    779: 
                    780:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    781:        return;
                    782:    }
                    783: 
                    784:    liberation(s_etat_processus, s_objet_argument);
                    785: 
                    786:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    787:            == NULL)
                    788:    {
                    789:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    790:        return;
                    791:    }
                    792: 
                    793:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    794: 
                    795:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    796:            s_objet_resultat) == d_erreur)
                    797:    {
                    798:        return;
                    799:    }
                    800: 
                    801:    return;
                    802: }
                    803: 
                    804: 
                    805: /*
                    806: ================================================================================
                    807:   Fonction 'mtxunlock'
                    808: ================================================================================
                    809:   Entrées :
                    810: --------------------------------------------------------------------------------
                    811:   Sorties :
                    812: --------------------------------------------------------------------------------
                    813:   Effets de bord : néant
                    814: ================================================================================
                    815: */
                    816: 
                    817: void
                    818: instruction_mtxunlock(struct_processus *s_etat_processus)
                    819: {
                    820:    struct_liste_chainee        *l_element_courant;
                    821: 
                    822:    struct_objet                *s_objet_argument;
                    823: 
                    824:    (*s_etat_processus).erreur_execution = d_ex;
                    825: 
                    826:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    827:    {
                    828:        printf("\n  MTXUNLOCK ");
                    829: 
                    830:        if ((*s_etat_processus).langue == 'F')
                    831:        {
                    832:            printf("(déverrouille un mutex)\n\n");
                    833:        }
                    834:        else
                    835:        {
                    836:            printf("(unlock mutex)\n\n");
                    837:        }
                    838: 
                    839:        printf("    1: %s\n", d_MTX);
                    840: 
                    841:        return;
                    842:    }
                    843:    else if ((*s_etat_processus).test_instruction == 'Y')
                    844:    {
                    845:        (*s_etat_processus).nombre_arguments = -1;
                    846:        return;
                    847:    }
                    848: 
                    849:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    850:    {
                    851:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    852:        {
                    853:            return;
                    854:        }
                    855:    }
                    856: 
                    857:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    858:            &s_objet_argument) == d_erreur)
                    859:    {
                    860:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    861:        return;
                    862:    }
                    863: 
                    864:    if ((*s_objet_argument).type == MTX)
                    865:    {
                    866:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    867: 
                    868:        while(l_element_courant != NULL)
                    869:        {
                    870:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    871:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    872:                    .mutex))
                    873:            {
                    874:                break;
                    875:            }
                    876: 
                    877:            l_element_courant = (*l_element_courant).suivant;
                    878:        }
                    879: 
                    880:        if (l_element_courant == NULL)
                    881:        {
                    882:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    883: 
                    884:            liberation(s_etat_processus, s_objet_argument);
                    885:            return;
                    886:        }
                    887: 
                    888:        if (pthread_mutex_trylock(&((*((struct_mutex *)
                    889:                (*s_objet_argument).objet)).mutex)) == EINVAL)
                    890:        {
                    891:            liberation(s_etat_processus, s_objet_argument);
                    892: 
                    893:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    894:            return;
                    895:        }
                    896: 
                    897:        if (pthread_mutex_unlock(&((*((struct_mutex *)
                    898:                (*s_objet_argument).objet)).mutex)) != 0)
                    899:        {
                    900:            liberation(s_etat_processus, s_objet_argument);
                    901: 
                    902:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    903:            return;
                    904:        }
                    905:    }
                    906:    else
                    907:    {
                    908:        liberation(s_etat_processus, s_objet_argument);
                    909: 
                    910:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    911:        return;
                    912:    }
                    913: 
                    914:    liberation(s_etat_processus, s_objet_argument);
                    915: 
                    916:    return;
                    917: }
                    918: 
                    919: 
                    920: /*
                    921: ================================================================================
                    922:   Fonction 'mark'
                    923: ================================================================================
                    924:   Entrées :
                    925: --------------------------------------------------------------------------------
                    926:   Sorties :
                    927: --------------------------------------------------------------------------------
                    928:   Effets de bord : néant
                    929: ================================================================================
                    930: */
                    931: 
                    932: void
                    933: instruction_mark(struct_processus *s_etat_processus)
                    934: {
                    935:    struct_marque               *marque;
                    936: 
                    937:    struct_objet                *s_objet_argument;
                    938:    struct_objet                *s_objet_label;
                    939: 
                    940:    (*s_etat_processus).erreur_execution = d_ex;
                    941: 
                    942:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    943:    {
                    944:        printf("\n  MARK ");
                    945: 
                    946:        if ((*s_etat_processus).langue == 'F')
                    947:        {
                    948:            printf("(ajoute une marque à un graphique)\n\n");
                    949:        }
                    950:        else
                    951:        {
                    952:            printf("(add mark to graph)\n\n");
                    953:        }
                    954: 
                    955:        printf("    2: %s\n", d_CHN);
                    956:        printf("    1: %s\n", d_CPL);
                    957: 
                    958:        return;
                    959:    }
                    960:    else if ((*s_etat_processus).test_instruction == 'Y')
                    961:    {
                    962:        (*s_etat_processus).nombre_arguments = -1;
                    963:        return;
                    964:    }
                    965: 
                    966:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    967:    {
                    968:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    969:        {
                    970:            return;
                    971:        }
                    972:    }
                    973: 
                    974:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    975:            &s_objet_argument) == d_erreur)
                    976:    {
                    977:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    978:        return;
                    979:    }
                    980: 
                    981:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    982:            &s_objet_label) == d_erreur)
                    983:    {
                    984:        liberation(s_etat_processus, s_objet_argument);
                    985: 
                    986:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    987:        return;
                    988:    }
                    989: 
                    990:    if (((*s_objet_argument).type == CPL) && ((*s_objet_label).type == CHN))
                    991:    {
                    992:        if ((marque = malloc(sizeof(struct_marque))) == NULL)
                    993:        {
                    994:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    995:            return;
                    996:        }
                    997: 
                    998:        if (((*marque).label = malloc((strlen((unsigned char *)
                    999:                (*s_objet_label).objet) + 1) * sizeof(unsigned char))) == NULL)
                   1000:        {
                   1001:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1002:            return;
                   1003:        }
                   1004: 
                   1005:        sprintf((*marque).label, "%s",
                   1006:                (unsigned char *) (*s_objet_label).objet);
                   1007: 
                   1008:        if (((*marque).position = malloc(64 * sizeof(unsigned char))) == NULL)
                   1009:        {
                   1010:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1011:            return;
                   1012:        }
                   1013: 
                   1014:        sprintf((*marque).position, "%f,%f",
                   1015:                (*((complex16 *) (*s_objet_argument).objet)).partie_reelle,
                   1016:                (*((complex16 *) (*s_objet_argument).objet)).partie_imaginaire);
                   1017: 
                   1018:        (*marque).suivant = (*s_etat_processus).s_marques;
                   1019:        (*s_etat_processus).s_marques = marque;
                   1020: 
                   1021:        (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
                   1022:    }
                   1023:    else
                   1024:    {
                   1025:        liberation(s_etat_processus, s_objet_argument);
                   1026:        liberation(s_etat_processus, s_objet_label);
                   1027: 
                   1028:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1029:        return;
                   1030:    }
                   1031: 
                   1032:    liberation(s_etat_processus, s_objet_argument);
                   1033:    liberation(s_etat_processus, s_objet_label);
                   1034: 
                   1035:    return;
                   1036: }
                   1037: 
                   1038: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>