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

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

CVSweb interface <joel.bertrand@systella.fr>