File:  [local] / rpl / src / fusible.c
Revision 1.25: download - view: text, annotated - select for diffs - revision graph
Tue Jun 21 15:26:29 2011 UTC (12 years, 10 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Correction d'une réinitialisation sauvage de la pile des variables par niveau
dans la copie de la structure de description du processus. Cela corrige
la fonction SPAWN qui échouait sur un segmentation fault car la pile des
variables par niveau était vide alors même que l'arbre des variables contenait
bien les variables. Passage à la prerelease 2.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.0.prerelease.2
    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: #   ifndef OS2
   44: 
   45:     real8                   temps_cpu_precedent;
   46:     real8                   temps_cpu_courant;
   47: 
   48:     sigset_t                masque;
   49: 
   50:     struct_processus        *s_etat_processus;
   51: 
   52:     struct rusage           s_rusage;
   53: 
   54:     struct timespec         temporisation;
   55: 
   56:     s_etat_processus = argument;
   57: 
   58:     sigemptyset(&masque);
   59:     sigaddset(&masque, SIGINJECT);
   60:     sigaddset(&masque, SIGFSTOP);
   61:     sigaddset(&masque, SIGFABORT);
   62:     sigaddset(&masque, SIGURG);
   63:     sigaddset(&masque, SIGALRM);
   64:     sigaddset(&masque, SIGCONT);
   65:     sigaddset(&masque, SIGINT);
   66:     pthread_sigmask(SIG_BLOCK, &masque, NULL);
   67: 
   68:     if ((*s_etat_processus).debug == d_vrai)
   69:         if (((*s_etat_processus).type_debug &
   70:                 d_debug_fusible) != 0)
   71:     {
   72:         if ((*s_etat_processus).langue == 'F')
   73:         {
   74:             printf("[%d] Lancement du thread fusible du"
   75:                     " processus\n", (int) getpid());
   76:         }
   77:         else
   78:         {
   79:             printf("[%d] Start fuse process\n", (int) getpid());
   80:         }
   81: 
   82:         fflush(stdout);
   83:     }
   84: 
   85:     s_etat_processus = argument;
   86: 
   87:     temporisation.tv_sec = 0;
   88:     temporisation.tv_nsec = 100000000; // un dixième de seconde
   89: 
   90:     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
   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:         getrusage(RUSAGE_SELF, &s_rusage);
  101: 
  102:         temps_cpu_precedent = temps_cpu_courant;
  103:         temps_cpu_courant = s_rusage.ru_utime.tv_sec +
  104:                 (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
  105: 
  106:         (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant -
  107:                 temps_cpu_precedent;
  108: 
  109:         if ((*s_etat_processus).temps_maximal_cpu <= 0)
  110:         {
  111:             (*s_etat_processus).temps_maximal_cpu = 0;
  112: 
  113:             pthread_kill((*s_etat_processus).thread_surveille_par_fusible,
  114:                     SIGFSTOP);
  115:             break;
  116:         }
  117:     } while((*s_etat_processus).var_volatile_requete_arret == 0);
  118: 
  119:     if ((*s_etat_processus).debug == d_vrai)
  120:         if (((*s_etat_processus).type_debug &
  121:                 d_debug_fusible) != 0)
  122:     {
  123:         if ((*s_etat_processus).langue == 'F')
  124:         {
  125:             printf("[%d] Arrêt du thread fusible du"
  126:                     " processus\n", (int) getpid());
  127:         }
  128:         else
  129:         {
  130:             printf("[%d] Stop fuse process\n", (int) getpid());
  131:         }
  132: 
  133:         fflush(stdout);
  134:     }
  135: 
  136: #   else
  137: 
  138:     struct_processus        *s_etat_processus;
  139: 
  140:     s_etat_processus = argument;
  141: 
  142:     if ((*s_etat_processus).langue == 'F')
  143:     {
  144:         printf("+++Attention : Support indisponible sous OS/2\n");
  145:     }
  146:     else
  147:     {
  148:         printf("+++Warning : Function unavailable\n");
  149:     }
  150: #   endif
  151: 
  152:     pthread_exit(NULL);
  153: }
  154: 
  155: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>