summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/times.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-09-07 05:18:01 +0000
committerChristopher Faylor <me@cgf.cx>2003-09-07 05:18:01 +0000
commited2287adcd6b16a0ef34defb443d5c61fc7830d7 (patch)
tree4b567ae87a505f3fb4bc5ba3329db06a1936df78 /winsup/cygwin/times.cc
parent6cce721b15c6ac75e7d6ae86a4354aa02bcf14d8 (diff)
downloadcygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.tar.gz
cygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.tar.bz2
cygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.zip
* signal.cc (nanosleep): Improve test for valid values. Round delay up to
resolution. Fix test for negative remainder. Use timeGetTime through gtod. (sleep): Round up return value. Christopher Faylor <cgf@redhat.com> * hires.h (HIRES_DELAY_MAX): Define. (hires_ms::minperiod): Declare static. (hires_ms::resolution): New. (hires_ms::dmsecs): New. (hires_ms::prime): Return UINT. (gtod): Declare. * times.cc (hires_ms::prime): Always calculate minperiod and set it to 1 in case of failure. Return minperiod. (hires_ms::resolution): Define. (hires_ms::~hires_ms): Delete. (hires_ms::usecs): Check minperiod to prime. (gtod) Define as global.
Diffstat (limited to 'winsup/cygwin/times.cc')
-rw-r--r--winsup/cygwin/times.cc47
1 files changed, 27 insertions, 20 deletions
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index 0d4bc7112..9eea3352d 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -142,11 +142,13 @@ totimeval (struct timeval *dst, FILETIME *src, int sub, int flag)
dst->tv_sec = x / (long long) (1e6);
}
+hires_ms gtod;
+UINT NO_COPY hires_ms::minperiod;
+
/* FIXME: Make thread safe */
extern "C" int
gettimeofday (struct timeval *tv, struct timezone *tz)
{
- static hires_ms gtod;
static bool tzflag;
LONGLONG now = gtod.usecs (false);
if (now == (LONGLONG) -1)
@@ -620,37 +622,42 @@ hires_us::usecs (bool justdelta)
return justdelta ? now.QuadPart : primed_ft.QuadPart + now.QuadPart;
}
-void
+UINT
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);
- }
+ if (!minperiod)
+ if (timeGetDevCaps (&tc, sizeof (tc)) != TIMERR_NOERROR)
+ minperiod = 1;
+ else
+ {
+ minperiod = min (max (tc.wPeriodMin, 1), tc.wPeriodMax);
+ timeBeginPeriod (minperiod);
+ }
- initime_ms = timeGetTime ();
- GetSystemTimeAsFileTime (&f);
- SetThreadPriority (GetCurrentThread (), priority);
+ if (!inited)
+ {
+ int priority = GetThreadPriority (GetCurrentThread ());
+ SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
+ initime_ms = timeGetTime ();
+ GetSystemTimeAsFileTime (&f);
+ SetThreadPriority (GetCurrentThread (), priority);
- inited = 1;
- initime_us.HighPart = f.dwHighDateTime;
- initime_us.LowPart = f.dwLowDateTime;
- initime_us.QuadPart -= FACTOR;
- initime_us.QuadPart /= 10;
+ inited = 1;
+ initime_us.HighPart = f.dwHighDateTime;
+ initime_us.LowPart = f.dwLowDateTime;
+ initime_us.QuadPart -= FACTOR;
+ initime_us.QuadPart /= 10;
+ }
+ return minperiod;
}
LONGLONG
hires_ms::usecs (bool justdelta)
{
- if (!inited)
+ if (!minperiod) /* NO_COPY variable */
prime ();
DWORD now = timeGetTime ();
// FIXME: Not sure how this will handle the 49.71 day wrap around