*** empty log message ***
[arla.git] / rx / rx_clock.c
blob073abfbb5041e5992c587ce8557bec27675f7d29
1 /*
2 ****************************************************************************
3 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
4 * *
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. *
12 * *
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 */
24 #include "rx_locl.h"
26 RCSID("$Id$");
28 #ifndef KERNEL
30 struct clock clock_now;
32 int clock_haveCurrentTime;
34 int clock_nUpdates;
36 /* Magic tdiff that guarantees a monotonically increasing clock value. */
37 static struct clock tdiff;
39 void
40 clock_Init(void)
42 struct timeval tv;
44 gettimeofday(&tv, 0);
45 tdiff.sec = tv.tv_sec;
46 tdiff.usec = tv.tv_usec;
47 clock_now.sec = clock_now.usec = 0;
48 clock_haveCurrentTime = 1;
49 clock_nUpdates = 0;
52 /* Refresh value of clock_now. */
53 void
54 clock_UpdateTime(void)
56 struct timeval tv;
57 struct clock t;
59 gettimeofday(&tv, 0);
60 t.sec = tv.tv_sec;
61 t.usec = tv.tv_usec;
62 clock_Sub(&t, &tdiff);
64 /* We can't have time running backwards!!! */
65 if (clock_Le(&t, &clock_now))
67 /* Calculate new tdiff. */
68 t.sec = tv.tv_sec;
69 t.usec = tv.tv_usec;
70 clock_Sub(&t, &clock_now);
71 tdiff.sec = t.sec;
72 tdiff.usec = t.usec;
74 /* Fake new time. */
75 t.sec = tv.tv_sec;
76 t.usec = tv.tv_usec;
77 clock_Sub(&t, &tdiff);
78 t.usec++;
79 if (t.usec >= 1000000)
81 t.sec += 1;
82 t.usec = 0;
86 clock_now = t;
87 clock_haveCurrentTime = 1;
88 clock_nUpdates++;
91 void
92 clock_ReInit(void)
96 #endif /* KERNEL */