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

1.1       bertrand    1: /*
                      2: ================================================================================
1.40    ! bertrand    3:   RPL/2 (R) version 4.1.7
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:        }
                    613: 
1.37      bertrand  614:        (*((struct_mutex *) (*s_objet_argument).objet)).tid = pthread_self();
                    615: 
1.1       bertrand  616:        if ((*s_etat_processus).profilage == d_vrai)
                    617:        {
                    618:            profilage(s_etat_processus, NULL);
                    619:        }
                    620:    }
                    621:    else
                    622:    {
                    623:        liberation(s_etat_processus, s_objet_argument);
                    624: 
                    625:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    626:        return;
                    627:    }
                    628: 
                    629:    liberation(s_etat_processus, s_objet_argument);
                    630: 
                    631:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    632:            == NULL)
                    633:    {
                    634:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    635:        return;
                    636:    }
                    637: 
                    638:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    639: 
                    640:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    641:            s_objet_resultat) == d_erreur)
                    642:    {
                    643:        return;
                    644:    }
                    645: 
                    646:    return;
                    647: }
                    648: 
1.37      bertrand  649: 
1.1       bertrand  650: /*
                    651: ================================================================================
                    652:   Fonction 'mtxstatus'
                    653: ================================================================================
                    654:   Entrées :
                    655: --------------------------------------------------------------------------------
                    656:   Sorties :
                    657: --------------------------------------------------------------------------------
                    658:   Effets de bord : néant
                    659: ================================================================================
                    660: */
                    661: 
                    662: void
                    663: instruction_mtxstatus(struct_processus *s_etat_processus)
                    664: {
                    665:    int                         ios;
                    666: 
                    667:    struct_liste_chainee        *l_element_courant;
                    668: 
                    669:    struct_objet                *s_objet_argument;
                    670:    struct_objet                *s_objet_resultat;
                    671: 
                    672:    unsigned char               *tampon;
                    673: 
                    674:    (*s_etat_processus).erreur_execution = d_ex;
                    675: 
                    676:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    677:    {
                    678:        printf("\n  MTXSTATUS ");
                    679: 
                    680:        if ((*s_etat_processus).langue == 'F')
                    681:        {
                    682:            printf("(statut du mutex)\n\n");
                    683:        }
                    684:        else
                    685:        {
                    686:            printf("(mutex status)\n\n");
                    687:        }
                    688: 
                    689:        printf("    1: %s\n", d_MTX);
                    690:        printf("->  1: %s\n", d_INT);
                    691: 
                    692:        return;
                    693:    }
                    694:    else if ((*s_etat_processus).test_instruction == 'Y')
                    695:    {
                    696:        (*s_etat_processus).nombre_arguments = -1;
                    697:        return;
                    698:    }
                    699: 
                    700:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    701:    {
                    702:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    703:        {
                    704:            return;
                    705:        }
                    706:    }
                    707: 
                    708:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    709:            &s_objet_argument) == d_erreur)
                    710:    {
                    711:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    712:        return;
                    713:    }
                    714: 
                    715:    if ((*s_objet_argument).type == MTX)
                    716:    {
                    717:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    718: 
                    719:        while(l_element_courant != NULL)
                    720:        {
                    721:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    722:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    723:                    .mutex))
                    724:            {
                    725:                break;
                    726:            }
                    727: 
                    728:            l_element_courant = (*l_element_courant).suivant;
                    729:        }
                    730: 
                    731:        if (l_element_courant == NULL)
                    732:        {
                    733:            (*s_etat_processus).erreur_execution = d_ex_mutex;
                    734: 
                    735:            liberation(s_etat_processus, s_objet_argument);
                    736:            return;
                    737:        }
                    738: 
                    739:        if ((*s_etat_processus).profilage == d_vrai)
                    740:        {
                    741:            if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
                    742:                    == NULL)
                    743:            {
                    744:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    745:                return;
                    746:            }
                    747: 
                    748:            profilage(s_etat_processus, tampon);
                    749:            free(tampon);
                    750: 
                    751:            if ((*s_etat_processus).erreur_systeme != d_es)
                    752:            {
                    753:                return;
                    754:            }
                    755:        }
                    756: 
                    757:        if ((ios = pthread_mutex_trylock(&((*((struct_mutex *)
                    758:                (*s_objet_argument).objet)).mutex))) != 0)
                    759:        {
                    760:            if (ios != EBUSY)
                    761:            {
                    762:                liberation(s_etat_processus, s_objet_argument);
                    763: 
                    764:                if ((*s_etat_processus).profilage == d_vrai)
                    765:                {
                    766:                    profilage(s_etat_processus, NULL);
                    767:                }
                    768: 
                    769:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    770:                return;
                    771:            }
                    772:        }
                    773: 
