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

1.1       bertrand    1: /*
                      2: ================================================================================
1.24    ! bertrand    3:   RPL/2 (R) version 4.1.0.prerelease.2
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.7       bertrand  419: #      ifndef SEMAPHORES_NOMMES
1.1       bertrand  420:        if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
                    421:        {
                    422:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    423:            return;
                    424:        }
1.7       bertrand  425: #      else
                    426:        if (sem_post((*s_etat_processus).semaphore_fork) != 0)
                    427:        {
                    428:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    429:            return;
                    430:        }
                    431: #      endif
1.1       bertrand  432: 
                    433:        if (pthread_mutex_lock(&((*((struct_mutex *) (*s_objet_argument).objet))
                    434:                .mutex)) != 0)
                    435:        {
1.7       bertrand  436: #          ifndef SEMAPHORES_NOMMES
1.1       bertrand  437:            while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.7       bertrand  438: #          else
                    439:            while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
                    440: #          endif
1.1       bertrand  441:            {
                    442:                if ((*s_etat_processus).profilage == d_vrai)
                    443:                {
                    444:                    profilage(s_etat_processus, NULL);
                    445:                }
                    446: 
                    447:                if (errno != EINTR)
                    448:                {
                    449:                    (*s_etat_processus).erreur_systeme = d_es_processus;
                    450:                    return;
                    451:                }
                    452:            }
                    453: 
                    454:            liberation(s_etat_processus, s_objet_argument);
                    455: 
                    456:            if ((*s_etat_processus).profilage == d_vrai)
                    457:            {
                    458:                profilage(s_etat_processus, NULL);
                    459:            }
                    460: 
                    461:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    462:            return;
                    463:        }
                    464: 
1.7       bertrand  465: #      ifndef SEMAPHORES_NOMMES
1.1       bertrand  466:        while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
1.7       bertrand  467: #      else
                    468:        while(sem_wait((*s_etat_processus).semaphore_fork) == -1)
                    469: #      endif
1.1       bertrand  470:        {
                    471:            if (errno != EINTR)
                    472:            {
                    473:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    474:                return;
                    475:            }
                    476:        }
                    477: 
                    478:        if ((*s_etat_processus).profilage == d_vrai)
                    479:        {
                    480:            profilage(s_etat_processus, NULL);
                    481:        }
                    482:    }
                    483:    else
                    484:    {
                    485:        liberation(s_etat_processus, s_objet_argument);
                    486: 
                    487:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    488:        return;
                    489:    }
                    490: 
                    491:    liberation(s_etat_processus, s_objet_argument);
                    492: 
                    493:    return;
                    494: }
                    495: 
                    496: 
                    497: /*
                    498: ================================================================================
                    499:   Fonction 'mtxtrylock'
                    500: ================================================================================
                    501:   Entrées :
                    502: --------------------------------------------------------------------------------
                    503:   Sorties :
                    504: --------------------------------------------------------------------------------
                    505:   Effets de bord : néant
                    506: ================================================================================
                    507: */
                    508: 
                    509: void
                    510: instruction_mtxtrylock(struct_processus *s_etat_processus)
                    511: {
                    512:    int                         ios;
                    513: 
                    514:    struct_liste_chainee        *l_element_courant;
                    515: 
                    516:    struct_objet                *s_objet_argument;
                    517:    struct_objet                *s_objet_resultat;
                    518: 
                    519:    unsigned char               *tampon;
                    520: 
                    521:    (*s_etat_processus).erreur_execution = d_ex;
                    522: 
                    523:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    524:    {
                    525:        printf("\n  MTXTRYLOCK ");
                    526: 
                    527:        if ((*s_etat_processus).langue == 'F')
                    528:        {
                    529:            printf("(essai de verrouillage du mutex)\n\n");
                    530:        }
                    531:        else
                    532:        {
                    533:            printf("(try to lock mutex)\n\n");
                    534:        }
                    535: 
                    536:        printf("    1: %s\n", d_MTX);
                    537:        printf("->  1: %s\n", d_INT);
                    538: 
                    539:        return;
                    540:    }
                    541:    else if ((*s_etat_processus).test_instruction == 'Y')
                    542:    {
                    543:        (*s_etat_processus).nombre_arguments = -1;
                    544:        return;
                    545:    }
                    546: 
                    547:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    548:    {
                    549:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    550:        {
                    551:            return;
                    552:        }
                    553:    }
                    554: 
                    555:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    556:            &s_objet_argument) == d_erreur)
                    557:    {
                    558:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    559:        return;
                    560:    }
                    561: 
                    562:    if ((*s_objet_argument).type == MTX)
                    563:    {
                    564:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    565: 
                    566:        while(l_element_courant != NULL)
                    567:        {
                    568:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    569:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    570:                    .mutex))
                    571:            {
                    572:                break;
                    573:            }
                    574: 
                    575:            l_element_courant = (*l_element_courant).suivant;
                    576:        }
                    577: 
                    578:        if (l_element_courant == NULL)
                    579:        {
                    580:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    581: 
                    582:            liberation(s_etat_processus, s_objet_argument);
                    583:            return;
                    584:        }
                    585: 
                    586:        if ((*s_etat_processus).profilage == d_vrai)
                    587:        {
                    588:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    589:                    == NULL)
                    590:            {
                    591:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    592:                return;
                    593:            }
                    594: 
                    595:            profilage(s_etat_processus, tampon);
                    596:            free(tampon);
                    597: 
                    598:            if ((*s_etat_processus).erreur_systeme != d_es)
                    599:            {
                    600:                return;
                    601:            }
                    602:        }
                    603: 
                    604:        if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
                    605:                (*s_objet_argument).objet)).mutex))) != 0)
                    606:        {
                    607:            if (ios != EBUSY)
                    608:            {
                    609:                liberation(s_etat_processus, s_objet_argument);
                    610: 
                    611:                if ((*s_etat_processus).profilage == d_vrai)
                    612:                {
                    613:                    profilage(s_etat_processus, NULL);
                    614:                }
                    615: 
                    616:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    617:                return;
                    618:            }
                    619:        }
                    620: 
                    621:        if ((*s_etat_processus).profilage == d_vrai)
                    622:        {
                    623:            profilage(s_etat_processus, NULL);
                    624:        }
                    625:    }
                    626:    else
                    627:    {
                    628:        liberation(s_etat_processus, s_objet_argument);
                    629: 
                    630:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    631:        return;
                    632:    }
                    633: 
                    634:    liberation(s_etat_processus, s_objet_argument);
                    635: 
                    636:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    637:            == NULL)
                    638:    {
                    639:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    640:        return;
                    641:    }
                    642: 
                    643:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    644: 
                    645:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    646:            s_objet_resultat) == d_erreur)
                    647:    {
                    648:        return;
                    649:    }
                    650: 
                    651:    return;
                    652: }
                    653: 
                    654: /*
                    655: ================================================================================
                    656:   Fonction 'mtxstatus'
                    657: ================================================================================
                    658:   Entrées :
                    659: --------------------------------------------------------------------------------
                    660:   Sorties :
                    661: --------------------------------------------------------------------------------
                    662:   Effets de bord : néant
                    663: ================================================================================
                    664: */
                    665: 
                    666: void
                    667: instruction_mtxstatus(struct_processus *s_etat_processus)
                    668: {
                    669:    int                         ios;
                    670: 
                    671:    struct_liste_chainee        *l_element_courant;
                    672: 
                    673:    struct_objet                *s_objet_argument;
                    674:    struct_objet                *s_objet_resultat;
                    675: 
                    676:    unsigned char               *tampon;
                    677: 
                    678:    (*s_etat_processus).erreur_execution = d_ex;
                    679: 
                    680:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    681:    {
                    682:        printf("\n  MTXSTATUS ");
                    683: 
                    684:        if ((*s_etat_processus).langue == 'F')
                    685:        {
                    686:            printf("(statut du mutex)\n\n");
                    687:        }
                    688:        else
                    689:        {
                    690:            printf("(mutex status)\n\n");
                    691:        }
                    692: 
                    693:        printf("    1: %s\n", d_MTX);
                    694:        printf("->  1: %s\n", d_INT);
                    695: 
                    696:        return;
                    697:    }
                    698:    else if ((*s_etat_processus).test_instruction == 'Y')
                    699:    {
                    700:        (*s_etat_processus).nombre_arguments = -1;
                    701:        return;
                    702:    }
                    703: 
                    704:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    705:    {
                    706:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    707:        {
                    708:            return;
                    709:        }
                    710:    }
                    711: 
                    712:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    713:            &s_objet_argument) == d_erreur)
                    714:    {
                    715:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    716:        return;
                    717:    }
                    718: 
                    719:    if ((*s_objet_argument).type == MTX)
                    720:    {
                    721:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    722: 
                    723:        while(l_element_courant != NULL)
                    724:        {
                    725:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    726:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    727:                    .mutex))
                    728:            {
                    729:                break;
                    730:            }
                    731: 
                    732:            l_element_courant = (*l_element_courant).suivant;
                    733:        }
                    734: 
                    735:        if (l_element_courant == NULL)
                    736:        {
                    737:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    738: 
                    739:            liberation(s_etat_processus, s_objet_argument);
                    740:            return;
                    741:        }
                    742: 
                    743:        if ((*s_etat_processus).profilage == d_vrai)
                    744:        {
                    745:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    746:                    == NULL)
                    747:            {
                    748:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    749:                return;
                    750:            }
                    751: 
                    752:            profilage(s_etat_processus, tampon);
                    753:            free(tampon);
                    754: 
                    755:            if ((*s_etat_processus).erreur_systeme != d_es)
                    756:            {
                    757:                return;
                    758:            }
                    759:        }
                    760: 
                    761:        if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
                    762:                (*s_objet_argument).objet)).mutex))) != 0)
                    763:        {
                    764:            if (ios != EBUSY)
                    765:            {
                    766:                liberation(s_etat_processus, s_objet_argument);
                    767: 
                    768:                if ((*s_etat_processus).profilage == d_vrai)
                    769:                {
                    770:                    profilage(s_etat_processus, NULL);
                    771:                }
                    772: 
                    773:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    774:                return;
                    775:            }
                    776:        }
                    777: 
                    778:        if (pthread_mutex_unlock(&((*((struct_mutex *)
                    779:                (*s_objet_argument).objet)).mutex)) != 0)
                    780:        {
                    781:            liberation(s_etat_processus, s_objet_argument);
                    782: 
                    783:            if ((*s_etat_processus).profilage == d_vrai)
                    784:            {
                    785:                profilage(s_etat_processus, NULL);
                    786:            }
                    787: 
                    788:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    789:            return;
                    790:        }
                    791: 
                    792:        if ((*s_etat_processus).profilage == d_vrai)
                    793:        {
                    794:            profilage(s_etat_processus, NULL);
                    795:        }
                    796:    }
                    797:    else
                    798:    {
                    799:        liberation(s_etat_processus, s_objet_argument);
                    800: 
                    801:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    802:        return;
                    803:    }
                    804: 
                    805:    liberation(s_etat_processus, s_objet_argument);
                    806: 
                    807:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    808:            == NULL)
                    809:    {
                    810:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    811:        return;
                    812:    }
                    813: 
                    814:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    815: 
                    816:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    817:            s_objet_resultat) == d_erreur)
                    818:    {
                    819:        return;
                    820:    }
                    821: 
                    822:    return;
                    823: }
                    824: 
                    825: 
                    826: /*
                    827: ================================================================================
                    828:   Fonction 'mtxunlock'
                    829: ================================================================================
                    830:   Entrées :
                    831: --------------------------------------------------------------------------------
                    832:   Sorties :
                    833: --------------------------------------------------------------------------------
                    834:   Effets de bord : néant
                    835: ================================================================================
                    836: */
                    837: 
                    838: void
                    839: instruction_mtxunlock(struct_processus *s_etat_processus)
                    840: {
                    841:    struct_liste_chainee        *l_element_courant;
                    842: 
                    843:    struct_objet                *s_objet_argument;
                    844: 
                    845:    (*s_etat_processus).erreur_execution = d_ex;
                    846: 
                    847:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    848:    {
                    849:        printf("\n  MTXUNLOCK ");
                    850: 
                    851:        if ((*s_etat_processus).langue == 'F')
                    852:        {
                    853:            printf("(déverrouille un mutex)\n\n");
                    854:        }
                    855:        else
                    856:        {
                    857:            printf("(unlock mutex)\n\n");
                    858:        }
                    859: 
                    860:        printf("    1: %s\n", d_MTX);
                    861: 
                    862:        return;
                    863:    }
                    864:    else if ((*s_etat_processus).test_instruction == 'Y')
                    865:    {
                    866:        (*s_etat_processus).nombre_arguments = -1;
                    867:        return;
                    868:    }
                    869: 
                    870:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    871:    {
                    872:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    873:        {
                    874:            return;
                    875:        }
                    876:    }
                    877: 
                    878:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    879:            &s_objet_argument) == d_erreur)
                    880:    {
                    881:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    882:        return;
                    883:    }
                    884: 
                    885:    if ((*s_objet_argument).type == MTX)
                    886:    {
                    887:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    888: 
                    889:        while(l_element_courant != NULL)
                    890:        {
                    891:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    892:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    893:                    .mutex))
                    894:            {
                    895:                break;
                    896:            }
                    897: 
                    898:            l_element_courant = (*l_element_courant).suivant;
                    899:        }
                    900: 
                    901:        if (l_element_courant == NULL)
                    902:        {
                    903:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    904: 
                    905:            liberation(s_etat_processus, s_objet_argument);
                    906:            return;
                    907:        }
                    908: 
                    909:        if (pthread_mutex_trylock(&((*((struct_mutex *)
                    910:                (*s_objet_argument).objet)).mutex)) == EINVAL)
                    911:        {
                    912:            liberation(s_etat_processus, s_objet_argument);
                    913: 
                    914:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    915:            return;
                    916:        }
                    917: 
                    918:        if (pthread_mutex_unlock(&((*((struct_mutex *)
                    919:                (*s_objet_argument).objet)).mutex)) != 0)
                    920:        {
                    921:            liberation(s_etat_processus, s_objet_argument);
                    922: 
                    923:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    924:            return;
                    925:        }
                    926:    }
                    927:    else
                    928:    {
                    929:        liberation(s_etat_processus, s_objet_argument);
                    930: 
                    931:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    932:        return;
                    933:    }
                    934: 
                    935:    liberation(s_etat_processus, s_objet_argument);
                    936: 
                    937:    return;
                    938: }
                    939: 
                    940: 
                    941: /*
                    942: ================================================================================
                    943:   Fonction 'mark'
                    944: ================================================================================
                    945:   Entrées :
                    946: --------------------------------------------------------------------------------
                    947:   Sorties :
                    948: --------------------------------------------------------------------------------
                    949:   Effets de bord : néant
                    950: ================================================================================
                    951: */
                    952: 
                    953: void
                    954: instruction_mark(struct_processus *s_etat_processus)
                    955: {
                    956:    struct_marque               *marque;
                    957: 
                    958:    struct_objet                *s_objet_argument;
                    959:    struct_objet                *s_objet_label;
                    960: 
                    961:    (*s_etat_processus).erreur_execution = d_ex;
                    962: 
                    963:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    964:    {
                    965:        printf("\n  MARK ");
                    966: 
                    967:        if ((*s_etat_processus).langue == 'F')
                    968:        {
                    969:            printf("(ajoute une marque à un graphique)\n\n");
                    970:        }
                    971:        else
                    972:        {
                    973:            printf("(add mark to graph)\n\n");
                    974:        }
                    975: 
                    976:        printf("    2: %s\n", d_CHN);
                    977:        printf("    1: %s\n", d_CPL);
                    978: 
                    979:        return;
                    980:    }
                    981:    else if ((*s_etat_processus).test_instruction == 'Y')
                    982:    {
                    983:        (*s_etat_processus).nombre_arguments = -1;
                    984:        return;
                    985:    }
                    986: 
                    987:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    988:    {
                    989:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    990:        {
                    991:            return;
                    992:        }
                    993:    }
                    994: 
                    995:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    996:            &s_objet_argument) == d_erreur)
                    997:    {
                    998:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    999:        return;
                   1000:    }
                   1001: 
                   1002:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1003:            &s_objet_label) == d_erreur)
                   1004:    {
                   1005:        liberation(s_etat_processus, s_objet_argument);
                   1006: 
                   1007:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1008:        return;
                   1009:    }
                   1010: 
                   1011:    if (((*s_objet_argument).type == CPL) && ((*s_objet_label).type == CHN))
                   1012:    {
                   1013:        if ((marque = malloc(sizeof(struct_marque))) == NULL)
                   1014:        {
                   1015:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1016:            return;
                   1017:        }
                   1018: 
                   1019:        if (((*marque).label = malloc((strlen((unsigned char *)
                   1020:                (*s_objet_label).objet) + 1) * sizeof(unsigned char))) == NULL)
                   1021:        {
                   1022:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1023:            return;
                   1024:        }
                   1025: 
                   1026:        sprintf((*marque).label, "%s",
                   1027:                (unsigned char *) (*s_objet_label).objet);
                   1028: 
                   1029:        if (((*marque).position = malloc(64 * sizeof(unsigned char))) == NULL)
                   1030:        {
                   1031:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1032:            return;
                   1033:        }
                   1034: 
                   1035:        sprintf((*marque).position, "%f,%f",
                   1036:                (*((complex16 *) (*s_objet_argument).objet)).partie_reelle,
                   1037:                (*((complex16 *) (*s_objet_argument).objet)).partie_imaginaire);
                   1038: 
                   1039:        (*marque).suivant = (*s_etat_processus).s_marques;
                   1040:        (*s_etat_processus).s_marques = marque;
                   1041: 
                   1042:        (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
                   1043:    }
                   1044:    else
                   1045:    {
                   1046:        liberation(s_etat_processus, s_objet_argument);
                   1047:        liberation(s_etat_processus, s_objet_label);
                   1048: 
                   1049:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1050:        return;
                   1051:    }
                   1052: 
                   1053:    liberation(s_etat_processus, s_objet_argument);
                   1054:    liberation(s_etat_processus, s_objet_label);
                   1055: 
                   1056:    return;
                   1057: }
                   1058: 
                   1059: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>