mask-loopback-address-allow-loopback-interfaces-to-be-advertised-20041110
[openafs.git] / src / rx / rx_clock_nt.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* Elapsed time package */
11 /* See rx_clock.h for calling conventions */
12
13 #include <afsconfig.h>
14 #include <afs/param.h>
15
16 RCSID
17     ("$Header$");
18
19 #ifdef AFS_NT40_ENV
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include "rx_clock.h"
25
26 void clock_UpdateTime(void);    /* forward reference */
27
28 struct clock clock_now;         /* The last elapsed time ready by clock_GetTimer */
29
30 /* This is set to 1 whenever the time is read, and reset to 0 whenever
31  * clock_NewTime is called.  This is to allow the caller to control the
32  * frequency with which the actual time is re-evaluated.
33  */
34 int clock_haveCurrentTime;
35
36 int clock_nUpdates;             /* The actual number of clock updates */
37 static int clockInitialized = 0;
38
39 /* Timing tests show that we can compute times at about 4uS per call. */
40 LARGE_INTEGER rxi_clock0;
41 LARGE_INTEGER rxi_clockFreq;
42
43 #undef clock_UpdateTime
44 void clock_UpdateTime(void);
45
46 void
47 clock_Init(void)
48 {
49     if (!QueryPerformanceFrequency(&rxi_clockFreq)) {
50         printf("No High Performance clock, exiting.\n");
51         exit(1);
52     }
53
54     clockInitialized = 1;
55     (void)QueryPerformanceCounter(&rxi_clock0);
56
57     clock_UpdateTime();
58 }
59
60 #ifndef KERNEL
61 /* Make clock uninitialized. */
62 int
63 clock_UnInit(void)
64 {
65     clockInitialized = 0;
66     return 0;
67 }
68 #endif
69
70 void
71 clock_UpdateTime(void)
72 {
73     LARGE_INTEGER now, delta;
74     double seconds;
75
76     (void)QueryPerformanceCounter(&now);
77
78     delta.QuadPart = now.QuadPart - rxi_clock0.QuadPart;
79
80     seconds = (double)delta.QuadPart / (double)rxi_clockFreq.QuadPart;
81
82     clock_now.sec = (int)seconds;
83     clock_now.usec = (int)((seconds - (double)clock_now.sec)
84                            * (double)1000000);
85     clock_haveCurrentTime = 1;
86     clock_nUpdates++;
87
88 }
89 #endif /* AFS_NT40_ENV */