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