diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2012-03-26 13:05:50 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2012-03-26 13:05:50 +0400 |
commit | b54d64de05084f38af3e475c70d50aa3966cbc2e (patch) | |
tree | 6f9d0d3608864768c7d614ab70e0cb0ecbbd745e /winsup/cygwin/times.cc | |
parent | cff00a203897a28629486e87662c0444aa9549d7 (diff) |
* hires.h (hires_ms::dmsecs): Drop unused method.
* times.cc (JITTER): Remove.
(gtod): Revert to process-local variable.
(hires_ms::nsecs): Just return system time to disallow discrepancy with
the OS.
(hires_ms::resolution): Return coarsest timer value from OS. Add
comment to explain why.
(clock_setres): Ditto.
Diffstat (limited to 'winsup/cygwin/times.cc')
-rw-r--r-- | winsup/cygwin/times.cc | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 4f4c39c92..051be82ba 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -1,7 +1,7 @@ /* times.cc Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. + 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -27,17 +27,7 @@ details. */ #include "cygtls.h" #include "ntdll.h" -/* Max allowed diversion in 100ns of internal timer from system time. If - this difference is exceeded, the internal timer gets re-primed. */ -#define JITTER (40 * 10000LL) - -/* TODO: Putting this variable in the shared cygwin region partially solves - the problem of cygwin processes not recognizing date changes when other - cygwin processes set the date. There is still an additional problem of - long-running cygwin processes becoming confused when a non-cygwin process - sets the date. Unfortunately, it looks like a minor redesign is required - to handle that case. */ -hires_ms gtod __attribute__((section (".cygwin_dll_common"), shared)); +hires_ms NO_COPY gtod; hires_ns NO_COPY ntod; @@ -575,16 +565,7 @@ hires_ms::nsecs () { if (!inited) prime (); - - LONGLONG t = systime_ns (); - LONGLONG res = initime_ns + timeGetTime_ns (); - if (llabs (res - t) > JITTER) - { - inited = false; - prime (); - res = initime_ns + timeGetTime_ns (); - } - return res; + return systime_ns (); } extern "C" int @@ -731,10 +712,15 @@ hires_ms::resolution () status = NtQueryTimerResolution (&coarsest, &finest, &actual); if (NT_SUCCESS (status)) - minperiod = (DWORD) actual; + /* The actual resolution of the OS timer is a system-wide setting which + can be changed any time, by any process. The only fixed value we + can rely on is the coarsest value. */ + minperiod = coarsest; else { - /* Try to empirically determine current timer resolution */ + /* There's no good reason that NtQueryTimerResolution should fail + at all, but let's play it safe. Try to empirically determine + current timer resolution */ int priority = GetThreadPriority (GetCurrentThread ()); SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); @@ -837,7 +823,10 @@ clock_setres (clockid_t clk_id, struct timespec *tp) __seterrno_from_nt_status (status); return -1; } - minperiod = actual; + /* The actual resolution of the OS timer is a system-wide setting which + can be changed any time, by any process. The only fixed value we can + rely on is the coarsest value. */ + minperiod = coarsest; period_set = true; return 0; } |