Cygwin: implement extensible clock interface
- Drop hires_[nm]s clocks, rename hires.h to clock.h. - Implement clk_t class as an extensible clock class in new file clock.cc. - Introduce get_clock(clock_id) returning a pointer to the clk_t instance for clock_id. Provide the following methods along the lines of the former hires classes: void clk_t::nsecs (struct timespec *); ULONGLONG clk_t::nsecs (); LONGLONG clk_t::usecs (); LONGLONG clk_t::msecs (); void clk_t::resolution (struct timespec *); - Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE and CLOCK_BOOTTIME clocks. - Allow clock_nanosleep, pthread_condattr_setclock and timer_create to use all new clocks (both clocks should be usable with a small tweak, though). - Bump DLL major version to 2.12. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@@ -76,16 +76,9 @@ clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *rqtp,
|
||||
/* support for CPU-time clocks is optional */
|
||||
if (CLOCKID_IS_PROCESS (clk_id) || CLOCKID_IS_THREAD (clk_id))
|
||||
return ENOTSUP;
|
||||
|
||||
switch (clk_id)
|
||||
{
|
||||
case CLOCK_REALTIME:
|
||||
case CLOCK_MONOTONIC:
|
||||
break;
|
||||
default:
|
||||
/* unknown or illegal clock ID */
|
||||
return EINVAL;
|
||||
}
|
||||
/* All other valid clocks are valid */
|
||||
if (clk_id >= MAX_CLOCKS)
|
||||
return EINVAL;
|
||||
|
||||
LARGE_INTEGER timeout;
|
||||
|
||||
@@ -103,14 +96,18 @@ clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *rqtp,
|
||||
|| (tp.tv_sec == rqtp->tv_sec && tp.tv_nsec > rqtp->tv_nsec))
|
||||
return 0;
|
||||
|
||||
if (clk_id == CLOCK_REALTIME)
|
||||
timeout.QuadPart += FACTOR;
|
||||
else
|
||||
switch (clk_id)
|
||||
{
|
||||
case CLOCK_REALTIME_COARSE:
|
||||
case CLOCK_REALTIME:
|
||||
timeout.QuadPart += FACTOR;
|
||||
break;
|
||||
default:
|
||||
/* other clocks need to be handled with a relative timeout */
|
||||
timeout.QuadPart -= tp.tv_sec * NS100PERSEC
|
||||
+ tp.tv_nsec / (NSPERSEC/NS100PERSEC);
|
||||
timeout.QuadPart *= -1LL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else /* !abstime */
|
||||
|
Reference in New Issue
Block a user