[Spice-devel] [PATCH 09/11] utils: add red_get_monotonic_time()

Francois Gouget fgouget at codeweavers.com
Fri Oct 30 04:06:35 PDT 2015


On Thu, 29 Oct 2015, Frediano Ziglio wrote:
[...]
> +/* FIXME: consider g_get_monotonic_time (), but in microseconds */
> +static inline red_time_t red_get_monotonic_time(void)
> +{
> +    struct timespec time;
> +
> +    clock_gettime(CLOCK_MONOTONIC, &time);
> +    return (red_time_t) time.tv_sec * (1000 * 1000 * 1000) + time.tv_nsec;
> +}

I think the name should be more generic as I see no reason why this 
function could not also replace get_time_stamp() (the signed/unsigned 
difference does not seem insurmountable), and various clock_gettime() 
calls in mjpeg_encoder.c and in red_channel.c. 

It would also be nice to have a NANO_SECOND constant instead of '1000 * 
1000 * 1000' in one place, '1000000000ULL' in another (notice the LL 
btw), etc.

Also '30 * NANO_SECOND' would be clearer than '30000000000ULL'.

I'm open to naming variations but it should be something that can 
readily be adapted to get the duration of one second in milliseconds, 
MILLI_SECOND, in microseconds, MICRO_SECOND, or the duration of a 
millisecond in nanoseconds (for conversions), NANO_MS or 
NANO_MILLISECOND.


-- 
Francois Gouget <fgouget at codeweavers.com>


More information about the Spice-devel mailing list