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

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

CVSweb interface <joel.bertrand@systella.fr>