Daniel Stone wrote:
> Hi,
> 
> On Tue, Aug 24, 2010 at 08:55:22AM +0800, ykzhao wrote:
>> What Mark mentioned is that the CLOCK_MONOTONIC_COARSE posix timer is
>> not supported while the corresponding ID is used for other posix timer.
>> Right? 
> 
> 6 has no meaning to clock_gettime().  CLOCK_MONOTONIC_COARSE is the only
> thing that has any meaning: if it's not defined, you can't just invent a
> definition and hope that it works.  That's why the spec says
> CLOCK_MONOTONIC_COARSE and not 6.
> 
>> If so, is there an approach that helps us to detect whether the
>> CLOCK_MONOTONIC_COARSE posix timer is supported on one OS?
> 
> Try the following completely untested patch (hey, it compiles).  It's
> not perfect though: if CLOCK_MONOTONIC or CLOCK_MONOTONIC_COARSE were
> ever 0, we'd make two or three syscalls for GetTimeInMillis() instead of
> one, and if either of them were ~0L, we'd never use them.
> 
> Cheers,
> Daniel
> 
> diff --git a/os/utils.c b/os/utils.c
> index 51455cc..a1659ec 100644
> --- a/os/utils.c
> +++ b/os/utils.c
> @@ -427,7 +427,20 @@ GetTimeInMillis(void)
>  
>  #ifdef MONOTONIC_CLOCK
>      struct timespec tp;
> -    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
> +    static clockid_t clockid;
> +    if (!clockid) {
> +#ifdef CLOCK_MONOTONIC_COARSE
> +        if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
> +            (tp.tv_nsec / 1000) <= 1000)
> +            clockid = CLOCK_MONOTONIC_COARSE;
> +        else
> +#endif
> +        if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
> +            clockid = CLOCK_MONOTONIC;
> +        else
> +            clockid = ~0L;
> +    }
> +    if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
>          return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
>  #endif

>From Review, not Testing, that looks like a pretty good solution to me.

-- 
        -Alan Coopersmith-        [email protected]
         Oracle Solaris Platform Engineering: X Window System

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to