Cygwin: timers: drop error handling for Windows perf timer functions
Per MSDN, the perf timer functions always succeed on Windows XP or later. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
65091f0f35
commit
161d0fd27b
@ -466,21 +466,14 @@ void
|
|||||||
hires_ns::prime ()
|
hires_ns::prime ()
|
||||||
{
|
{
|
||||||
LARGE_INTEGER ifreq;
|
LARGE_INTEGER ifreq;
|
||||||
if (!QueryPerformanceFrequency (&ifreq))
|
|
||||||
{
|
/* On XP or later the perf counter functions will always succeed. */
|
||||||
inited = -1;
|
QueryPerformanceFrequency (&ifreq);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int priority = GetThreadPriority (GetCurrentThread ());
|
int priority = GetThreadPriority (GetCurrentThread ());
|
||||||
|
|
||||||
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
|
||||||
if (!QueryPerformanceCounter (&primed_pc))
|
QueryPerformanceCounter (&primed_pc);
|
||||||
{
|
|
||||||
SetThreadPriority (GetCurrentThread (), priority);
|
|
||||||
inited = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
freq = (double) ((double) NSPERSEC / (double) ifreq.QuadPart);
|
freq = (double) ((double) NSPERSEC / (double) ifreq.QuadPart);
|
||||||
inited = true;
|
inited = true;
|
||||||
@ -490,21 +483,11 @@ hires_ns::prime ()
|
|||||||
LONGLONG
|
LONGLONG
|
||||||
hires_ns::nsecs (bool monotonic)
|
hires_ns::nsecs (bool monotonic)
|
||||||
{
|
{
|
||||||
|
LARGE_INTEGER now;
|
||||||
|
|
||||||
if (!inited)
|
if (!inited)
|
||||||
prime ();
|
prime ();
|
||||||
if (inited < 0)
|
QueryPerformanceCounter (&now);
|
||||||
{
|
|
||||||
set_errno (ENOSYS);
|
|
||||||
return (LONGLONG) -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LARGE_INTEGER now;
|
|
||||||
if (!QueryPerformanceCounter (&now))
|
|
||||||
{
|
|
||||||
set_errno (ENOSYS);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Use round() here?
|
// FIXME: Use round() here?
|
||||||
now.QuadPart = (LONGLONG) (freq * (double)
|
now.QuadPart = (LONGLONG) (freq * (double)
|
||||||
(now.QuadPart - (monotonic ? 0LL : primed_pc.QuadPart)));
|
(now.QuadPart - (monotonic ? 0LL : primed_pc.QuadPart)));
|
||||||
@ -646,12 +629,6 @@ hires_ns::resolution ()
|
|||||||
{
|
{
|
||||||
if (!inited)
|
if (!inited)
|
||||||
prime ();
|
prime ();
|
||||||
if (inited < 0)
|
|
||||||
{
|
|
||||||
set_errno (ENOSYS);
|
|
||||||
return (LONGLONG) -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (freq <= 1.0) ? 1LL : (LONGLONG) freq;
|
return (freq <= 1.0) ? 1LL : (LONGLONG) freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user