File:  [local] / rpl / src / fusible.c
Revision 1.13: download - view: text, annotated - select for diffs - revision graph
Fri Aug 6 15:32:58 2010 UTC (13 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Cohérence

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.18
    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 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:     sigset_t                masque;
   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:     sigemptyset(&masque);
   57:     sigaddset(&masque, SIGINJECT);
   58:     sigaddset(&masque, SIGFSTOP);
   59:     sigaddset(&masque, SIGFABORT);
   60:     sigaddset(&masque, SIGURG);
   61:     sigaddset(&masque, SIGALRM);
   62:     sigaddset(&masque, SIGCONT);
   63:     sigaddset(&masque, SIGINT);
   64:     pthread_sigmask(SIG_BLOCK, &masque, NULL);
   65: 
   66:     if ((*s_etat_processus).debug == d_vrai)
   67:         if (((*s_etat_processus).type_debug &
   68:                 d_debug_fusible) != 0)
   69:     {
   70:         if ((*s_etat_processus).langue == 'F')
   71:         {
   72:             printf("[%d] Lancement du thread fusible du"
   73:                     " processus\n", (int) getpid());
   74:         }
   75:         else
   76:         {
   77:             printf("[%d] Start fuse process\n", (int) getpid());
   78:         }
   79: 
   80:         fflush(stdout);
   81:     }
   82: 
   83:     s_etat_processus = argument;
   84: 
   85:     temporisation.tv_sec = 0;
   86:     temporisation.tv_nsec = 100000000; // un dixième de seconde
   87: 
   88: #   ifndef OS2
   89:     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
   90: #   endif
   91: 
   92:     getrusage(RUSAGE_SELF, &s_rusage);
   93:     temps_cpu_courant = s_rusage.ru_utime.tv_sec +
   94:             (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
   95: 
   96:     do
   97:     {
   98:         pthread_testcancel();
   99:         nanosleep(&temporisation, NULL);
  100: 
  101:         getrusage(RUSAGE_SELF, &s_rusage);
  102: 
  103:         temps_cpu_precedent = temps_cpu_courant;
  104:         temps_cpu_courant = s_rusage.ru_utime.tv_sec +
  105:                 (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
  106: 
  107:         (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant -
  108:                 temps_cpu_precedent;
  109: 
  110:         if ((*s_etat_processus).temps_maximal_cpu <= 0)
  111:         {
  112:             (*s_etat_processus).temps_maximal_cpu = 0;
  113: 
  114:             pthread_kill((*s_etat_processus).thread_surveille_par_fusible,
  115:                     SIGFSTOP);
  116:             break;
  117:         }
  118:     } while((*s_etat_processus).var_volatile_requete_arret == 0);
  119: 
  120:     if ((*s_etat_processus).debug == d_vrai)
  121:         if (((*s_etat_processus).type_debug &
  122:                 d_debug_fusible) != 0)
  123:     {
  124:         if ((*s_etat_processus).langue == 'F')
  125:         {
  126:             printf("[%d] Arrêt du thread fusible du"
  127:                     " processus\n", (int) getpid());
  128:         }
  129:         else
  130:         {
  131:             printf("[%d] Stop fuse process\n", (int) getpid());
  132:         }
  133: 
  134:         fflush(stdout);
  135:     }
  136: 
  137:     pthread_exit(NULL);
  138: }
  139: 
  140: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>