Annotation of rpl/src/fusible.c, revision 1.36

1.1       bertrand    1: /*
                      2: ================================================================================
1.33      bertrand    3:   RPL/2 (R) version 4.1.4
1.19      bertrand    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.12      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction fusible.
                     29:   Elle déclanche un signal d'arrêt (SIGFSTOP) lorsque le timeout est
                     30:   dépassé.
                     31: ================================================================================
                     32:   Entrées : pointeur sur une structure
                     33: --------------------------------------------------------------------------------
                     34:   Sorties :
                     35: --------------------------------------------------------------------------------
                     36:   Effets de bord : néant
                     37: ================================================================================
                     38: */
                     39: 
                     40: void *
                     41: fusible(void *argument)
                     42: {
1.14      bertrand   43: #  ifndef OS2
                     44: 
1.1       bertrand   45:    real8                   temps_cpu_precedent;
                     46:    real8                   temps_cpu_courant;
                     47: 
                     48:    struct_processus        *s_etat_processus;
                     49: 
1.36    ! bertrand   50: #  ifndef OS2
1.1       bertrand   51:    struct rusage           s_rusage;
1.36    ! bertrand   52: #  else
        !            53:    clock_t                 horloge;
        !            54: #  endif
1.1       bertrand   55: 
                     56:    struct timespec         temporisation;
                     57: 
                     58:    s_etat_processus = argument;
                     59: 
                     60:    if ((*s_etat_processus).debug == d_vrai)
                     61:        if (((*s_etat_processus).type_debug &
                     62:                d_debug_fusible) != 0)
                     63:    {
                     64:        if ((*s_etat_processus).langue == 'F')
                     65:        {
                     66:            printf("[%d] Lancement du thread fusible du"
                     67:                    " processus\n", (int) getpid());
                     68:        }
                     69:        else
                     70:        {
                     71:            printf("[%d] Start fuse process\n", (int) getpid());
                     72:        }
                     73: 
                     74:        fflush(stdout);
                     75:    }
                     76: 
                     77:    s_etat_processus = argument;
                     78: 
                     79:    temporisation.tv_sec = 0;
                     80:    temporisation.tv_nsec = 100000000; // un dixième de seconde
                     81: 
1.34      bertrand   82:    // Par défaut, le thread peut être annulé.
                     83: 
                     84: #  ifdef PTHREAD_CANCEL_ENABLE
1.1       bertrand   85:    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
1.34      bertrand   86: #  endif
1.1       bertrand   87: 
1.36    ! bertrand   88: #  ifndef OS2
        !            89:        getrusage(RUSAGE_SELF, &s_rusage);
        !            90:        temps_cpu_courant = s_rusage.ru_utime.tv_sec +
        !            91:                (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
        !            92: #  else
        !            93:        horloge = clock();
        !            94:        temps_cpu_courant = horloge / CLOCKS_PER_SEC;
        !            95: #  endif
1.1       bertrand   96: 
                     97:    do
                     98:    {
                     99:        pthread_testcancel();
                    100:        nanosleep(&temporisation, NULL);
1.36    ! bertrand  101:        temps_cpu_precedent = temps_cpu_courant;
1.1       bertrand  102: 
1.36    ! bertrand  103: #      ifndef OS2
        !           104:            getrusage(RUSAGE_SELF, &s_rusage);
        !           105:            temps_cpu_courant = s_rusage.ru_utime.tv_sec +
        !           106:                    (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
        !           107: #      else
        !           108:            horloge = clock();
        !           109:            temps_cpu_courant = horloge / CLOCKS_PER_SEC;
        !           110: 
        !           111:            if (temps_cpu_courant < temps_cpu_precedent)
        !           112:            {
        !           113:                // Le compteur a fait un tour...
        !           114:                temps_cpu_precedent = temps_cpu_courant;
        !           115:            }
        !           116: #      endif
1.1       bertrand  117: 
                    118:        (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant -
                    119:                temps_cpu_precedent;
                    120: 
                    121:        if ((*s_etat_processus).temps_maximal_cpu <= 0)
                    122:        {
                    123:            (*s_etat_processus).temps_maximal_cpu = 0;
                    124: 
1.32      bertrand  125:            envoi_signal_thread((*s_etat_processus)
                    126:                    .thread_surveille_par_fusible, rpl_sigstop);
1.1       bertrand  127:            break;
                    128:        }
                    129:    } while((*s_etat_processus).var_volatile_requete_arret == 0);
                    130: 
                    131:    if ((*s_etat_processus).debug == d_vrai)
                    132:        if (((*s_etat_processus).type_debug &
                    133:                d_debug_fusible) != 0)
                    134:    {
                    135:        if ((*s_etat_processus).langue == 'F')
                    136:        {
                    137:            printf("[%d] Arrêt du thread fusible du"
                    138:                    " processus\n", (int) getpid());
                    139:        }
                    140:        else
                    141:        {
                    142:            printf("[%d] Stop fuse process\n", (int) getpid());
                    143:        }
                    144: 
                    145:        fflush(stdout);
                    146:    }
                    147: 
                    148:    pthread_exit(NULL);
                    149: }
                    150: 
                    151: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>