1.37      bertrand  774:        if (ios == 0)
1.1       bertrand  775:        {
1.37      bertrand  776:            // Le mutex a été verrouillé par le trylock précédent.
1.1       bertrand  777: 
1.37      bertrand  778:            if (pthread_mutex_unlock(&((*((struct_mutex *)
                    779:                    (*s_objet_argument).objet)).mutex)) != 0)
1.1       bertrand  780:            {
1.37      bertrand  781:                liberation(s_etat_processus, s_objet_argument);
                    782: 
                    783:                if ((*s_etat_processus).profilage == d_vrai)
                    784:                {
                    785:                    profilage(s_etat_processus, NULL);
                    786:                }
                    787: 
                    788:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    789:                return;
1.1       bertrand  790:            }
                    791:        }
                    792: 
                    793:        if ((*s_etat_processus).profilage == d_vrai)
                    794:        {
                    795:            profilage(s_etat_processus, NULL);
                    796:        }
                    797:    }
                    798:    else
                    799:    {
                    800:        liberation(s_etat_processus, s_objet_argument);
                    801: 
                    802:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    803:        return;
                    804:    }
                    805: 
                    806:    liberation(s_etat_processus, s_objet_argument);
                    807: 
                    808:    if ((s_objet_resultat = allocation(s_etat_processus, INT))
                    809:            == NULL)
                    810:    {
                    811:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    812:        return;
                    813:    }
                    814: 
                    815:    (*((integer8 *) (*s_objet_resultat).objet)) = (ios == 0) ? 0 : -1;
                    816: 
                    817:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    818:            s_objet_resultat) == d_erreur)
                    819:    {
                    820:        return;
                    821:    }
                    822: 
                    823:    return;
                    824: }
                    825: 
                    826: 
                    827: /*
                    828: ================================================================================
                    829:   Fonction 'mtxunlock'
                    830: ================================================================================
                    831:   Entrées :
                    832: --------------------------------------------------------------------------------
                    833:   Sorties :
                    834: --------------------------------------------------------------------------------
                    835:   Effets de bord : néant
                    836: ================================================================================
                    837: */
                    838: 
                    839: void
                    840: instruction_mtxunlock(struct_processus *s_etat_processus)
                    841: {
                    842:    struct_liste_chainee        *l_element_courant;
                    843: 
                    844:    struct_objet                *s_objet_argument;
                    845: 
                    846:    (*s_etat_processus).erreur_execution = d_ex;
                    847: 
                    848:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    849:    {
                    850:        printf("\n  MTXUNLOCK ");
                    851: 
                    852:        if ((*s_etat_processus).langue == 'F')
                    853:        {
                    854:            printf("(déverrouille un mutex)\n\n");
                    855:        }
                    856:        else
                    857:        {
                    858:            printf("(unlock mutex)\n\n");
                    859:        }
                    860: 
                    861:        printf("    1: %s\n", d_MTX);
                    862: 
                    863:        return;
                    864:    }
                    865:    else if ((*s_etat_processus).test_instruction == 'Y')
                    866:    {
                    867:        (*s_etat_processus).nombre_arguments = -1;
                    868:        return;
                    869:    }
                    870: 
                    871:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    872:    {
                    873:        if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
                    874:        {
                    875:            return;
                    876:        }
                    877:    }
                    878: 
                    879:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    880:            &s_objet_argument) == d_erreur)
                    881:    {
                    882:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    883:        return;
                    884:    }
                    885: 
                    886:    if ((*s_objet_argument).type == MTX)
                    887:    {
                    888:        l_element_courant = (*s_etat_processus).liste_mutexes;
                    889: 
                    890:        while(l_element_courant != NULL)
                    891:        {
                    892:            if (&((*((struct_mutex *) (*(*l_element_courant).donnee).objet))
                    893:                    .mutex) == &((*((struct_mutex *) (*s_objet_argument).objet))
                    894:                    .mutex))
                    895:            {
                    896:                break;
                    897:            }
                    898: 
                    899:            l_element_courant = (*l_element_courant).suivant;
                    900:        }
                    901: 
                    902:        if (l_element_courant == NULL)
                    903:        {
1.37      bertrand  904:            liberation(s_etat_processus, s_objet_argument);
                    905: 
1.1       bertrand  906:            (*s_etat_processus).erreur_execution = d_ex_mutex;
1.37      bertrand  907:            return;
                    908:        }
1.1       bertrand  909: 
1.37      bertrand  910:        if (pthread_equal(pthread_self(), (*((struct_mutex *)
                    911:                (*s_objet_argument).objet)).tid) == 0)
                    912:        {
1.1       bertrand  913:            liberation(s_etat_processus, s_objet_argument);
1.37      bertrand  914: 
                    915:            (*s_etat_processus).erreur_execution =
                    916:                    d_ex_mutex_acquis_autre_thread;
1.1       bertrand  917:            return;
                    918:        }
                    919: 
                    920:        if (pthread_mutex_trylock(&((*((struct_mutex *)
                    921:                (*s_objet_argument).objet)).mutex)) == EINVAL)
                    922:        {
                    923:            liberation(s_etat_processus, s_objet_argument);
                    924: 
                    925:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    926:            return;
                    927:        }
                    928: 
                    929:        if (pthread_mutex_unlock(&((*((struct_mutex *)
                    930:                (*s_objet_argument).objet)).mutex)) != 0)
                    931:        {
                    932:            liberation(s_etat_processus, s_objet_argument);
                    933: 
                    934:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    935:            return;
                    936:        }
                    937:    }
                    938:    else
                    939:    {
                    940:        liberation(s_etat_processus, s_objet_argument);
                    941: 
                    942:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    943:        return;
                    944:    }
                    945: 
                    946:    liberation(s_etat_processus, s_objet_argument);
                    947: 
                    948:    return;
                    949: }
                    950: 
                    951: 
                    952: /*
                    953: ================================================================================
                    954:   Fonction 'mark'
                    955: ================================================================================
                    956:   Entrées :
                    957: --------------------------------------------------------------------------------
                    958:   Sorties :
                    959: --------------------------------------------------------------------------------
                    960:   Effets de bord : néant
                    961: ================================================================================
                    962: */
                    963: 
                    964: void
                    965: instruction_mark(struct_processus *s_etat_processus)
                    966: {
                    967:    struct_marque               *marque;
                    968: 
                    969:    struct_objet                *s_objet_argument;
                    970:    struct_objet                *s_objet_label;
                    971: 
                    972:    (*s_etat_processus).erreur_execution = d_ex;
                    973: 
                    974:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    975:    {
                    976:        printf("\n  MARK ");
                    977: 
                    978:        if ((*s_etat_processus).langue == 'F')
                    979:        {
                    980:            printf("(ajoute une marque à un graphique)\n\n");
                    981:        }
                    982:        else
                    983:        {
                    984:            printf("(add mark to graph)\n\n");
                    985:        }
                    986: 
                    987:        printf("    2: %s\n", d_CHN);
                    988:        printf("    1: %s\n", d_CPL);
                    989: 
                    990:        return;
                    991:    }
                    992:    else if ((*s_etat_processus).test_instruction == 'Y')
                    993:    {
                    994:        (*s_etat_processus).nombre_arguments = -1;
                    995:        return;
                    996:    }
                    997: 
                    998:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    999:    {
                   1000:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                   1001:        {
                   1002:            return;
                   1003:        }
                   1004:    }
                   1005: 
                   1006:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1007:            &s_objet_argument) == d_erreur)
                   1008:    {
                   1009:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1010:        return;
                   1011:    }
                   1012: 
                   1013:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1014:            &s_objet_label) == d_erreur)
                   1015:    {
                   1016:        liberation(s_etat_processus, s_objet_argument);
                   1017: 
                   1018:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1019:        return;
                   1020:    }
                   1021: 
                   1022:    if (((*s_objet_argument).type == CPL) && ((*s_objet_label).type == CHN))
                   1023:    {
                   1024:        if ((marque = malloc(sizeof(struct_marque))) == NULL)
                   1025:        {
                   1026:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1027:            return;
                   1028:        }
                   1029: 
                   1030:        if (((*marque).label = malloc((strlen((unsigned char *)
                   1031:                (*s_objet_label).objet) + 1) * sizeof(unsigned char))) == NULL)
                   1032:        {
                   1033:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1034:            return;
                   1035:        }
                   1036: 
                   1037:        sprintf((*marque).label, "%s",
                   1038:                (unsigned char *) (*s_objet_label).objet);
                   1039: 
                   1040:        if (((*marque).position = malloc(64 * sizeof(unsigned char))) == NULL)
                   1041:        {
                   1042:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1043:            return;
                   1044:        }
                   1045: 
                   1046:        sprintf((*marque).position, "%f,%f",
                   1047:                (*((complex16 *) (*s_objet_argument).objet)).partie_reelle,
                   1048:                (*((complex16 *) (*s_objet_argument).objet)).partie_imaginaire);
                   1049: 
                   1050:        (*marque).suivant = (*s_etat_processus).s_marques;
                   1051:        (*s_etat_processus).s_marques = marque;
                   1052: 
                   1053:        (*s_etat_processus).mise_a_jour_trace_requise = d_vrai;
                   1054:    }
                   1055:    else
                   1056:    {
                   1057:        liberation(s_etat_processus, s_objet_argument);
                   1058:        liberation(s_etat_processus, s_objet_label);
                   1059: 
                   1060:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1061:        return;
                   1062:    }
                   1063: 
                   1064:    liberation(s_etat_processus, s_objet_argument);
                   1065:    liberation(s_etat_processus, s_objet_label);
                   1066: 
                   1067:    return;
                   1068: }
                   1069: 
                   1070: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>