use monotonic time source in convar->timed_wait, and in the scheduler using it

This commit is contained in:
Martin Willi
2009-08-31 15:13:48 +02:00
parent 3f310c0d1f
commit 3d5818ec38
6 changed files with 50 additions and 21 deletions
+6 -3
View File
@@ -167,7 +167,9 @@ bool mkdir_p(const char *path, mode_t mode)
*/
time_t time_monotonic(timeval_t *tv)
{
#if defined(HAVE_CLOCK_GETTIME)
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CONDATTR_CLOCK_MONOTONIC)
/* as we use time_monotonic() for condvar operations, we use the
* monotonic time source only if it is also supported by pthread. */
timespec_t ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
@@ -179,11 +181,12 @@ time_t time_monotonic(timeval_t *tv)
}
return ts.tv_sec;
}
#endif /* HAVE_CLOCK_MONOTONIC */
#endif /* HAVE_CLOCK_MONOTONIC && HAVE_CONDATTR_CLOCK_MONOTONIC */
/* Fallback to non-monotonic timestamps:
* On MAC OS X, creating monotonic timestamps is rather difficult. We
* could use mach_absolute_time() and catch sleep/wakeup notifications.
* We stick to the simpler (non-monotonic) gettimeofday() for now. */
* We stick to the simpler (non-monotonic) gettimeofday() for now.
* But keep in mind: we need the same time source here as in condvar! */
if (!tv)
{
return time(NULL);