From 7584fa98d40958abe6d657e9c5707e962aaf794c Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 14 Jun 2013 15:41:17 +0000 Subject: [PATCH] * autoload.cc (GetSystemTimePreciseAsFileTime): Define. * times.cc (GetSystemTimePreciseAsFileTime): Temporarily declare here to workaround missing definition in 32 bit w32api headers. (get_system_time): New always inline function to call either GetSystemTimePreciseAsFileTime or GetSystemTimeAsFileTime on a per OS basis. Call throughout instead of GetSystemTimeAsFileTime. * wincap.h (wincaps::has_precise_system_time): New element. * wincap.cc: Implement above element throughout. --- winsup/cygwin/ChangeLog | 13 ++++++++++++- winsup/cygwin/autoload.cc | 1 + winsup/cygwin/times.cc | 18 ++++++++++++++---- winsup/cygwin/wincap.cc | 5 +++++ winsup/cygwin/wincap.h | 2 ++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 842c6a228..386d54c42 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,4 +1,15 @@ -2013-06-13 Corinna Vinschen +2013-06-14 Corinna Vinschen + + * autoload.cc (GetSystemTimePreciseAsFileTime): Define. + * times.cc (GetSystemTimePreciseAsFileTime): Temporarily declare here + to workaround missing definition in 32 bit w32api headers. + (get_system_time): New always inline function to call either + GetSystemTimePreciseAsFileTime or GetSystemTimeAsFileTime on a per OS + basis. Call throughout instead of GetSystemTimeAsFileTime. + * wincap.h (wincaps::has_precise_system_time): New element. + * wincap.cc: Implement above element throughout. + +2013-06-14 Corinna Vinschen Streamline time/times functionality. Remove last remains of former Windows 9x compatibility. diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 75771a2b6..ed8080258 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -577,6 +577,7 @@ LoadDLLfunc (GetUdpTable, 12, iphlpapi) LoadDLLfuncEx (CancelSynchronousIo, 4, kernel32, 1) LoadDLLfunc (CreateSymbolicLinkW, 12, kernel32) LoadDLLfuncEx (GetNamedPipeClientProcessId, 8, kernel32, 1) +LoadDLLfunc (GetSystemTimePreciseAsFileTime, 4, kernel32) LoadDLLfunc (LocaleNameToLCID, 8, kernel32) LoadDLLfunc (WNetCloseEnum, 4, mpr) diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 749c7cdea..ac0f4e155 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -31,6 +31,16 @@ hires_ms NO_COPY gtod; hires_ns NO_COPY ntod; +extern "C" { void WINAPI GetSystemTimePreciseAsFileTime (LPFILETIME); } + +static inline void __attribute__ ((always_inline)) +get_system_time (PLARGE_INTEGER systime) +{ + wincap.has_precise_system_time () + ? GetSystemTimePreciseAsFileTime ((LPFILETIME) systime) + : GetSystemTimeAsFileTime ((LPFILETIME) systime); +} + /* Cygwin internal */ static uint64_t __stdcall __to_clock_t (PLARGE_INTEGER src, int flag) @@ -64,7 +74,7 @@ times (struct tms *buf) NtQueryInformationProcess (NtCurrentProcess (), ProcessTimes, &kut, sizeof kut, NULL); - GetSystemTimeAsFileTime ((LPFILETIME) &ticks); + get_system_time (&ticks); /* uptime */ ticks.QuadPart -= stodi.BootTime.QuadPart; @@ -286,7 +296,7 @@ time_as_timestruc_t (timestruc_t * out) { LARGE_INTEGER systime; - GetSystemTimeAsFileTime ((LPFILETIME) &systime); + get_system_time (&systime); to_timestruc_t (&systime, out); } @@ -298,7 +308,7 @@ time (time_t * ptr) time_t res; LARGE_INTEGER systime; - GetSystemTimeAsFileTime ((LPFILETIME) &systime); + get_system_time (&systime); res = to_time_t (&systime); if (ptr) *ptr = res; @@ -486,7 +496,7 @@ LONGLONG hires_ms::nsecs () { LARGE_INTEGER systime; - GetSystemTimeAsFileTime ((LPFILETIME) &systime); + get_system_time (&systime); /* Add conversion factor for UNIX vs. Windows base time */ return systime.QuadPart - FACTOR; } diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 9964467e3..d84679df5 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -48,6 +48,7 @@ wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = { has_program_compatibility_assistant:false, has_pipe_reject_remote_clients:false, terminate_thread_frees_stack:false, + has_precise_system_time:false, }; wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -75,6 +76,7 @@ wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { has_program_compatibility_assistant:false, has_pipe_reject_remote_clients:false, terminate_thread_frees_stack:false, + has_precise_system_time:false, }; wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -102,6 +104,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { has_program_compatibility_assistant:true, has_pipe_reject_remote_clients:true, terminate_thread_frees_stack:true, + has_precise_system_time:false, }; wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -129,6 +132,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { has_program_compatibility_assistant:true, has_pipe_reject_remote_clients:true, terminate_thread_frees_stack:true, + has_precise_system_time:false, }; wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -156,6 +160,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = { has_program_compatibility_assistant:true, has_pipe_reject_remote_clients:true, terminate_thread_frees_stack:true, + has_precise_system_time:true, }; wincapc wincap __attribute__((section (".cygwin_dll_common"), shared)); diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index 1004a5e46..cf42dc90e 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -38,6 +38,7 @@ struct wincaps unsigned has_program_compatibility_assistant : 1; unsigned has_pipe_reject_remote_clients : 1; unsigned terminate_thread_frees_stack : 1; + unsigned has_precise_system_time : 1; }; class wincapc @@ -87,6 +88,7 @@ public: bool IMPLEMENT (has_program_compatibility_assistant) bool IMPLEMENT (has_pipe_reject_remote_clients) bool IMPLEMENT (terminate_thread_frees_stack) + bool IMPLEMENT (has_precise_system_time) #undef IMPLEMENT };