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

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

CVSweb interface <joel.bertrand@systella.fr>