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

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

CVSweb interface <joel.bertrand@systella.fr>