Annotation of rpl/src/fusible.c, revision 1.83
1.1 bertrand 1: /*
2: ================================================================================
1.82 bertrand 3: RPL/2 (R) version 4.1.36
1.83 ! bertrand 4: Copyright (C) 1989-2025 Dr. BERTRAND Joël
1.1 bertrand 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:
1.12 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 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: struct_processus *s_etat_processus;
47:
1.36 bertrand 48: # ifndef OS2
1.1 bertrand 49: struct rusage s_rusage;
1.36 bertrand 50: # else
51: clock_t horloge;
52: # endif
1.1 bertrand 53:
54: struct timespec temporisation;
55:
1.52 bertrand 56: sigset_t set;
1.48 bertrand 57:
58: sigfillset(&set);
59: pthread_sigmask(SIG_BLOCK, &set, NULL);
60:
1.1 bertrand 61: s_etat_processus = argument;
62:
63: if ((*s_etat_processus).debug == d_vrai)
64: if (((*s_etat_processus).type_debug &
65: d_debug_fusible) != 0)
66: {
67: if ((*s_etat_processus).langue == 'F')
68: {
69: printf("[%d] Lancement du thread fusible du"
70: " processus\n", (int) getpid());
71: }
72: else
73: {
74: printf("[%d] Start fuse process\n", (int) getpid());
75: }
76:
77: fflush(stdout);
78: }
79:
80: s_etat_processus = argument;
81:
82: temporisation.tv_sec = 0;
83: temporisation.tv_nsec = 100000000; // un dixième de seconde
84:
1.34 bertrand 85: // Par défaut, le thread peut être annulé.
86:
87: # ifdef PTHREAD_CANCEL_ENABLE
1.1 bertrand 88: pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
1.34 bertrand 89: # endif
1.1 bertrand 90:
1.36 bertrand 91: # ifndef OS2
92: getrusage(RUSAGE_SELF, &s_rusage);
1.51 bertrand 93: temps_cpu_courant = ((real8) s_rusage.ru_utime.tv_sec) +
1.36 bertrand 94: (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
95: # else
96: horloge = clock();
97: temps_cpu_courant = horloge / CLOCKS_PER_SEC;
98: # endif
1.1 bertrand 99:
100: do
101: {
102: pthread_testcancel();
103: nanosleep(&temporisation, NULL);
1.36 bertrand 104: temps_cpu_precedent = temps_cpu_courant;
1.1 bertrand 105:
1.36 bertrand 106: # ifndef OS2
107: getrusage(RUSAGE_SELF, &s_rusage);
1.51 bertrand 108: temps_cpu_courant = ((real8) s_rusage.ru_utime.tv_sec) +
1.36 bertrand 109: (((real8) s_rusage.ru_utime.tv_usec) / ((real8) 1E6));
110: # else
111: horloge = clock();
112: temps_cpu_courant = horloge / CLOCKS_PER_SEC;
113:
114: if (temps_cpu_courant < temps_cpu_precedent)
115: {
116: // Le compteur a fait un tour...
117: temps_cpu_precedent = temps_cpu_courant;
118: }
119: # endif
1.1 bertrand 120:
121: (*s_etat_processus).temps_maximal_cpu -= temps_cpu_courant -
122: temps_cpu_precedent;
123:
124: if ((*s_etat_processus).temps_maximal_cpu <= 0)
125: {
126: (*s_etat_processus).temps_maximal_cpu = 0;
127:
1.75 bertrand 128: envoi_signal_thread(NULL, (*s_etat_processus)
1.32 bertrand 129: .thread_surveille_par_fusible, rpl_sigstop);
1.1 bertrand 130: break;
131: }
132: } while((*s_etat_processus).var_volatile_requete_arret == 0);
133:
134: if ((*s_etat_processus).debug == d_vrai)
135: if (((*s_etat_processus).type_debug &
136: d_debug_fusible) != 0)
137: {
138: if ((*s_etat_processus).langue == 'F')
139: {
140: printf("[%d] Arrêt du thread fusible du"
141: " processus\n", (int) getpid());
142: }
143: else
144: {
145: printf("[%d] Stop fuse process\n", (int) getpid());
146: }
147:
148: fflush(stdout);
149: }
150:
151: pthread_exit(NULL);
152: }
153:
154: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>