]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MINICERN/packlib/kernlib/kerngen/ccgen/timel.c
This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / MINICERN / packlib / kernlib / kerngen / ccgen / timel.c
1 /*
2  * $Id$
3  *
4  * $Log$
5  * Revision 1.2  1997/02/04 17:34:47  mclareni
6  * Merge Winnt and 97a versions
7  *
8  * Revision 1.1.1.1.2.1  1997/01/21 11:29:45  mclareni
9  * All mods for Winnt 96a on winnt branch
10  *
11  * Revision 1.1.1.1  1996/02/15 17:49:27  mclareni
12  * Kernlib
13  *
14  */
15 #include "kerngen/pilot.h"
16 #if defined(CERNLIB_WINNT)
17 #include "wntgs/timel.c"
18 #elif defined(CERNLIB_QMDOS)
19 #include "dosgs/timel.c"
20 #elif defined(CERNLIB_QMIRTD)
21 #include "irtdgs/timel.c"
22 #else
23 /*>    ROUTINE TIMEL
24   CERN PROGLIB# Z007    TIMEST          .VERSION KERNFOR  4.39  940228
25   ORIG. 01/03/85  FCA, mod 03/11/93 GF
26 */
27 #include <sys/types.h>
28 #include <time.h>
29 #include <sys/times.h>
30 #include <sys/param.h>
31 #include <sys/time.h>
32 #include <sys/resource.h>
33
34 #ifndef CLOCKS_PER_SEC
35 #define  CLOCKS_PER_SEC CLK_TCK
36 #endif
37
38
39 #ifndef RLIMIT_CPU
40 #define RLIMIT_CPU 0    /* For HP-UX... */
41 #endif
42 #ifndef RLIM_INFINITY
43 #define RLIM_INFINITY 0x7fffffff    /* For HP-UX... */
44 #endif
45
46 #if defined(CERNLIB_QSYSBSD)||defined(CERNLIB_QMVMI)||defined(CERNLIB_QMVAOS)
47 #define HZ 60.;
48 #endif
49
50 #ifndef HZ
51 #ifdef __GNUC__
52 #define HZ 1
53 #else
54 #define HZ 1./CLOCKS_PER_SEC
55 #endif
56 #endif
57
58 struct tms tps;
59 static float timlim;
60 static time_t timstart, timlast;
61 static int tml_init = 1;
62 float deftim = 999.;
63
64 #if defined(CERNLIB_QX_SC)
65 #define timest timest_
66 #define timex  timex_
67 #define timed  timed_
68 #define timel  timel_
69 #endif
70 #if defined(CERNLIB_QXCAPT)
71 #define timest TIMEST
72 #define timex  TIMEX
73 #define timed  TIMED
74 #define timel  TIMEL
75 #endif
76
77                    /*  local routine called by timst, and time_init */
78 static void time_st(timl)
79 float timl;
80 {
81     times(&tps);
82     timlim = timl;
83     timstart =  tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
84     timlast  = timstart;
85     tml_init = 0;
86     return;
87 }
88                    /*  local routine to start by default  */
89 static void time_init()
90 {
91         struct rlimit rlimit;
92         float  maxtime;
93
94         maxtime=deftim;
95
96         if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
97                 if ( rlimit.rlim_cur != RLIM_INFINITY )
98                    maxtime = (float) rlimit.rlim_cur;
99         }       
100
101         time_st(maxtime);
102         return;
103 }
104
105 void timest(timl)
106 float *timl;
107 {
108  struct rlimit rlimit;
109  float  maxtime;
110
111  if (tml_init != 0) {
112
113 /*  get maximum time allowed by system, and do not allow more */
114     maxtime = *timl;
115     if (getrlimit(RLIMIT_CPU, &rlimit)==0) {
116            maxtime = (float) rlimit.rlim_cur;
117            maxtime = ( maxtime > *timl ) ? *timl : maxtime;
118     }
119     time_st(maxtime);
120  }
121  return;
122 }
123 void timex(tx)
124 /*
125 C
126   CERN PROGLIB# Z007    TIMEX           .VERSION KERNFOR  4.39  940228
127 C
128 */
129 float *tx;
130 {
131    time_t timnow;
132    if (tml_init) {
133        time_init();
134        *tx = 0.;
135    }
136    else {
137        times(&tps);
138        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
139        *tx = (float) (timnow - timstart) / HZ;
140    }
141    return;
142 }
143
144 void timed(td)
145 /*
146 C
147   CERN PROGLIB# Z007    TIMED           .VERSION KERNFOR  4.39  940228
148 C
149 */
150 float *td;
151 {
152    time_t timnow;
153    if (tml_init) {
154        time_init();
155        *td = timlim;
156    }
157    else {
158        times(&tps);
159        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
160        *td = (float) (timnow - timlast) / HZ;
161        timlast = timnow;
162    }
163    return;
164 }
165
166 void timel(tl)
167 /*
168 C
169   CERN PROGLIB# Z007    TIMEL           .VERSION KERNFOR  4.39  940228
170 C
171 */
172 float *tl;
173 {
174    time_t timnow;
175    if (tml_init) {
176        time_init();
177        *tl = timlim;
178    }
179    else {
180        times(&tps);
181        timnow = tps.tms_utime+tps.tms_cutime+tps.tms_stime+tps.tms_cstime;
182        *tl = timlim - (float) (timnow - timstart) / HZ;
183    }
184    return;
185 }
186 #ifdef __GNUC__
187 #undef time_t
188 #endif
189 /*> END <----------------------------------------------------------*/
190 #endif