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

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

CVSweb interface <joel.bertrand@systella.fr>