Le 2014-09-09 10:48, [email protected] a écrit :
Rémi Denis-Courmont <[email protected]> writes:
Le 2014-09-08 22:20, Gabriel Dume a écrit :
#if HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- return (int64_t)ts.tv_sec * 100000 + ts.tv_nsec / 1000;
+ return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
The original code is still wrong by the way. If
_POSIX_MONOTONIC_CLOCK
is zero (as on GNU/libc), then availability of the clock needs to be
checked at run-time. Nominally, sysconf(_SC_MONOTONIC_CLOCK) does
it.
Wouldn't it be more robust to check the return value of
clock_gettime?
Should give errno == EINVAL for clocks that aren't available.
Why would it be more robust? Unless the libc is utterly broken, the
result will be the same. Indeed I believe glibc's sysconf() calls
clock_getres() internally.
Also, you really want to probe the clock once and use the same result
always. Checking it everytime is slower and arguably wrong. It gets
worse if you need to use pthread_cond_timedwait(), and thus
pthread_condattr_setclock().
pthread_once() and a clockid_t static variable are perfectly suited
here.
--
Rémi Denis-Courmont
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel