/* ================================================================================ RPL/2 (R) version 4.1.0 Copyright (C) 1989-2011 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) { # ifndef OS2 real8 temps_cpu_precedent; real8 temps_cpu_courant; sigset_t masque; struct_processus *s_etat_processus; struct rusage s_rusage; struct timespec temporisation; s_etat_processus = argument; sigemptyset(&masque); sigaddset(&masque, SIGINJECT); sigaddset(&masque, SIGFSTOP); sigaddset(&masque, SIGFABORT); sigaddset(&masque, SIGURG); sigaddset(&masque, SIGALRM); sigaddset(&masque, SIGCONT); sigaddset(&masque, SIGINT); pthread_sigmask(SIG_BLOCK, &masque, NULL); 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 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); getrusage(RUSAGE_SELF, &s_rusage); temps_cpu_courant = s_rusage.ru_utime.tv_sec + (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6)); do { pthread_testcancel(); nanosleep(&temporisation, NULL); getrusage(RUSAGE_SELF, &s_rusage); temps_cpu_precedent = temps_cpu_courant; temps_cpu_courant = s_rusage.ru_utime.tv_sec + (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6)); (*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; pthread_kill((*s_etat_processus).thread_surveille_par_fusible, SIGFSTOP); 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); } # else struct_processus *s_etat_processus; s_etat_processus = argument; if ((*s_etat_processus).langue == 'F') { printf("+++Attention : Support indisponible sous OS/2\n"); } else { printf("+++Warning : Function unavailable\n"); } # endif pthread_exit(NULL); } // vim: ts=4