Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2011-03-12 13:02:53 +0300
committerCorinna Vinschen <corinna@vinschen.de>2011-03-12 13:02:53 +0300
commit32d63e069cbbeeabba0338841d1b97546d29314a (patch)
treee5c5ff5eb3acb04e73eca73a7134707c33a7d2d0
parentaf2861c7e16a59ad8ddd5d910f3c162e32cfb4df (diff)
* times.cc (hires_ms::timeGetTime_ns): Fix formatting in comment.
(hires_ms::resolution): Cast to DWORD in assignments to minperiod. (clock_setres): Improve comment. Convert period to ULONGLONG and store 100ns value to simplify code.
-rw-r--r--winsup/cygwin/ChangeLog7
-rw-r--r--winsup/cygwin/times.cc60
2 files changed, 40 insertions, 27 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 0e0ba1e76..b69804e88 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-12 Corinna Vinschen <corinna@vinschen.de>
+
+ * times.cc (hires_ms::timeGetTime_ns): Fix formatting in comment.
+ (hires_ms::resolution): Cast to DWORD in assignments to minperiod.
+ (clock_setres): Improve comment. Convert period to ULONGLONG and
+ store 100ns value to simplify code.
+
2011-03-11 Corinna Vinschen <corinna@vinschen.de>
* times.cc (clock_setres): Use status code from NtSetTimerResolution
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index ad416839b..19c03fdf8 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -682,24 +682,25 @@ hires_ms::timeGetTime_ns ()
DWORD tick_count_start;
LARGE_INTEGER int_time_start;
- do {
- tick_count_start = GetTickCount ()
- do
- {
- int_time_start.HighPart = SharedUserData.InterruptTime.High1Time;
- int_time_start.LowPart = SharedUserData.InterruptTime.LowPart;
- }
- while (int_time_start.HighPart
- != SharedUserData.InterruptTime.High2Time);
- }
- while (tick_count_start != GetTickCount ();
-
- - timeGetTime computes its return value in the loop as below, but then:
-
- t.QuadPart -= int_time_start.QuadPart;
- t.QuadPart /= 10000;
- t.LowPart += tick_count_start;
- return t.LowPart;
+ do
+ {
+ tick_count_start = GetTickCount ()
+ do
+ {
+ int_time_start.HighPart = SharedUserData.InterruptTime.High1Time;
+ int_time_start.LowPart = SharedUserData.InterruptTime.LowPart;
+ }
+ while (int_time_start.HighPart
+ != SharedUserData.InterruptTime.High2Time);
+ }
+ while (tick_count_start != GetTickCount ();
+
+ - timeGetTime computes its return value in the loop as below, and then:
+
+ t.QuadPart -= int_time_start.QuadPart;
+ t.QuadPart /= 10000;
+ t.LowPart += tick_count_start;
+ return t.LowPart;
*/
do
{
@@ -780,7 +781,7 @@ clock_gettime (clockid_t clk_id, struct timespec *tp)
static DWORD minperiod; // FIXME: Maintain period after a fork.
LONGLONG
-hires_ns::resolution()
+hires_ns::resolution ()
{
if (!inited)
prime ();
@@ -803,7 +804,7 @@ hires_ms::resolution ()
status = NtQueryTimerResolution (&coarsest, &finest, &actual);
if (NT_SUCCESS (status))
- minperiod = (UINT) actual / 10000L;
+ minperiod = (DWORD) actual / 10000L;
else
{
/* Try to empirically determine current timer resolution */
@@ -824,7 +825,7 @@ hires_ms::resolution ()
}
SetThreadPriority (GetCurrentThread (), priority);
period /= 40000L;
- minperiod = (UINT) period;
+ minperiod = (DWORD) period;
}
}
return minperiod;
@@ -871,24 +872,29 @@ clock_setres (clockid_t clk_id, struct timespec *tp)
return -1;
}
- DWORD period = (tp->tv_sec * 1000) + ((tp->tv_nsec) / 1000000);
+ /* Convert to 100ns to match OS resolution. The OS uses ULONG values
+ to express resolution in 100ns units, so the coarsest timer resolution
+ is < 430 secs. Actually the coarsest timer resolution is only slightly
+ beyond 15ms, but this might change in future OS versions, so we play nice
+ here. */
+ ULONGLONG period = (tp->tv_sec * 10000000ULL) + ((tp->tv_nsec) / 100ULL);
/* clock_setres is non-POSIX/non-Linux. On QNX, the function always
rounds the incoming value to the nearest supported value. */
ULONG coarsest, finest, actual;
if (NT_SUCCESS (NtQueryTimerResolution (&coarsest, &finest, &actual)))
{
- if (period > coarsest / 10000L)
- period = coarsest / 10000L;
- else if (finest / 10000L > period)
- period = finest / 10000L;
+ if (period > coarsest)
+ period = coarsest;
+ else if (finest > period)
+ period = finest;
}
if (period_set
&& NT_SUCCESS (NtSetTimerResolution (minperiod * 10000L, FALSE, &actual)))
period_set = false;
- status = NtSetTimerResolution (period * 10000L, TRUE, &actual);
+ status = NtSetTimerResolution (period, TRUE, &actual);
if (!NT_SUCCESS (status))
{
__seterrno_from_nt_status (status);