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

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

CVSweb interface <joel.bertrand@systella.fr>