diff options
author | Christopher Faylor <me@cgf.cx> | 2002-06-07 03:44:33 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-06-07 03:44:33 +0000 |
commit | 9d0efbb3aeef0490d227c9b98bd478ac1964d16d (patch) | |
tree | 005964002ffa58bbddce64254ce2b60cfc9e0d59 /winsup/cygwin/times.cc | |
parent | b841df7954ad31383688775114132af73b7693d4 (diff) | |
download | cygnal-9d0efbb3aeef0490d227c9b98bd478ac1964d16d.tar.gz cygnal-9d0efbb3aeef0490d227c9b98bd478ac1964d16d.tar.bz2 cygnal-9d0efbb3aeef0490d227c9b98bd478ac1964d16d.zip |
* autoload.cc (timeGetDevCaps): Define new autoload function.
(timeGetTime): Ditto.
(timeBeginPeriod): Ditto.
(timeEndPeriod): Ditto.
* hires.h (hires_base): New class. Renamed from hires.
(hires_us): New class.
(hires_ms): New class.
* strace.cc (strace::microseconds): Use hires_us class.
* times.cc (gettimeofday): Use hires-ms class.
(hires_us::prime): Renamed from hires::prime.
(hires_us::usecs): Renamed from hires:usecs.
(hires_ms::prime): New method.
(hires_ms::usecs): New method.
(hires_ms::~hires_ms): New destructor.
Diffstat (limited to 'winsup/cygwin/times.cc')
-rw-r--r-- | winsup/cygwin/times.cc | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index a81201e7b..a64ee3d86 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -143,9 +143,9 @@ totimeval (struct timeval *dst, FILETIME *src, int sub, int flag) /* FIXME: Make thread safe */ extern "C" int -gettimeofday(struct timeval *tv, struct timezone *tz) +gettimeofday (struct timeval *tv, struct timezone *tz) { - static hires gtod; + static hires_ms gtod; static bool tzflag; LONGLONG now = gtod.usecs (false); if (now == (LONGLONG) -1) @@ -580,7 +580,7 @@ cygwin_tzset () } void -hires::prime () +hires_us::prime () { LARGE_INTEGER ifreq; if (!QueryPerformanceFrequency (&ifreq)) @@ -612,7 +612,7 @@ hires::prime () } LONGLONG -hires::usecs (bool justdelta) +hires_us::usecs (bool justdelta) { if (!inited) prime (); @@ -633,3 +633,42 @@ hires::usecs (bool justdelta) now.QuadPart = (LONGLONG) (freq * (double) (now.QuadPart - primed_pc.QuadPart)); return justdelta ? now.QuadPart : primed_ft.QuadPart + now.QuadPart; } + +void +hires_ms::prime () +{ + TIMECAPS tc; + FILETIME f; + int priority = GetThreadPriority (GetCurrentThread ()); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); + + if (timeGetDevCaps (&tc, sizeof (tc)) != TIMERR_NOERROR) + minperiod = 0; + else + { + minperiod = min (max(tc.wPeriodMin, 1), tc.wPeriodMax); + timeBeginPeriod (minperiod); + } + initime_ms = timeGetTime (); + GetSystemTimeAsFileTime (&f); + SetThreadPriority (GetCurrentThread (), priority); + initime_us.HighPart = f.dwHighDateTime; + initime_us.LowPart = f.dwLowDateTime; + initime_us.QuadPart /= 10; +} + +LONGLONG +hires_ms::usecs (bool justdelta) +{ + if (!inited) + prime (); + DWORD now = timeGetTime (); + // FIXME: Not sure how this will handle the 49.71 day wrap around + LONGLONG res = initime_us.QuadPart + ((LONGLONG) (now - initime_ms) * 1000); + return res; +} + +hires_ms::~hires_ms () +{ + timeEndPeriod (minperiod); +} |