qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] slirp: Use monotonic clock if available


From: malc
Subject: Re: [Qemu-devel] [PATCH] slirp: Use monotonic clock if available
Date: Thu, 23 Jul 2009 03:38:13 +0400 (MSD)

On Wed, 22 Jul 2009, Ed Swierk wrote:

[..snip..]

> -static void updtime(void)
> -{
> +#ifdef CLOCK_MONOTONIC
> +    struct timespec tv;
> +
> +    clock_gettime(CLOCK_MONOTONIC, &tv);
> +
> +    curtime = tv.tv_sec * 1000 + tv.tv_nsec / 1000000;
> +#else
>      struct timeval tv;
>  
>      gettimeofday(&tv, NULL);
>  
>      curtime = tv.tv_sec * 1000 + tv.tv_usec / 1000;
> -}
>  #endif
> +#endif
> +}

This is wrong on many levels.

Suppose CLOCK_MONOTONIC(which is wrong _POSIX_MONOTONIC_CLOCK ought to
be checked) is defined and you compile your binary on, say, Linux 2.6
and then try to run it on 2.4 (without any fancy RHEL patches for
instance), things wouldn't work, what's worse they wouldn't work
silently, giving no indication what's wrong all because nobody checks
clock_gettime result for failures.

The CLOCK_MONOTONIC presence ought to be checked at runtime
(see sysconf(3) and _POSIX_MONOTONIC_CLOCK)

[..snip..]

-- 
mailto:address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]