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

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: 
                     50:    struct rusage           s_rusage;
                     51: 
                     52:    struct timespec         temporisation;
                     53: 
                     54:    s_etat_processus = argument;
                     55: 
                     56:    if ((*s_etat_processus).debug == d_vrai)
                     57:        if (((*s_etat_processus).type_debug &
                     58:                d_debug_fusible) != 0)
                     59:    {
                     60:        if ((*s_etat_processus).langue == 'F')
                     61:        {
                     62:            printf("[%d] Lancement du thread fusible du"
                     63:                    " processus\n", (int) getpid());
                     64:        }
                     65:        else
                     66:        {
                     67:            printf("[%d] Start fuse process\n", (int) getpid());
                     68:        }
                     69: 
                     70:        fflush(stdout);
                     71:    }
                     72: 
                     73:    s_etat_processus = argument;
                     74: 
                     75:    temporisation.tv_sec = 0;
                     76:    temporisation.tv_nsec = 100000000; // un dixième de seconde
                     77: 
1.34    ! bertrand   78:    // Par défaut, le thread peut être annulé.
        !            79: 
        !            80: #  ifdef PTHREAD_CANCEL_ENABLE
1.1       bertrand   81:    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
1.34    ! bertrand   82: #  endif
1.1       bertrand   83: 
                     84:    getrusage(RUSAGE_SELF, &s_rusage);
                     85:    temps_cpu_courant = s_rusage.ru_utime.tv_sec +
                     86:            (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
                     87: 
                     88:    do
                     89:    {
                     90:        pthread_testcancel();
                     91:        nanosleep(&temporisation, NULL);
                     92:        getrusage(RUSAGE_SELF, &s_rusage);
                     93: 
                     94:        temps_cpu_precedent = temps_cpu_courant;
                     95:        temps_cpu_courant = s_rusage.ru_utime.tv_sec +
                     96:                (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
                     97: 
                     98:        (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant -
                     99:                temps_cpu_precedent;
                    100: 
                    101:        if ((*s_etat_processus).temps_maximal_cpu <= 0)
                    102:        {
                    103:            (*s_etat_processus).temps_maximal_cpu = 0;
                    104: 
1.32      bertrand  105:            envoi_signal_thread((*s_etat_processus)
                    106:                    .thread_surveille_par_fusible, rpl_sigstop);
1.1       bertrand  107:            break;
                    108:        }
                    109:    } while((*s_etat_processus).var_volatile_requete_arret == 0);
                    110: 
                    111:    if ((*s_etat_processus).debug == d_vrai)
                    112:        if (((*s_etat_processus).type_debug &
                    113:                d_debug_fusible) != 0)
                    114:    {
                    115:        if ((*s_etat_processus).langue == 'F')
                    116:        {
                    117:            printf("[%d] Arrêt du thread fusible du"
                    118:                    " processus\n", (int) getpid());
                    119:        }
                    120:        else
                    121:        {
                    122:            printf("[%d] Stop fuse process\n", (int) getpid());
                    123:        }
                    124: 
                    125:        fflush(stdout);
                    126:    }
                    127: 
1.14      bertrand  128: #  else
1.15      bertrand  129: 
                    130:    struct_processus        *s_etat_processus;
                    131: 
                    132:    s_etat_processus = argument;
                    133: 
                    134:    if ((*s_etat_processus).langue == 'F')
                    135:    {
                    136:        printf("+++Attention : Support indisponible sous OS/2\n");
                    137:    }
                    138:    else
                    139:    {
1.16      bertrand  140:        printf("+++Warning : Function unavailable\n");
1.15      bertrand  141:    }
1.14      bertrand  142: #  endif
                    143: 
1.1       bertrand  144:    pthread_exit(NULL);
                    145: }
                    146: 
                    147: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>