File:  [local] / rpl / src / fusible.c
Revision 1.37: download - view: text, annotated - select for diffs - revision graph
Fri Oct 14 09:02:16 2011 UTC (12 years, 6 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_4, HEAD
Suppression d'un #ifdef non fermé.

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

CVSweb interface <joel.bertrand@systella.fr>