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