1 /**************************************************************************
3 * Copyright 2008-2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * OS independent time-manipulation functions.
32 * @author Jose Fonseca <jfonseca@vmware.com>
36 #include "pipe/p_config.h"
38 #if defined(PIPE_OS_UNIX) || defined(PIPE_OS_AROS)
39 # include <sys/time.h> /* timeval */
40 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
43 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
45 extern VOID
KeQuerySystemTime(PLARGE_INTEGER
);
46 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
49 # error Unsupported OS
58 #if defined(PIPE_OS_UNIX) || defined(PIPE_OS_AROS)
61 gettimeofday(&tv
, NULL
);
62 return tv
.tv_usec
+ tv
.tv_sec
*1000000LL;
64 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
66 static LONGLONG frequency
;
69 EngQueryPerformanceFrequency(&frequency
);
70 EngQueryPerformanceCounter(&counter
);
71 return counter
*INT64_C(1000000)/frequency
;
73 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
75 static LARGE_INTEGER frequency
;
76 LARGE_INTEGER counter
;
77 if(!frequency
.QuadPart
)
78 QueryPerformanceFrequency(&frequency
);
79 QueryPerformanceCounter(&counter
);
80 return counter
.QuadPart
*INT64_C(1000000)/frequency
.QuadPart
;
82 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
84 /* Updated every 10 miliseconds, measured in units of 100 nanoseconds.
85 * http://msdn.microsoft.com/en-us/library/ms801642.aspx */
86 LARGE_INTEGER counter
;
87 KeQuerySystemTime(&counter
);
88 return counter
.QuadPart
/10;
94 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
97 os_time_sleep(int64_t usecs
)
99 static LONGLONG frequency
;
100 LONGLONG start
, curr
, end
;
102 EngQueryPerformanceCounter(&start
);
105 EngQueryPerformanceFrequency(&frequency
);
107 end
= start
+ (usecs
* frequency
+ 999999LL)/1000000LL;
110 EngQueryPerformanceCounter(&curr
);
111 } while(start
<= curr
&& curr
< end
||
112 end
< start
&& (curr
< end
|| start
<= curr
));
115 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
118 os_time_sleep(int64_t usecs
)
120 Sleep((usecs
+ 999) / 1000);