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

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

CVSweb interface <joel.bertrand@systella.fr>