Fix so that UKERNEL can keep using system xdr
[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
17 #ifdef AFS_NT40_ENV
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <windef.h>
21 #include <winbase.h>
22 #include "rx_clock.h"
23
24 struct clock clock_now;         /* The last elapsed time ready by clock_GetTimer */
25
26 /* This is set to 1 whenever the time is read, and reset to 0 whenever
27  * clock_NewTime is called.  This is to allow the caller to control the
28  * frequency with which the actual time is re-evaluated.
29  */
30 #undef clock_haveCurrentTime
31 int clock_haveCurrentTime = 0;
32
33 int clock_nUpdates;             /* The actual number of clock updates */
34 static int clockInitialized = 0;
35
36 /* Timing tests show that we can compute times at about 4uS per call. */
37 LARGE_INTEGER rxi_clock0;
38 LARGE_INTEGER rxi_clockFreq;
39
40 #undef clock_UpdateTime
41 void clock_UpdateTime(void);
42
43 #undef clock_Init
44 void
45 clock_Init(void)
46 {
47     if (!QueryPerformanceFrequency(&rxi_clockFreq)) {
48         OutputDebugString("No High Performance clock, exiting.\n");
49         exit(1);
50     }
51     clockInitialized = 1;
52     
53     clock_UpdateTime();
54 }
55
56 #ifndef KERNEL
57 /* Make clock uninitialized. */
58 int
59 clock_UnInit(void)
60 {
61     clockInitialized = 0;
62     return 0;
63 }
64 #endif
65
66 void
67 clock_UpdateTime(void)
68 {
69     LARGE_INTEGER now, delta;
70     double seconds;
71
72     (void)QueryPerformanceCounter(&now);
73
74     delta.QuadPart = now.QuadPart - rxi_clock0.QuadPart;
75
76     seconds = (double)delta.QuadPart / (double)rxi_clockFreq.QuadPart;
77
78     clock_now.sec = (int)seconds;
79     clock_now.usec = (int)((seconds - (double)clock_now.sec)
80                            * (double)1000000);
81     clock_haveCurrentTime = 1;
82     clock_nUpdates++;
83
84 }
85 #endif /* AFS_NT40_ENV */