Rev 4921 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4921 | Rev 6099 | ||
---|---|---|---|
1 | /* NetWare can not use this implementation of clock, since it does not |
1 | /* NetWare can not use this implementation of clock, since it does not |
2 | have times or any similar function. It provides its own version of |
2 | have times or any similar function. It provides its own version of |
3 | clock in clib.nlm. If we can not use clib.nlm, then we must write |
3 | clock in clib.nlm. If we can not use clib.nlm, then we must write |
4 | clock in sys/netware. */ |
4 | clock in sys/netware. */ |
5 | 5 | ||
6 | #ifdef CLOCK_PROVIDED |
6 | #ifdef CLOCK_PROVIDED |
7 | 7 | ||
8 | int _dummy_clock = 1; |
8 | int _dummy_clock = 1; |
9 | 9 | ||
10 | #else |
10 | #else |
11 | 11 | ||
12 | /* |
12 | /* |
13 | * clock.c |
13 | * clock.c |
14 | * Original Author: G. Haley |
14 | * Original Author: G. Haley |
15 | * |
15 | * |
16 | * Determines the processor time used by the program since invocation. The time |
16 | * Determines the processor time used by the program since invocation. The time |
17 | * in seconds is the value returned divided by the value of the macro CLK_TCK. |
17 | * in seconds is the value returned divided by the value of the macro CLK_TCK. |
18 | * If the processor time used is not available, (clock_t) -1 is returned. |
18 | * If the processor time used is not available, (clock_t) -1 is returned. |
19 | */ |
19 | */ |
20 | 20 | ||
21 | /* |
21 | /* |
22 | FUNCTION |
22 | FUNCTION |
23 | < |
23 | < |
24 | 24 | ||
25 | INDEX |
25 | INDEX |
26 | clock |
26 | clock |
27 | 27 | ||
28 | ANSI_SYNOPSIS |
28 | ANSI_SYNOPSIS |
29 | #include |
29 | #include |
30 | clock_t clock(void); |
30 | clock_t clock(void); |
31 | 31 | ||
32 | TRAD_SYNOPSIS |
32 | TRAD_SYNOPSIS |
33 | #include |
33 | #include |
34 | clock_t clock(); |
34 | clock_t clock(); |
35 | 35 | ||
36 | DESCRIPTION |
36 | DESCRIPTION |
37 | Calculates the best available approximation of the cumulative amount |
37 | Calculates the best available approximation of the cumulative amount |
38 | of time used by your program since it started. To convert the result |
38 | of time used by your program since it started. To convert the result |
39 | into seconds, divide by the macro < |
39 | into seconds, divide by the macro < |
40 | 40 | ||
41 | RETURNS |
41 | RETURNS |
42 | The amount of processor time used so far by your program, in units |
42 | The amount of processor time used so far by your program, in units |
43 | defined by the machine-dependent macro < |
43 | defined by the machine-dependent macro < |
44 | measurement is available, the result is (clock_t)<<-1>>. |
44 | measurement is available, the result is (clock_t)<<-1>>. |
45 | 45 | ||
46 | PORTABILITY |
46 | PORTABILITY |
47 | ANSI C requires < |
47 | ANSI C requires < |
48 | 48 | ||
49 | Supporting OS subroutine required: < |
49 | Supporting OS subroutine required: < |
50 | */ |
50 | */ |
51 | 51 | ||
52 | #include |
52 | #include |
53 | #include |
53 | #include |
54 | #include |
54 | #include |
55 | 55 | ||
56 | clock_t |
56 | clock_t |
57 | clock () |
57 | clock () |
58 | { |
58 | { |
59 | struct tms tim_s; |
59 | struct tms tim_s; |
60 | clock_t res; |
60 | clock_t res; |
61 | 61 | ||
62 | if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1) |
62 | if ((res = (clock_t) _times_r (_REENT, &tim_s)) != (clock_t) -1) |
63 | res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + |
63 | res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + |
64 | tim_s.tms_cutime + tim_s.tms_cstime); |
64 | tim_s.tms_cutime + tim_s.tms_cstime); |
65 | 65 | ||
66 | return res; |
66 | return res; |
67 | } |
67 | } |
68 | 68 | ||
69 | #endif /* CLOCK_PROVIDED */ |
69 | #endif /* CLOCK_PROVIDED */ |