2 ****************************************************************************
3 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
5 * Permission to use, copy, modify, and distribute this software and its *
6 * documentation for any purpose and without fee is hereby granted, *
7 * provided that the above copyright notice appear in all copies and *
8 * that both that copyright notice and this permission notice appear in *
9 * supporting documentation, and that the name of IBM not be used in *
10 * advertising or publicity pertaining to distribution of the software *
11 * without specific, written prior permission. *
13 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
15 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
16 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
17 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
18 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
19 ****************************************************************************
22 /* Elapsed time package */
30 struct clock clock_now
;
32 int clock_haveCurrentTime
;
36 /* Magic tdiff that guarantees a monotonically increasing clock value. */
37 static struct clock tdiff
;
45 tdiff
.sec
= tv
.tv_sec
;
46 tdiff
.usec
= tv
.tv_usec
;
47 clock_now
.sec
= clock_now
.usec
= 0;
48 clock_haveCurrentTime
= 1;
52 /* Refresh value of clock_now. */
54 clock_UpdateTime(void)
62 clock_Sub(&t
, &tdiff
);
64 /* We can't have time running backwards!!! */
65 if (clock_Le(&t
, &clock_now
))
67 /* Calculate new tdiff. */
70 clock_Sub(&t
, &clock_now
);
77 clock_Sub(&t
, &tdiff
);
79 if (t
.usec
>= 1000000)
87 clock_haveCurrentTime
= 1;