--- rpl/src/fusible.c 2011/09/14 14:34:28 1.32 +++ rpl/src/fusible.c 2015/01/05 13:12:31 1.60 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.3 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.19 + Copyright (C) 1989-2015 Dr. BERTRAND Joël This file is part of RPL/2. @@ -40,17 +40,24 @@ void * fusible(void *argument) { -# ifndef OS2 - 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) @@ -75,21 +82,41 @@ fusible(void *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 - getrusage(RUSAGE_SELF, &s_rusage); - temps_cpu_courant = s_rusage.ru_utime.tv_sec + - (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6)); +# 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); - 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)); + +# 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; @@ -121,22 +148,6 @@ fusible(void *argument) 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); }