/* ================================================================================ RPL/2 (R) version 4.1.32 Copyright (C) 1989-2020 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl-conv.h" /* ================================================================================ Fonction fusible. Elle déclanche un signal d'arrêt (SIGFSTOP) lorsque le timeout est dépassé. ================================================================================ Entrées : pointeur sur une structure -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ void * fusible(void *argument) { real8 temps_cpu_precedent; real8 temps_cpu_courant; struct_processus *s_etat_processus; # ifndef OS2 struct rusage s_rusage; # else clock_t horloge; # endif struct timespec temporisation; sigset_t set; sigfillset(&set); pthread_sigmask(SIG_BLOCK, &set, NULL); s_etat_processus = argument; if ((*s_etat_processus).debug == d_vrai) if (((*s_etat_processus).type_debug & d_debug_fusible) != 0) { if ((*s_etat_processus).langue == 'F') { printf("[%d] Lancement du thread fusible du" " processus\n", (int) getpid()); } else { printf("[%d] Start fuse process\n", (int) getpid()); } fflush(stdout); } s_etat_processus = argument; temporisation.tv_sec = 0; temporisation.tv_nsec = 100000000; // un dixième de seconde // Par défaut, le thread peut être annulé. # ifdef PTHREAD_CANCEL_ENABLE pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); # endif # ifndef OS2 getrusage(RUSAGE_SELF, &s_rusage); temps_cpu_courant = ((real8) s_rusage.ru_utime.tv_sec) + (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6)); # else horloge = clock(); temps_cpu_courant = horloge / CLOCKS_PER_SEC; # endif do { pthread_testcancel(); nanosleep(&temporisation, NULL); temps_cpu_precedent = temps_cpu_courant; # ifndef OS2 getrusage(RUSAGE_SELF, &s_rusage); temps_cpu_courant = ((real8) s_rusage.ru_utime.tv_sec) + (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6)); # else horloge = clock(); temps_cpu_courant = horloge / CLOCKS_PER_SEC; if (temps_cpu_courant < temps_cpu_precedent) { // Le compteur a fait un tour... temps_cpu_precedent = temps_cpu_courant; } # endif (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant - temps_cpu_precedent; if ((*s_etat_processus).temps_maximal_cpu <= 0) { (*s_etat_processus).temps_maximal_cpu = 0; envoi_signal_thread(NULL, (*s_etat_processus) .thread_surveille_par_fusible, rpl_sigstop); break; } } while((*s_etat_processus).var_volatile_requete_arret == 0); if ((*s_etat_processus).debug == d_vrai) if (((*s_etat_processus).type_debug & d_debug_fusible) != 0) { if ((*s_etat_processus).langue == 'F') { printf("[%d] Arrêt du thread fusible du" " processus\n", (int) getpid()); } else { printf("[%d] Stop fuse process\n", (int) getpid()); } fflush(stdout); } pthread_exit(NULL); } // vim: ts=4